diff --git a/Editor/HierarchyData.cs b/Editor/HierarchyData.cs index 8d855b4..e02fe26 100644 --- a/Editor/HierarchyData.cs +++ b/Editor/HierarchyData.cs @@ -6,7 +6,7 @@ namespace Febucci.HierarchyData public class HierarchyData : ScriptableObject { public bool enabled = true; - + public bool updateInPlayMode = true; public bool drawActivationToggle = true; @@ -22,14 +22,15 @@ public struct HierarchyElement { [SerializeField] public Texture2D iconToDraw; [SerializeField] public MonoScript[] targetClasses; + [SerializeField] public string[] tags; } - + public bool aligned = false; public HierarchyElement[] pairs = new HierarchyElement[0]; } - + public IconsData icons; - + #endregion #region PrefabsData @@ -50,21 +51,21 @@ public class Prefab } public PrefabsData prefabsData; - + #endregion - + #region Alternating Lines [System.Serializable] public class AlternatingBGData { public bool enabled = true; - public Color color = new Color(0,0,0, .08f); + public Color color = new Color(0, 0, 0, .08f); } public AlternatingBGData alternatingBackground; - + #endregion #region SeparatorData @@ -74,9 +75,9 @@ public class SeparatorData { public bool enabled = true; public string startString = ">"; - public Color color = new Color(0, 1,1, .15f); + public Color color = new Color(0, 1, 1, .15f); } - + public SeparatorData separator; #endregion @@ -88,7 +89,7 @@ public class TreeData { public bool enabled = true; public bool drawOverlayOnColoredPrefabs = true; - [Range(0,3)] public float dividerHeigth = 1; + [Range(0, 3)] public float dividerHeigth = 1; public Color baseLevelColor = Color.gray; [System.Serializable] @@ -106,21 +107,21 @@ public class BranchGroup overlayColor = new Color(1f, 0.44f, 0.97f, .04f), colors = new [] { - new Color(1f, 0.44f, 0.97f), - new Color(0.56f, 0.44f, 1f), - new Color(0.44f, 0.71f, 1f), + new Color(1f, 0.44f, 0.97f), + new Color(0.56f, 0.44f, 1f), + new Color(0.44f, 0.71f, 1f), new Color(0.19f, 0.53f, 0.78f) } }, - + new BranchGroup() { - overlayColor = new Color(0.93f, 1f, 0.42f, .04f), + overlayColor = new Color(0.93f, 1f, 0.42f, .04f), colors = new [] { - new Color(0.93f, 1f, 0.42f), - new Color(1f, 0.75f, 0.42f), - new Color(1f, 0.46f, 0.31f), + new Color(0.93f, 1f, 0.42f), + new Color(1f, 0.75f, 0.42f), + new Color(1f, 0.46f, 0.31f), new Color(1f, 0.35f, 0.34f) } } @@ -128,7 +129,7 @@ public class BranchGroup } public TreeData tree; - + #endregion diff --git a/Editor/HierarchyDrawer.cs b/Editor/HierarchyDrawer.cs index efcfbb0..eb5c18b 100644 --- a/Editor/HierarchyDrawer.cs +++ b/Editor/HierarchyDrawer.cs @@ -31,7 +31,7 @@ static HierarchyDrawer() { Initialize(); } - + static class HierarchyRenderer { static private HierarchyData.TreeData.BranchGroup currentBranch; @@ -46,32 +46,32 @@ static class HierarchyRenderer new Color(0.19f, 0.53f, 0.78f) } }; - + public static void SwitchBranchesColors(int hierarchyIndex) { int targetIndex = hierarchyIndex % data.tree.branches.Length; - if (data.tree.branches.Length == 0 || data.tree.branches[targetIndex].colors.Length<=0) + if (data.tree.branches.Length == 0 || data.tree.branches[targetIndex].colors.Length <= 0) { currentBranch = fallbackGroup; return; } - + currentBranch = data.tree.branches[targetIndex]; } - + private const float barWidth = 2; - + public static void DrawNestGroupOverlay(Rect originalRect) { if (currentBranch.overlayColor.a <= 0) return; - - originalRect = new Rect(32, originalRect.y, originalRect.width + (originalRect.x-32), originalRect.height); + + originalRect = new Rect(32, originalRect.y, originalRect.width + (originalRect.x - 32), originalRect.height); EditorGUI.DrawRect(originalRect, currentBranch.overlayColor); } static float GetStartX(Rect originalRect, int nestLevel) { - return 37 + (originalRect.height-2) * nestLevel; + return 37 + (originalRect.height - 2) * nestLevel; //return originalRect.x //aligned start position (9 is the magic number here) // - originalRect.height * 2 //GameObject icon offset // + 9 @@ -85,49 +85,49 @@ static Color GetNestColor(int nestLevel) public static void DrawVerticalLineFrom(Rect originalRect, int nestLevel) { - DrawHalfVerticalLineFrom(originalRect, true, nestLevel); - DrawHalfVerticalLineFrom(originalRect, false, nestLevel); + DrawHalfVerticalLineFrom(originalRect, true, nestLevel); + DrawHalfVerticalLineFrom(originalRect, false, nestLevel); } public static void DrawHalfVerticalLineFrom(Rect originalRect, bool startsOnTop, int nestLevel) { - if(currentBranch.colors.Length<=0) return; + if (currentBranch.colors.Length <= 0) return; DrawHalfVerticalLineFrom(originalRect, startsOnTop, nestLevel, GetNestColor(nestLevel)); } - + public static void DrawHalfVerticalLineFrom(Rect originalRect, bool startsOnTop, int nestLevel, Color color) { //Vertical rect, starts from the very left and then proceeds to te right EditorGUI.DrawRect( new Rect( - GetStartX(originalRect, nestLevel), - startsOnTop ? originalRect.y : (originalRect.y + originalRect.height/2f), - barWidth, - originalRect.height/2f - ), + GetStartX(originalRect, nestLevel), + startsOnTop ? originalRect.y : (originalRect.y + originalRect.height / 2f), + barWidth, + originalRect.height / 2f + ), color ); } public static void DrawHorizontalLineFrom(Rect originalRect, int nestLevel, bool hasChilds) { - if(currentBranch.colors.Length<=0) return; - + if (currentBranch.colors.Length <= 0) return; + //Vertical rect, starts from the very left and then proceeds to te right EditorGUI.DrawRect( new Rect( - GetStartX(originalRect, nestLevel), - originalRect.y + originalRect.height/2f, - originalRect.height + (hasChilds ? -5 : 2), + GetStartX(originalRect, nestLevel), + originalRect.y + originalRect.height / 2f, + originalRect.height + (hasChilds ? -5 : 2), //originalRect.height - 5, barWidth - ), + ), GetNestColor(nestLevel) ); } } - + #region Types [Serializable] @@ -145,7 +145,7 @@ struct InstanceInfo public bool isLastElement; public bool hasChilds; public bool topParentHasChild; - + public int nestingGroup; public int nestingLevel; } @@ -245,9 +245,9 @@ static void CreateAsset() Debug.LogWarning("HierarchyIcons: Data already exists, won't create a new one."); return; } - + //Creates folder - if(!AssetDatabase.IsValidFolder("Assets/Editor Default Resources")) + if (!AssetDatabase.IsValidFolder("Assets/Editor Default Resources")) AssetDatabase.CreateFolder("Assets", "Editor Default Resources"); string path = "Assets/Editor Default Resources/Febucci"; @@ -311,16 +311,16 @@ public static void Initialize() #endregion RetrieveDataFromScene(); - + prefabColors.Clear(); foreach (var prefab in data.prefabsData.prefabs) { - if (prefab.color.a<=0) continue; + if (prefab.color.a <= 0) continue; if (!prefab.gameObject) continue; - + int instanceID = prefab.gameObject.GetInstanceID(); - if(prefabColors.ContainsKey(instanceID)) continue; - + if (prefabColors.ContainsKey(instanceID)) continue; + prefabColors.Add(instanceID, prefab.color); } } @@ -341,11 +341,11 @@ static void RetrieveDataFromScene() sceneGameObjects.Clear(); iconsPositions.Clear(); - var prefabStage = UnityEditor.Experimental.SceneManagement.PrefabStageUtility.GetCurrentPrefabStage(); + var prefabStage = UnityEditor.SceneManagement.PrefabStageUtility.GetCurrentPrefabStage(); if (prefabStage != null) { - var prefabContentsRoot = UnityEditor.Experimental.SceneManagement.PrefabStageUtility.GetCurrentPrefabStage().prefabContentsRoot; - + var prefabContentsRoot = UnityEditor.SceneManagement.PrefabStageUtility.GetCurrentPrefabStage().prefabContentsRoot; + AnalyzeGoWithChildren( go: prefabContentsRoot, nestingLevel: -1, @@ -361,7 +361,7 @@ static void RetrieveDataFromScene() GameObject[] sceneRoots; Scene tempScene; firstInstanceID = -1; - + for (int i = 0; i < SceneManager.sceneCount; i++) { tempScene = SceneManager.GetSceneAt(i); @@ -413,7 +413,7 @@ static void AnalyzeGoWithChildren(GameObject go, int nestingLevel, bool topParen newInfo.isSeparator = String.Compare(go.tag, "EditorOnly", StringComparison.Ordinal) == 0 //gameobject has EditorOnly tag && (!string.IsNullOrEmpty(go.name) && !string.IsNullOrEmpty(data.separator.startString) && go.name.StartsWith(data.separator.startString)); //and also starts with '>' - if (data.icons.enabled && data.icons.pairs!=null && data.icons.pairs.Length>0) + if (data.icons.enabled && data.icons.pairs != null && data.icons.pairs.Length > 0) { #region Components Information (icons) @@ -423,7 +423,7 @@ static void AnalyzeGoWithChildren(GameObject go, int nestingLevel, bool topParen foreach (var c in go.GetComponents()) { - if(!c) continue; + if (!c) continue; componentType = c.GetType(); @@ -434,11 +434,11 @@ static void AnalyzeGoWithChildren(GameObject go, int nestingLevel, bool topParen //Class inherithance foreach (var classReference in data.icons.pairs[elementIndex].targetClasses) { - if(!classReference) continue; - + if (!classReference) continue; + classReferenceType = classReference.GetClass(); - - if(!classReferenceType.IsClass) continue; + + if (!classReferenceType.IsClass) continue; //class ineriths if (componentType.IsAssignableFrom(classReferenceType) || componentType.IsSubclassOf(classReferenceType)) @@ -454,6 +454,23 @@ static void AnalyzeGoWithChildren(GameObject go, int nestingLevel, bool topParen break; } } + + // Tags + foreach (var tag in data.icons.pairs[elementIndex].tags) + { + // Matched tag + if (go.tag == tag) + { + //Adds the icon index to the "positions" list, to draw all of them in order later [if enabled] + if (!iconsPositions.Contains(elementIndex)) iconsPositions.Add(elementIndex); + + //Adds the icon index to draw, only if it's not present already + if (!newInfo.iconIndexes.Contains(elementIndex)) + newInfo.iconIndexes.Add(elementIndex); + + break; + } + } } } @@ -490,7 +507,7 @@ static void AnalyzeGoWithChildren(GameObject go, int nestingLevel, bool topParen private static InstanceInfo currentItem; private static bool drawedPrefabOverlay; - + static void DrawCore(int instanceID, Rect selectionRect) { //skips early if item is not registered or not valid @@ -502,7 +519,7 @@ static void DrawCore(int instanceID, Rect selectionRect) if (instanceID == firstInstanceID) { - temp_alternatingDrawed = currentItem.nestingGroup %2 == 0; + temp_alternatingDrawed = currentItem.nestingGroup % 2 == 0; } #region Draw Activation Toggle @@ -545,14 +562,14 @@ static void DrawCore(int instanceID, Rect selectionRect) temp_alternatingDrawed = true; } } - + #endregion #region DrawingPrefabsBackground drawedPrefabOverlay = false; - if (data.prefabsData.enabled && prefabColors.Count>0) + if (data.prefabsData.enabled && prefabColors.Count > 0) { if (prefabColors.ContainsKey(currentItem.prefabInstanceID)) { @@ -560,10 +577,10 @@ static void DrawCore(int instanceID, Rect selectionRect) drawedPrefabOverlay = true; } } - + #endregion - + #region Drawing Tree if (data.tree.enabled @@ -578,7 +595,7 @@ static void DrawCore(int instanceID, Rect selectionRect) { HierarchyRenderer.DrawNestGroupOverlay(selectionRect); } - + if (currentItem.nestingLevel == 0 && !currentItem.hasChilds) { @@ -592,11 +609,11 @@ static void DrawCore(int instanceID, Rect selectionRect) { HierarchyRenderer.DrawVerticalLineFrom(selectionRect, i); } - - HierarchyRenderer.DrawHorizontalLineFrom( - selectionRect, currentItem.nestingLevel, currentItem.hasChilds - ); - + + HierarchyRenderer.DrawHorizontalLineFrom( + selectionRect, currentItem.nestingLevel, currentItem.hasChilds + ); + } } @@ -611,16 +628,16 @@ static void DrawCore(int instanceID, Rect selectionRect) ); EditorGUI.DrawRect(boldGroupRect, Color.black * .3f); } - + } #endregion #region Drawing Separators - + //EditorOnly objects are only removed from build if they're not childrens - if (data.separator.enabled && data.separator.color.a >0 + if (data.separator.enabled && data.separator.color.a > 0 && currentItem.isSeparator && currentItem.nestingLevel == 0) { //Adds color on top of the label @@ -671,7 +688,7 @@ int CalculateIconPosition() { //Draws the gameobject icon, if present var content = EditorGUIUtility.ObjectContent(go ?? EditorUtility.InstanceIDToObject(instanceID), null); - + if (content.image && !string.IsNullOrEmpty(content.image.name)) { if (content.image.name != "d_GameObject Icon" && content.image.name != "d_Prefab Icon") @@ -687,9 +704,9 @@ int CalculateIconPosition() } } } - - - + + + for (int i = 0; i < currentItem.iconIndexes.Count; i++) { DrawIcon(currentItem.iconIndexes[i]);