kingBook

导航

Unity ContextMenu 扩展组件的环境菜单(在 Inspector 视图组件名称上的右击下拉菜单)

public class EndArea : MonoBehaviour {

#if UNITY_EDITOR
    [ContextMenu("Generate")]
    private void Generate () {
        Debug.Log("Generate");
    }
#endif
}

扩展内置组件的环境菜单

EditorRigidbodyMenu.cs

#if UNITY_EDITOR

using UnityEditor;
using UnityEngine;

public class EditorRigidbodyMenu : Editor {
    [MenuItem("CONTEXT/Rigidbody/在Rigidbody上右键")] // 注意此处使用的不是 ContextMenu
    static void DoIt () {
        EditorUtility.DisplayDialog("MyTool", "Do It in C# !", "OK", "");
    }
}
#endif

多个组件共同使用用一个方法

#if UNITY_EDITOR

using UnityEditor;
using UnityEngine;

public class EditorMeshContextMenu : Editor {
    [MenuItem("CONTEXT/MeshRenderer/在 MeshRenderer上右键")]
    [MenuItem("CONTEXT/SkinnedMeshRenderer/在 SkinnedMeshRenderer上右键")]
    static void DoIt () {
        EditorUtility.DisplayDialog("MyTool", "Do It in C# !", "OK", "");
        
    }
}
#endif

原文链接:https://www.cnblogs.com/kingBook/p/14943141.html

posted on 2021-06-28 09:41  kingBook  阅读(646)  评论(0编辑  收藏  举报