using UnityEngine;
using System.Collections;
using UnityEditor; // 编辑器命名空间的引用
public class Editor2 : EditorWindow // 编辑器类
{
private bool foldout; // 声明折叠菜单的状态
[MenuItem("EditorDemo/CreateWindow")] // 在编辑器中添加一个菜单
static void CreateWindow() // 下面这个函数必须是***静态的***
{
// 在这里面创建窗口
EditorWindow.GetWindow(typeof(Editor2), false, "EditorWindow", true);
}
void OnGUI()
{
foldout = EditorGUILayout.Foldout(foldout, "Foldout"); // 定义折叠菜单
if (foldout)
{
EditorGUILayout.HelpBox("HelpBox", MessageType.Error); // 显示一个提示框
}
}
}

using UnityEngine;
using System.Collections;
using UnityEditor; // 编辑器命名空间的引用
public class Editor2 : EditorWindow // 编辑器类
{
private bool fold = false; // 声明折叠
private GameObject selection; // 声明被选物体
[MenuItem("EditorDemo/CreateWindow")] // 在编辑器中添加一个菜单
static void CreateWindow() // 下面这个函数必须是***静态的***
{
// 在这里面创建窗口
EditorWindow.GetWindow(typeof(Editor2), false, "EditorWindow", true);
}
void OnGUI()
{
if (Selection.activeGameObject)
{
selection = Selection.gameObjects[0];
fold = EditorGUILayout.InspectorTitlebar(fold, selection); // 定义一个检视面板栏***Selection.objects表示当前被选中的物体***
if (fold) // 控制折叠
{
selection.transform.position = EditorGUILayout.Vector3Field("Position", selection.transform.position); // 定义一个Vector3输入区域
}
}
}
void OnInspectorUpdate()
{
this.Repaint(); // 刷新Inspector
}
}

using UnityEngine;
using System.Collections;
using UnityEditor; // 编辑器命名空间的引用
public class Editor2 : EditorWindow // 编辑器类
{
private float value0 = 0f;
private float value1 = 0f;
private float value2 = 0f;
[MenuItem("EditorDemo/CreateWindow")] // 在编辑器中添加一个菜单
static void CreateWindow() // 下面这个函数必须是***静态的***
{
// 在这里面创建窗口
EditorWindow.GetWindow(typeof(Editor2), false, "EditorWindow", true);
}
void OnGUI()
{
value0 = EditorGUILayout.Slider("Slider", value0, -50f, 50f); // 定义单滑块
EditorGUILayout.MinMaxSlider(new GUIContent("MinMaxSlider"), ref value1, ref value2, -50f, 50f); // 定义双滑块
EditorGUILayout.BeginHorizontal(); // 将下面两个值显示在同一行
EditorGUILayout.FloatField(value1);
EditorGUILayout.FloatField(value2);
EditorGUILayout.EndHorizontal();
}
void OnInspectorUpdate()
{
this.Repaint(); // 刷新Inspector
}
}

(转)Unity笔记之编辑器(Foldout、HelpBox、InspectorTitlebar、Slider、MinMaxSlid ...
原文:http://www.cnblogs.com/backlighting/p/5061576.html