1 usingUnityengine;2 usingUnityeditor;3 usingSystem.Collections;4 5 Public classMyhierarchymenu6 {7[MenuItem ("Window/test/yusong")]8 Static voidTest ()9 {Ten } One A[MenuItem ("Window/test/momo")] - Static voidTest1 () - { the } -[MenuItem ("window/test/Rain Pine/momo")] - Static voidTest2 () - { + } - + A [Initializeonloadmethod] at Static voidStartinitializeonloadmethod () - { -Editorapplication.hierarchywindowitemongui + =Onhierarchygui; - } - - Static voidOnhierarchygui (intInstanceID, Rect selectionrect) in { - if(Event.current! =NULL&&selectionrect.contains (Event.current.mousePosition) to&& Event.current.button = =1&& Event.current.type <=eventtype.mouseup) + { -Gameobject selectedgameobject = Editorutility.instanceidtoobject (InstanceID) asGameobject; the //Here you can judge the conditions of Selectedgameobject. * if(Selectedgameobject) $ {Panax NotoginsengVector2 mouseposition =Event.current.mousePosition; - theEditorutility.displaypopupmenu (NewRect (mouseposition.x, MOUSEPOSITION.Y,0,0),"window/test",NULL); + Event.current.Use (); A } the } + } - $}
Original link: http://www.xuanyusong.com/archives/3893
Unity3d Editor's rewrite hierarchy right-click menu