Unity processes the special identifiers of some special objects on the Hierarchy panel, unityhierarchy

Source: Internet
Author: User

Unity processes the special identifiers of some special objects on the Hierarchy panel, unityhierarchy

Sun Guangdong 2015.5.27

Reprinted please indicate the source: http://blog.csdn.net/u010019717

To achieve the following results: in fact, we mainly need to identify some special objects (or objects with special components)

The implementation method is to listen to some Unity events


EditorApplication. hierarchyWindowChanged + = HierarchyWindowChanged;
EditorApplication. hierarchyWindowItemOnGUI + = HierarchyWindowItemOnGUI;

It must be specified that this class is the derived class of AssetPostprocessor.

Resource import post-processing class, it is best not to perform too many time-consuming operations here, otherwise the Unity editor will be stuck, it takes a long time to get stuck when there is a small circle in the lower right corner of the editor for pre-compilation and import.

Using UnityEngine; using System. collections; using System. collections. generic; using System. IO; using DajiaGame. px; using UnityEditor; /// <summary> /// post-processing class for imported resources //// sun Guangdong is now handling special identifiers of some special objects on the Hierarchy panel. /// </ summary> public class PxCustomHierarchy: assetPostprocessor {// <summary> // internal class storage icon /// </summary> public static class Icons {public static Texture2D poseBones; public static Texture2D image; pu Blic static Texture2D boundingBox; public static Texture2D mesh; public static Texture2D warning; public static void Initialize () {poseBones = (Texture2D) AssetDatabase. loadMainAssetAtPath (SpineEditorUtilities. editorGUIPath + "/icon-poseBones.png"); image = (Texture2D) AssetDatabase. loadMainAssetAtPath (SpineEditorUtilities. editorGUIPath + "/icon-image.png"); boundingBox = (Texture2D) AssetDatabase. L OadMainAssetAtPath (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 defamix mix = 0.2f; public static string defaultShader = "Spine/Skeleton"; public static bool initialized; const string DEFAULT_MIX_KEY = "SPINE_DEFAULT_MIX"; // static constructor static PxCustomHierarchy () {Initialize ();} static void Initialize () {defaul TMix = EditorPrefs. getFloat (DEFAULT_MIX_KEY, 0.2f); DirectoryInfo rootDir = new DirectoryInfo (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 Dictio Nary <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 displayed later, otherwise it is in front of /// </summary> /// <param name = "instanceId"> </param> /// <param name = "selectionRect"> </param> static void HierarchyWindowItemOnGUI (int instanceId, rect selectionRect) {if (CanvasTable. containsKey (instanceId) {if (CanvasTable [instanceId]. transform. root = CanvasTable [instanceId]. transform) {// MyDebugLog. log ("this is the root node root:" + CanvasTable [instanceId]. gameObject. nam E); 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 );}}}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.