Inherits from EditorWindow
Derive from this class to create an editor wizard.
从这个类派生来创建一个编辑器向导。
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"引用。
Editor wizards are typically opened using a menu item.
编辑器向导通常使用菜单项打开。
// C#
// Creates a simple wizard that lets you create a Light GameObject
// or if the user clicks in "Apply", it will set the color of the currently
// object selected to red
//创建一个简单的向导,来创建灯光物体
//或如果用户点击"Apply",它将设置当前选择的物体颜色为红色
using UnityEditor;
using UnityEngine;
class WizardCreateLight : ScriptableWizard {
public float range = 500;
public Color color = Color.red;
[MenuItem ("GameObject/Create Light Wizard")]
static void CreateWizard () {
ScriptableWizard.DisplayWizard<WizardCreateLight>("Create Light", "Create", "Apply");
//If you don't want to use the secondary button simply leave it out:
//如果你不想使用辅助按钮可以忽略它:
//ScriptableWizard.DisplayWizard<WizardCreateLight>("Create Light", "Create");
}
void OnWizardCreate () {
GameObject go = new GameObject ("New Light");
go.AddComponent("Light");
go.light.range = range;
go.light.color = color;
}
void OnWizardUpdate () {
helpString = "Please set the color of the light!";
}
// When the user pressed the "Apply" button OnWizardOtherButton is called.
//当用户按下"Apply"按钮,OnWizardOtherButton被调用
void OnWizardOtherButton () {
if (Selection.activeTransform == null ||
Selection.activeTransform.light == null) return;
Selection.activeTransform.light.color = Color.red;
}
}