Advertisement
Guest User

Untitled

a guest
Apr 1st, 2015
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.18 KB | None | 0 0
  1. using System.Globalization;
  2. using UnityEditor;
  3. using UnityEngine;
  4.  
  5. [InitializeOnLoad]
  6. public static class HierarchyEnhancer
  7. {
  8. private static GUIStyle _style;
  9.  
  10. static HierarchyEnhancer ()
  11. {
  12. _style = null;
  13. EditorApplication.hierarchyWindowItemOnGUI = OnGUI;
  14. }
  15.  
  16. private static void OnGUI (int instanceID, Rect selectionRect)
  17. {
  18. if (_style == null)
  19. _style = new GUIStyle (EditorStyles.label) {alignment = TextAnchor.UpperRight, richText = true};
  20.  
  21. GameObject go = EditorUtility.InstanceIDToObject (instanceID) as GameObject;
  22.  
  23. /*
  24. byte c = EditorGUIUtility.isProSkin ? (byte)56 : (byte)194;
  25. GUI.color = new Color32 (c, c, c, 255);
  26. GUI.DrawTexture (selectionRect, EditorGUIUtility.whiteTexture);
  27. // GUI.color = UniqueColor (LayerMask.LayerToName (go.layer), 25);
  28. // GUI.DrawTexture (selectionRect, EditorGUIUtility.whiteTexture);
  29. // GUI.color = Color.white;
  30. // GUI.Label (selectionRect, go.name);
  31.  
  32. GUI.color = go.layer == 0 ? Color.white : UniqueColor (LayerMask.LayerToName (go.layer));
  33. GUI.Label (selectionRect, go.name);
  34. GUI.color = Color.white;
  35. //*/
  36.  
  37. selectionRect.width -= 16;
  38.  
  39. string label = "";
  40.  
  41. // if (go.layer != 0)
  42. // label += "<color=#" + UniqueStrColor (LayerMask.LayerToName (go.layer)) + ">[" +
  43. // LayerMask.LayerToName (go.layer) +
  44. // "]</color> ";
  45.  
  46. if (!go.CompareTag ("Untagged"))
  47. label += "<color=#" + UniqueStrColor (go.tag) + ">(" + go.tag + ")</color> ";
  48.  
  49. if (go.transform.childCount > 0)
  50. label += go.transform.childCount.ToString (CultureInfo.InvariantCulture);
  51.  
  52. GUI.Label (selectionRect, label, _style);
  53.  
  54. selectionRect.x = selectionRect.xMax;
  55. selectionRect.width = 16;
  56.  
  57. if (!go.activeInHierarchy && go.activeSelf)
  58. GUI.color = new Color (1, 1, 1, 0.5f);
  59. go.SetActive (GUI.Toggle (selectionRect, go.activeSelf, "", "OL Toggle"));
  60. GUI.color = Color.white;
  61. }
  62.  
  63. private static string UniqueStrColor (string str)
  64. {
  65. return (str.GetHashCode () & 0xffffff).ToString ("x6");
  66. }
  67.  
  68. private static Color UniqueColor (string str, byte alpha = 255)
  69. {
  70. int hash = str.GetHashCode ();
  71. byte r = (byte)((hash >> 16) & 255);
  72. byte g = (byte)((hash >> 8) & 255);
  73. byte b = (byte)(hash & 255);
  74. return new Color32 (r, g, b, alpha);
  75. }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement