Inherits from ScriptableObject
Derive from this class to create an editor window.
从这个类来创建编辑器窗口。
Note: This is an editor class. To use it you have to place your script in Assets/Editor inside your project folder. Editor classes are in the UnityEditor namespace so for C# scripts you need to add "using UnityEditor;" at the beginning of the script.
注意:这是一个编辑器类,如果想使用它你需要把它放到工程目录下的Assets/Editor文件夹下。编辑器类在UnityEditor命名空间下。所以当使用C#脚本时,你需要在脚本前面加上 "using UnityEditor"引用。
Create your own custom editor window that can float free or be docked as a tab, just like the native windows in the Unity interface.
创建自己的自定义编辑器窗口,可以自由浮动或作为一个标签停靠,就像在Unity接口的本地窗口。
Editor windows are typically opened using a menu item.
通常编辑器窗口是使用一个菜单项打开。
// C# example:
using UnityEngine;
using UnityEditor;
public class MyWindow : EditorWindow {
string myString = "Hello World";
bool groupEnabled;
bool myBool = true;
float myFloat = 1.23f;
// Add menu named "My Window" to the Window menu
[MenuItem ("Window/My Window")]
static void Init () {
// Get existing open window or if none, make a new one:
MyWindow window = (MyWindow)EditorWindow.GetWindow (typeof (MyWindow));
}
void OnGUI () {
GUILayout.Label ("Base Settings", EditorStyles.boldLabel);
myString = EditorGUILayout.TextField ("Text Field", myString);
groupEnabled = EditorGUILayout.BeginToggleGroup ("Optional Settings", groupEnabled);
myBool = EditorGUILayout.Toggle ("Toggle", myBool);
myFloat = EditorGUILayout.Slider ("Slider", myFloat, -3, 3);
EditorGUILayout.EndToggleGroup ();
}
}
// JavaScript example:
class MyWindow extends EditorWindow {
var myString = "Hello World";
var groupEnabled = false;
var myBool = true;
var myFloat = 1.23;
// Add menu named "My Window" to the Window menu
//添加菜单项My Window到Window菜单
@MenuItem ("Window/My Window")
static function Init () {
// Get existing open window or if none, make a new one:
//获取现有的打开窗口或如果没有,创建一个新的
var window : MyWindow = EditorWindow.GetWindow (MyWindow);
}
function OnGUI () {
GUILayout.Label ("Base Settings", EditorStyles.boldLabel);
myString = EditorGUILayout.TextField ("Text Field", myString);
groupEnabled = EditorGUILayout.BeginToggleGroup ("Optional Settings", groupEnabled);
myBool = EditorGUILayout.Toggle ("Toggle", myBool);
myFloat = EditorGUILayout.Slider ("Slider", myFloat, -3, 3);
EditorGUILayout.EndToggleGroup ();
}
}