Created
July 20, 2016 18:40
-
-
Save ilkinulas/802c993bb6bcdb3a45bfbdd01c2f3718 to your computer and use it in GitHub Desktop.
editor script that demonstrates how to customize hierarchy window
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using UnityEditor; | |
using System.Text; | |
[InitializeOnLoad] | |
public class CustomHierarchyView { | |
private static StringBuilder sb = new StringBuilder (); | |
static CustomHierarchyView() { | |
EditorApplication.hierarchyWindowItemOnGUI += HierarchyWindowItemOnGUI; | |
} | |
static void HierarchyWindowItemOnGUI (int instanceID, Rect selectionRect) { | |
GameObject gameObject = EditorUtility.InstanceIDToObject (instanceID) as GameObject; | |
DisplayActiveAndPassiveCardCount (selectionRect, gameObject); | |
} | |
static void DisplayActiveAndPassiveCardCount (Rect selectionRect, GameObject gameObject) | |
{ | |
Card[] cards = gameObject.GetComponentsInChildren<Card> (includeInactive: true); | |
int total = cards.Length; | |
if (total > 0 && gameObject.GetComponent<Card> () == null) { | |
ActivePassive pair = ProcessCards (cards); | |
Rect r = new Rect (selectionRect); | |
r.x += r.width - 65; | |
sb.Length = 0; | |
sb.Append (total).Append (" (").Append (pair.active).Append (", ").Append (pair.passive).Append (")"); | |
GUI.Label (r, sb.ToString ()); | |
} | |
} | |
private static ActivePassive ProcessCards(Card [] cards) { | |
ActivePassive pair = new ActivePassive (); | |
for (int i = 0; i < cards.Length; i++) { | |
Card card = cards [i]; | |
if (card.gameObject.activeInHierarchy) { | |
pair.active++; | |
} else { | |
pair.passive++; | |
} | |
} | |
return pair; | |
} | |
} | |
struct ActivePassive { | |
public int active; | |
public int passive; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment