ScriptableWizard 脚本化向导

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;
	}
}

Variables变量

Messages Sent发送消息

Class Functions类函数

Inherited members继承成员

Inherited Variables继承变量

Inherited Functions继承函数

Inherited Variables继承变量

Inherited Class Functions继承类函数

Inherited Messages Sent继承发送消息

最后修改:2011年8月20日 Saturday 18:37

本脚本参考基于Unity 3.4.1f5

英文部分版权属©Unity公司所有,中文部分© Unity圣典 版权所有,未经许可,严禁转载 。