码迷,mamicode.com
首页 > 编程语言 > 详细

Unity3D编辑器之重写Hierarchy的右键菜单

时间:2017-08-10 20:57:11      阅读:186      评论:0      收藏:0      [点我收藏+]

标签:hive   too   logs   get   span   art   pop   sep   eid   

 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

Unity3D编辑器之重写Hierarchy的右键菜单

标签:hive   too   logs   get   span   art   pop   sep   eid   

原文地址:http://www.cnblogs.com/AaronBlogs/p/7340966.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!