orange_17.09.18学习unity-菜单栏MenuItem

加油!!!
17年9月18日

using UnityEngine;
using UnityEditor;

public class MyTest : MonoBehaviour {
    /// <summary>
    /// 在菜单栏下添加一个新的菜单项
    /// </summary>
    [MenuItem ("Orange/orange_chenTest")]
    static void myTest() {
        GameObject go = new GameObject("Orange");
        Debug.Log("Hello World!");
    }
    / <summary>
    / 在GameObject下添加一个新的菜单项TestGameObject
    / </summary>
    [MenuItem("GameObject/TestGameObject")]
    static void TestGameObject()
    {
        GameObject go = new GameObject("TestGameObject");
    }
    / <summary>
    / 我们选中的时候才可以启用它,false是不选中也可以启用,可以添加优先级1为相同类型的最优先
    / </summary>
    / <returns></returns>
    [MenuItem("GameObject/TestGameObject", true)]//MenuItem("GameObject/TestGameObject", false, 1)
    static bool ValidateTestGameObject()
    {
        return Selection.activeTransform != null;
    }

    /// <summary>
    /// 创建Test Command选中创建子集Test Command不选中正常创建Test Command
    /// </summary>
    /// <param name="m_nCommand"></param>
    [MenuItem ("GameObject/TestOrange/TestCommand", false, 1)]
    static void CreateTestCommand(MenuCommand m_nCommand)
    {
        m_nCommand.context = Selection.activeObject;
        GameObject go = new GameObject("Test Command");
        GameObjectUtility.SetParentAndAlign(go, (GameObject)m_nCommand.context);
        Undo.RegisterCreatedObjectUndo(go, "Create " + go.name);//撤销  添加这句可以在编辑器里撤销不添加则不可以,和Destroy有些像
        Selection.activeObject = go;
        
    }
    
}
已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 创作都市 设计师:CSDN官方博客 返回首页