diff --git a/HierarchyDecorator/Scripts/Editor/Hierarchy/Drawers/PrefabOverrideDrawer.cs b/HierarchyDecorator/Scripts/Editor/Hierarchy/Drawers/PrefabOverrideDrawer.cs new file mode 100644 index 0000000..3071276 --- /dev/null +++ b/HierarchyDecorator/Scripts/Editor/Hierarchy/Drawers/PrefabOverrideDrawer.cs @@ -0,0 +1,44 @@ +using System.Collections.Generic; +using UnityEditor.SceneManagement; +using UnityEditor; +using UnityEngine; + +namespace HierarchyDecorator +{ + public class PrefabOverrideDrawer : HierarchyDrawer + { + protected override bool DrawerIsEnabled(HierarchyItem item, Settings settings) => settings.styleData.twoToneBackground && PrefabStageUtility.GetCurrentPrefabStage() == null; + + protected override void DrawInternal(Rect rect, HierarchyItem item, Settings _settings) + { + rect.width = 2; + +#if UNITY_2019_1_OR_NEWER + rect.x = 32; +#else + rect.x = 1f; + rect.y--; +#endif + + GameObject instance = item.GameObject; + + //Draw the little bar that indicates there's modifications in your prefab instance. + DrawPrefabOverrideBar(rect, instance); + } + + private void DrawPrefabOverrideBar(Rect rect, GameObject instance) + { + PrefabInstanceStatus status = PrefabUtility.GetPrefabInstanceStatus(instance); + if (status == PrefabInstanceStatus.Connected) + { + bool condition = false; +#if UNITY_2018_3_OR_NEWER + condition = PrefabUtility.GetObjectOverrides(instance).Count > 0; +#else + condition = PrefabUtility.GetPropertyModifications(instance).Count > 0; +#endif + if (condition) EditorGUI.DrawRect(rect, Color.cyan); + } + } + } +} \ No newline at end of file diff --git a/HierarchyDecorator/Scripts/Editor/Hierarchy/Drawers/PrefabOverrideDrawer.cs.meta b/HierarchyDecorator/Scripts/Editor/Hierarchy/Drawers/PrefabOverrideDrawer.cs.meta new file mode 100644 index 0000000..48316dd --- /dev/null +++ b/HierarchyDecorator/Scripts/Editor/Hierarchy/Drawers/PrefabOverrideDrawer.cs.meta @@ -0,0 +1,2 @@ +fileFormatVersion: 2 +guid: e4b57c62685e25447b8aacf4fe5d46b3 \ No newline at end of file diff --git a/HierarchyDecorator/Scripts/Editor/HierarchyManager.cs b/HierarchyDecorator/Scripts/Editor/HierarchyManager.cs index 3d34f24..9a6419a 100644 --- a/HierarchyDecorator/Scripts/Editor/HierarchyManager.cs +++ b/HierarchyDecorator/Scripts/Editor/HierarchyManager.cs @@ -31,7 +31,8 @@ public static class HierarchyManager { new StateDrawer(), new ToggleDrawer(), - new BreadcrumbsDrawer() + new BreadcrumbsDrawer(), + new PrefabOverrideDrawer() }; private static HierarchyInfo[] Info = new HierarchyInfo[]