Skip to content

Commit

Permalink
Update CustomHierarchyActivity.cs
Browse files Browse the repository at this point in the history
added prefab support
  • Loading branch information
alisahanyalcin committed May 20, 2022
1 parent abeb382 commit 0e49b1a
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions Editor/CustomHierarchyActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
[InitializeOnLoad]
public static class CustomHierarchyActivity
{
private static float _iconPadding = 3f;
private static readonly float IconWidth = 15;
private static readonly Vector2 IconPadding = new Vector2(3, 0);
private static readonly GUIContent ActiveIcon = EditorGUIUtility.IconContent("d_scenevis_visible_hover@2x");
private static readonly GUIContent InActiveIcon = EditorGUIUtility.IconContent("d_scenevis_hidden_hover@2x");

Expand All @@ -19,21 +19,18 @@ private static void DrawIconOnHierarchyPanel(int instanceID, Rect rect)
GUIStyle icon = new GUIStyle();
GameObject instanceGameObject = EditorUtility.InstanceIDToObject(instanceID) as GameObject;
if (instanceGameObject == null) return;

_iconPadding = PrefabUtility.IsPartOfAnyPrefab(instanceGameObject) ? 15 : 3;

EditorGUIUtility.SetIconSize(new Vector2(IconWidth, IconWidth));
var iconDrawRect = new Rect(rect.xMax - IconPadding.x, rect.yMin, rect.width, rect.height);
var iconDrawRect = new Rect(rect.xMax - _iconPadding, rect.yMin, rect.width, rect.height);

var iconGUIContent = new GUIContent(ActiveIcon);
switch (instanceGameObject.activeInHierarchy)
GUIContent iconGUIContent = instanceGameObject.activeInHierarchy switch
{
case true:
iconGUIContent = new GUIContent(ActiveIcon);
break;
case false:
iconGUIContent = new GUIContent(InActiveIcon);
break;
}

true => new GUIContent(ActiveIcon),
false => new GUIContent(InActiveIcon)
};

GUI.Label(iconDrawRect, iconGUIContent, icon);

bool toggle = EditorGUI.Toggle(iconDrawRect, instanceGameObject.activeInHierarchy, icon);
Expand Down

0 comments on commit 0e49b1a

Please sign in to comment.