Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Globalization;
- using UnityEditor;
- using UnityEngine;
- [InitializeOnLoad]
- public static class HierarchyEnhancer
- {
- private static GUIStyle _style;
- static HierarchyEnhancer ()
- {
- _style = null;
- EditorApplication.hierarchyWindowItemOnGUI = OnGUI;
- }
- private static void OnGUI (int instanceID, Rect selectionRect)
- {
- if (_style == null)
- _style = new GUIStyle (EditorStyles.label) {alignment = TextAnchor.UpperRight, richText = true};
- GameObject go = EditorUtility.InstanceIDToObject (instanceID) as GameObject;
- /*
- byte c = EditorGUIUtility.isProSkin ? (byte)56 : (byte)194;
- GUI.color = new Color32 (c, c, c, 255);
- GUI.DrawTexture (selectionRect, EditorGUIUtility.whiteTexture);
- // GUI.color = UniqueColor (LayerMask.LayerToName (go.layer), 25);
- // GUI.DrawTexture (selectionRect, EditorGUIUtility.whiteTexture);
- // GUI.color = Color.white;
- // GUI.Label (selectionRect, go.name);
- GUI.color = go.layer == 0 ? Color.white : UniqueColor (LayerMask.LayerToName (go.layer));
- GUI.Label (selectionRect, go.name);
- GUI.color = Color.white;
- //*/
- selectionRect.width -= 16;
- string label = "";
- // if (go.layer != 0)
- // label += "<color=#" + UniqueStrColor (LayerMask.LayerToName (go.layer)) + ">[" +
- // LayerMask.LayerToName (go.layer) +
- // "]</color> ";
- if (!go.CompareTag ("Untagged"))
- label += "<color=#" + UniqueStrColor (go.tag) + ">(" + go.tag + ")</color> ";
- if (go.transform.childCount > 0)
- label += go.transform.childCount.ToString (CultureInfo.InvariantCulture);
- GUI.Label (selectionRect, label, _style);
- selectionRect.x = selectionRect.xMax;
- selectionRect.width = 16;
- if (!go.activeInHierarchy && go.activeSelf)
- GUI.color = new Color (1, 1, 1, 0.5f);
- go.SetActive (GUI.Toggle (selectionRect, go.activeSelf, "", "OL Toggle"));
- GUI.color = Color.white;
- }
- private static string UniqueStrColor (string str)
- {
- return (str.GetHashCode () & 0xffffff).ToString ("x6");
- }
- private static Color UniqueColor (string str, byte alpha = 255)
- {
- int hash = str.GetHashCode ();
- byte r = (byte)((hash >> 16) & 255);
- byte g = (byte)((hash >> 8) & 255);
- byte b = (byte)(hash & 255);
- return new Color32 (r, g, b, alpha);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement