[cb]ScriptableWizard 创建向导

下面是项目中使用的一个实例,ScriptableWizard继承自ScriptableWizard,放在Editor

image image 

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属性

    }

}

 

 

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

你可能感兴趣的:(script)