[cb]ScriptableWizard 创建向导

时间:2023-03-08 22:25:07

需求

方便策划一步一步的创建Actor

[cb]ScriptableWizard 创建向导[cb]ScriptableWizard 创建向导

思路分析

Unity的Editor中提供创建向导的功能,ScriptableWizard

代码实现

创建一个WizardCreateActor继承自ScriptableWizard,放在Editor/下

using UnityEditor;
using UnityEngine;
//doc:http://docs.unity3d.com/ScriptReference/ScriptableWizard.html class WizardCreateActor : ScriptableWizard
{
public static CSimActor actor = new CSimActor();
public int NPC编号 = 1;
public int NPC等级 = 1;
public bool 是否敌人 = true;
public bool 是否障碍 = false; [MenuItem("Game/创建Actor向导")]
static void CreateWizard()
{
ScriptableWizard.DisplayWizard<WizardCreateActor>("创建Actor向导", "Create", "Apply");
//如果你不想使用辅助按钮可以忽略它:
//ScriptableWizard.DisplayWizard<WizardCreateActor>("创建Actor向导", "Create");
}
void OnWizardCreate()
{
GameObject go = new GameObject("Actor 机枪球");
go.AddComponent<CSimActor>();
actor.NPC编号 = NPC编号;
actor.是否敌人 = 是否敌人;
}
void OnWizardUpdate()
{
//errorString Allows you to set the error text of the wizard.
//helpString Allows you to set the help text of the wizard.
helpString = "初始化Actor属性";
} //当用户按下"Apply"按钮,OnWizardOtherButton被调用
void OnWizardOtherButton()
{
if (Selection.activeTransform == null || Selection.activeTransform.gameObject.GetComponent<CSimActor>() == null) return;
Selection.activeTransform.gameObject.GetComponent<CSimActor>().NPC编号 = NPC编号;
//.... 根据向导的值 初始化Actor属性
}
}


文档

ScriptableWizard API:http://docs.unity3d.com/ScriptReference/ScriptableWizard.html