Last active
September 8, 2016 08:23
-
-
Save kalineh/0d439a107517510c28606f31478c37dd to your computer and use it in GitHub Desktop.
Show icon next to items that are prefab root objects.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
using System.Collections.Generic; | |
#if UNITY_EDITOR | |
using UnityEditor; | |
[InitializeOnLoad()] | |
class PrefabStatusHelper | |
{ | |
static PrefabStatusHelper() | |
{ | |
iconPrefabSelf = EditorGUIUtility.ObjectContent(null, typeof(GameObject)).image; | |
iconPrefabParent = EditorGUIUtility.ObjectContent(null, typeof(Transform)).image; | |
EditorApplication.hierarchyWindowItemOnGUI -= OnHierarchyItem; | |
EditorApplication.hierarchyWindowItemOnGUI += OnHierarchyItem; | |
EditorApplication.RepaintHierarchyWindow(); | |
} | |
static Texture iconPrefabSelf; | |
static Texture iconPrefabParent; | |
static GUIStyle prefabTagStyle; | |
static void OnHierarchyItem(int instanceID, Rect instanceRect) | |
{ | |
if (prefabTagStyle == null) | |
{ | |
prefabTagStyle = new GUIStyle(GUI.skin.label); | |
prefabTagStyle.fontStyle = FontStyle.Italic; | |
} | |
var obj = EditorUtility.InstanceIDToObject(instanceID); | |
var gameObject = obj as GameObject; | |
if (!gameObject) | |
return; | |
var prefabType = PrefabUtility.GetPrefabType(obj); | |
if (prefabType == PrefabType.None) | |
return; | |
var root = PrefabUtility.FindRootGameObjectWithSameParentPrefab(gameObject); | |
var prefabParent = PrefabUtility.GetPrefabParent(root); | |
var prefabSelf = PrefabUtility.GetPrefabParent(gameObject); | |
var prefabObject = PrefabUtility.GetPrefabObject(gameObject); | |
var text = (string)null; | |
var icon = (Texture)null; | |
if (root == gameObject) | |
{ | |
// seems super slow | |
//var modifications = PrefabUtility.GetPropertyModifications(prefabSelf); | |
//var changed = modifications.Length > 0; | |
text = ""; | |
icon = iconPrefabSelf; | |
} | |
if (text == null || icon == null) | |
return; | |
var nameSize = GUI.skin.label.CalcSize(new GUIContent(gameObject.name)); | |
var textRect = new Rect(); | |
var iconRect = new Rect(); | |
iconRect.x = instanceRect.xMin + nameSize.x; | |
iconRect.y = instanceRect.yMin + 2; | |
iconRect.width = 16; | |
iconRect.height = nameSize.y - 1; | |
textRect.x = iconRect.x + 18; | |
textRect.y = iconRect.y; | |
textRect.width = 64; | |
textRect.height = iconRect.height; | |
GUI.Label(iconRect, icon, GUI.skin.label); | |
GUI.Label(textRect, text, prefabTagStyle); | |
return; | |
} | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment