From 60f742e5948d6a0575ce7c747efc26406d230b8c Mon Sep 17 00:00:00 2001 From: Chakib Chemso Date: Wed, 22 Dec 2021 21:30:37 +0100 Subject: [PATCH] added two toggles for a cleaner look: drawGameObjectIcon: whether to draw it or not drawGOIconOnlyIfNoPairSet: whether to draw it only when no pair set --- Editor/HierarchyData.cs | 3 ++ Editor/HierarchyDrawer.cs | 72 ++++++++++++++++++++++++--------------- 2 files changed, 47 insertions(+), 28 deletions(-) diff --git a/Editor/HierarchyData.cs b/Editor/HierarchyData.cs index 8d855b4..ce8b05b 100644 --- a/Editor/HierarchyData.cs +++ b/Editor/HierarchyData.cs @@ -17,6 +17,9 @@ public class HierarchyData : ScriptableObject public class IconsData { public bool enabled = true; + public bool drawGameObjectIcon = true; + public bool drawGOIconOnlyIfNoPairSet = true; + [System.Serializable] public struct HierarchyElement { diff --git a/Editor/HierarchyDrawer.cs b/Editor/HierarchyDrawer.cs index efcfbb0..4b50d67 100644 --- a/Editor/HierarchyDrawer.cs +++ b/Editor/HierarchyDrawer.cs @@ -341,10 +341,10 @@ 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, @@ -633,9 +633,9 @@ static void DrawCore(int instanceID, Rect selectionRect) if (data.icons.enabled) { - #region Local Method + #region Local Methods - //Draws each component icon + // Draws each component icon void DrawIcon(int textureIndex) { //---Icon Alignment--- @@ -644,10 +644,9 @@ void DrawIcon(int textureIndex) //Aligns icon based on texture's position on the array int CalculateIconPosition() { - for (int i = 0; i < iconsPositions.Count; i++) - { - if (iconsPositions[i] == textureIndex) return i; - } + for (var i = 0; i < iconsPositions.Count; i++) + if (iconsPositions[i] == textureIndex) + return i; return 0; } @@ -663,37 +662,54 @@ int CalculateIconPosition() GUI.DrawTexture( new Rect(selectionRect.xMax - 16 * (temp_iconsDrawedCount + 1) - 2, selectionRect.yMin, 16, 16), data.icons.pairs[textureIndex].iconToDraw - ); + ); } - - #endregion - + + // Draws each gameobject icon + void DrawGameObjectIcon() { - //Draws the gameobject icon, if present - var content = EditorGUIUtility.ObjectContent(go ?? EditorUtility.InstanceIDToObject(instanceID), null); - + //if enabled + 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") { temp_iconsDrawedCount++; GUI.DrawTexture( - new Rect( - selectionRect.xMax - 16 * (temp_iconsDrawedCount + 1) - 2, selectionRect.yMin, 16, - 16 - ), - content.image - ); + new Rect(selectionRect.xMax - 16 * (temp_iconsDrawedCount + 1) - 2, + selectionRect.yMin, + 16, + 16), + content.image); } - } } - - - - for (int i = 0; i < currentItem.iconIndexes.Count; i++) + + #endregion + + //Draws the gameobject icon, if present & enabled + if (data.icons.drawGameObjectIcon) { - DrawIcon(currentItem.iconIndexes[i]); + //whether to draw only when no pair set + if (data.icons.drawGOIconOnlyIfNoPairSet) + { + //no pair draw + if (currentItem.iconIndexes.Count.Equals(0)) + { + DrawGameObjectIcon(); + } + + //else dont draw + } + else + { + DrawGameObjectIcon(); + } } + + //Draws the component icons, if present + foreach (var index in currentItem.iconIndexes) DrawIcon(index); } #endregion