Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added two toggles to manage gameobject icon for a cleaner look: #11

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Editor/HierarchyData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down
72 changes: 44 additions & 28 deletions Editor/HierarchyDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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---
Expand All @@ -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;
}
Expand All @@ -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
Expand Down