Skip to content
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
17 changes: 11 additions & 6 deletions HierarchyDecorator/Scripts/Editor/HierarchyGUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public static class HierarchyGUI
private static GUIStyle TextStyle = new GUIStyle(EditorStyles.label);
private static readonly Color DarkModeText = new Color(0.48f, 0.67f, 0.95f, 1f);
private static readonly Color WhiteModeText = new Color(0.1f, 0.3f, 0.7f, 1f);
private static readonly Color MissingPrefabText = new Color(0.95f, 0.55f, 0.55f);

public static void DrawHierarchyStyle(HierarchyStyle style, Rect styleRect, Rect labelRect, string label, bool removePrefix = true)
{
Expand All @@ -29,19 +30,23 @@ public static void DrawStandardContent(Rect rect, GameObject instance)
// Get the content needed for the icon

bool isPrefab = item.IsPrefab;
bool isPrefabParent = item.PrefabInfo == PrefabInfo.Root;

bool isPrefabParent = item.PrefabInfo == PrefabInfo.Root;
bool isPrefabMissing = item.PrefabTypeInfo == PrefabAssetType.MissingAsset;

GUIContent content = GetStandardContent (instance, isPrefabParent);

// Handle colours

Color textColour = EditorStyles.label.normal.textColor;
if (isPrefab)
{
textColour = (EditorGUIUtility.isProSkin) ? DarkModeText : WhiteModeText;
if (isPrefabMissing)
textColour = MissingPrefabText;
else
textColour = (EditorGUIUtility.isProSkin) ? DarkModeText : WhiteModeText;
}

if (Selection.Contains(instance))
if (Selection.Contains(instance) && ! isPrefabMissing)
{
textColour = Color.white;
}
Expand Down Expand Up @@ -103,7 +108,7 @@ public static GUIContent GetStandardContent(GameObject instance, bool isPrefab)
image = GetPrefabIcon(instance)
};
}

return EditorGUIUtility.IconContent(GetGameObjectIcon(Selection.Contains(instance)));
}

Expand Down Expand Up @@ -138,7 +143,7 @@ private static string GetGameObjectIcon(bool selected)
}

private static Texture2D GetPrefabIcon(GameObject instance)
{
{
return PrefabUtility.GetIconForGameObject(instance);
}
}
Expand Down
11 changes: 9 additions & 2 deletions HierarchyDecorator/Scripts/Editor/HierarchyItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ public class HierarchyItem
/// </summary>
public bool HasParent => Transform.parent != null;

/// <summary>
/// The type of prefab asset.
/// </summary>
public PrefabAssetType PrefabTypeInfo { get; private set; }

/// <summary>
/// The prefab state.
/// </summary>
Expand All @@ -53,7 +58,7 @@ public class HierarchyItem
/// <summary>
/// Is this item part of a prefab?
/// </summary>
public bool IsPrefab => PrefabInfo != PrefabInfo.None;
public bool IsPrefab => PrefabInfo != PrefabInfo.None;

/// <summary>
/// The display string for the item.
Expand Down Expand Up @@ -83,7 +88,7 @@ private PrefabInfo GetPrefabInfo()
{
return PrefabInfo.None;
}

return PrefabUtility.GetNearestPrefabInstanceRoot(GameObject) == GameObject
? PrefabInfo.Root
: PrefabInfo.Part;
Expand All @@ -95,6 +100,8 @@ private PrefabInfo GetPrefabInfo()
public void OnGUIBegin()
{
PrefabInfo = GetPrefabInfo();
PrefabTypeInfo = PrefabInfo == PrefabInfo.None ?
PrefabAssetType.NotAPrefab : PrefabTypeInfo = PrefabUtility.GetPrefabAssetType(GameObject);
Components.Validate(GameObject);
}

Expand Down