1 using UnityEngine; 2 using UnityEditor; 3 using System.Collections; 4 5 public class MyHierarchyMenu 6 { 7 [MenuItem("Window/Test/yusong")] 8 static void Test() 9 { 10 } 11 12 [MenuItem("Window/Test/momo")] 13 static void Test1() 14 { 15 } 16 [MenuItem("Window/Test/雨松/MOMO")] 17 static void Test2() 18 { 19 } 20 21 22 [InitializeOnLoadMethod] 23 static void StartInitializeOnLoadMethod() 24 { 25 EditorApplication.hierarchyWindowItemOnGUI += OnHierarchyGUI; 26 } 27 28 static void OnHierarchyGUI(int instanceID, Rect selectionRect) 29 { 30 if (Event.current != null && selectionRect.Contains(Event.current.mousePosition) 31 && Event.current.button == 1 && Event.current.type <= EventType.mouseUp) 32 { 33 GameObject selectedGameObject = EditorUtility.InstanceIDToObject(instanceID) as GameObject; 34 //这里可以判断selectedGameObject的条件 35 if (selectedGameObject) 36 { 37 Vector2 mousePosition = Event.current.mousePosition; 38 39 EditorUtility.DisplayPopupMenu(new Rect(mousePosition.x, mousePosition.y, 0, 0), "Window/Test",null); 40 Event.current.Use(); 41 } 42 } 43 } 44 45 }
原文链接:http://www.xuanyusong.com/archives/3893
时间: 2024-11-05 12:30:33