• 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 菜单
                //}
            }
        }
    }
    
  • 相关阅读:
    Install Edge Browser to RedHat Linux 7.7
    Beam简介
    Beam Schema定义
    Beam Pipeline的几种模式
    centos 查询磁盘空间占用情况 以及Can't create/write to file '/tmp/#sql_1f98_0.MYI' (Errcode: 28)
    Caused by: org.flywaydb.core.api.FlywayException: Validate failed: Migration checksum mismatch for migration 1 -> Applied to database
    SSTI学习
    2020/11/22周总结
    2020/11/15周总结
    2020/11/08周总结
  • 原文地址:https://www.cnblogs.com/kingBook/p/16170943.html
Copyright © 2020-2023  润新知