• Unity Editor Hierarchy下拉菜单扩展


    TestHierarchyPopupMenuEditor.cs

    using UnityEditor;
    using UnityEngine;
    
    public class TestHierarchyPopupMenuEditor : ScriptableObject {
    
        [MenuItem("GameObject/Create New Child", true)]
        private static bool ValidateCreateChild() {
            GameObject[] gameObjects = Selection.gameObjects;
            return gameObjects.Length > 0;
        }
    
        [MenuItem("GameObject/Create New Child", false, 11)]
        private static void CreateChild() {
            GameObject[] gameObjects = Selection.gameObjects;
            for (int i = 0; i < gameObjects.Length; i++) {
                var child = new GameObject("New Child");
                child.transform.parent = gameObjects[i].transform;
            }
        }
    }
    

    修改为按下并释放鼠标中键弹出指定菜单
    TestHierarchyPopupMenuEditor.cs

    using UnityEditor;
    using UnityEngine;
    
    public class TestHierarchyPopupMenuEditor : ScriptableObject {
    
        [InitializeOnLoadMethod]
        private static void StartInitializeOnLoadMethod() {
            EditorApplication.hierarchyWindowItemOnGUI += OnHierarchyGUI;
        }
    
        private static void OnHierarchyGUI(int instanceID, Rect selectionRect) {
            if (Event.current!=null) {
                Debug.Log($"button:{Event.current.button}, type:{Event.current.type}");
            }
            
            if (Event.current != null && Event.current.button == 2 && Event.current.type == EventType.MouseUp) { // 按下并释放鼠标中键时
                //if (Selection.activeTransform) { // 选中激活一个 Transform 时才弹出
                    Vector2 mousePosition = Event.current.mousePosition;
                    EditorUtility.DisplayPopupMenu(new Rect(mousePosition.x, mousePosition.y, 0, 0), "GameObject/", null); // 弹出 GameObject 菜单
                //}
            }
        }
    }
    
  • 相关阅读:
    python 八进制数
    python hmac加盐
    python contextlib
    python hashlib
    python struct
    python namedtuple
    python datetime timezone 时区转化
    Android核心基础(手机卫士的一个知识点总结)
    TabHost结合RadioButton实现主页的导航效果
    Android SDK更新失败最新解决方案
  • 原文地址:https://www.cnblogs.com/kingBook/p/16170943.html
Copyright © 2020-2023  润新知