需求

方便策划一步一步的创建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

相关文章:

  • 2021-07-19
  • 2022-01-06
  • 2021-09-08
  • 2022-12-23
  • 2021-12-14
  • 2021-12-27
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-06-18
  • 2021-10-19
  • 2021-11-16
  • 2021-09-12
  • 2021-09-03
相关资源
相似解决方案