[cb]ScriptableWizard 创建向导



需求

方便策划一步一步的创建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属性
    }
}
本文转自赵青青博客园博客,原文链接:http://www.cnblogs.com/zhaoqingqing/p/3812397.html,如需转载请自行联系原作者
上一篇:CentOS 7 编译安装httpd-2.4.17


下一篇:redis benckmark 使用