Sun Guangdong 2015.5.27
Reprint Please specify source: http://blog.csdn.net/u010019717
To achieve the following effect: In fact, the main thing is to identify some of the more special objects (or objects with special components)
The way to do this is to listen to some of unity's events being
Editorapplication.hierarchywindowchanged + = hierarchywindowchanged;
Editorapplication.hierarchywindowitemongui + = Hierarchywindowitemongui;
It is necessary to indicate that this class is a derived class of assetpostprocessor.
After the resource import processing class, it is best not to do too much time-consuming operations here, otherwise the Unity editor will be in the process of pre-compilation and import processing in the bottom right corner of the editor has a small circle and then the transfer has a long period of lag
Using unityengine;using system.collections;using system.collections.generic;using system.io;using DajiaGame.Px; Using unityeditor;///<summary>///Import resource Post processing class///////////////Sun Guangdong Now is a special identification of some special objects on the hierarchy Panel///</summary>public Class pxcustomhierarchy:assetpostprocessor{//<summary>//Internal storage Icons///</summary> public STA Tic class Icons {public static texture2d posebones; public static texture2d image; public static texture2d BoundingBox; public static texture2d mesh; public static texture2d warning; public static void Initialize () {posebones = (texture2d) Assetdatabase.loadmainassetatpath (Spineeditorut Ilities.editorguipath + "/icon-posebones.png"); Image = (texture2d) assetdatabase.loadmainassetatpath (Spineeditorutilities.editorguipath + "/icon-image.png"); BoundingBox = (texture2d) assetdatabase.loadmainassetatpath (Spineeditorutilities.editorguipath + "/ Icon-boundingbox.pnG "); Mesh = (texture2d) assetdatabase.loadmainassetatpath (Spineeditorutilities.editorguipath + "/icon-mesh.png"); Warning = (texture2d) assetdatabase.loadmainassetatpath (Spineeditorutilities.editorguipath + "/icon-warning.png"); }}//Data public static string Editorpath = ""; public static string Editorguipath = ""; Static Dictionary<int, gameobject> skeletonrenderertable; Static Dictionary<int, canvas> canvastable; public static float Defaultscale = 0.01f; public static float defaultmix = 0.2f; public static string defaultshader = "Spine/skeleton"; public static bool initialized; Const string Default_mix_key = "Spine_default_mix"; Static constructor Pxcustomhierarchy () {Initialize ();} static void Initialize () {defaultmix = Editorprefs.getfloat (Default_mix_key, 0.2f);D irectoryinfo rootdir = new Directory Info (Application.datapath); fileinfo[] files = rootdir.getfiles ("SpineEditorUtilities.cs", Searchoption.alldirectories); Editorpath = Path.getdirectoryname (Files[0]. Fullname.replace ("\ \", "/"). Replace (Application.datapath, "Assets")), Editorguipath = Editorpath + "/gui"; Icons. Initialize (); canvastable = new Dictionary<int, canvas> (); Editorapplication.hierarchywindowchanged + = hierarchywindowchanged; Editorapplication.hierarchywindowitemongui + = Hierarchywindowitemongui; Hierarchywindowchanged (); initialized = true;} static void Hierarchywindowchanged () {canvastable.clear (); canvas[] Bonearr = object.findobjectsoftype<canvas> (); foreach (Canvas b in Bonearr) Canvastable.add (B.gameobject.getinstanceid (), b); }///<summary>///The root node is shown later, otherwise in front///</summary>//<param name= "InstanceId" ></PARAM&G T <param name= "Selectionrect" ></param> static void Hierarchywindowitemongui (int instanceId, Rect selecti Onrect) {if (Canvastable.containskey (instanceId)) {if (CAnvastable[instanceid].transform.root = = canvastable[instanceid].transform) {//mydebuglog.log (" This is root node: "+ Canvastable[instanceid].gameobject.name); Rect r = new rect (selectionrect); r.x = r.width-15; R.width = 15; Gui. Label (R, SpineEditorUtilities.Icons.poseBones); } else if (Canvastable[instanceid]! = null) {rect r = new rect (selectionrect); R.x-= 26; if (Canvastable[instanceid].transform.childcount = = 0) r.x + = 13; R.y + = 2; R.width = 13; R.height = 13; Gui. Drawtexture (R, SpineEditorUtilities.Icons.poseBones); } } }}
Unity handles special identification of some special objects on the hierarchy panel