Created
November 18, 2020 10:40
-
-
Save Sov3rain/97caf8c6e3fb266f27f0240ae56c6914 to your computer and use it in GitHub Desktop.
Editor class to override the default color highlighting effect of prefabs in hierarchy.
This file contains hidden or 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 System.Linq; | |
using UnityEditor; | |
using UnityEngine; | |
[InitializeOnLoad] | |
public class CustomHierarchy : MonoBehaviour | |
{ | |
private static Vector2 offset = new Vector2(0, 2); | |
static CustomHierarchy() | |
{ | |
EditorApplication.hierarchyWindowItemOnGUI += HandleHierarchyWindowItemOnGUI; | |
} | |
private static void HandleHierarchyWindowItemOnGUI(int instanceID, Rect selectionRect) | |
{ | |
Color fontColor = Color.blue; | |
Color backgroundColor = new Color(.76f, .76f, .76f); | |
var obj = EditorUtility.InstanceIDToObject(instanceID); | |
if (obj != null) | |
{ | |
var prefabType = PrefabUtility.GetPrefabType(obj); | |
if (prefabType == PrefabType.PrefabInstance) | |
{ | |
if (Selection.instanceIDs.Contains(instanceID)) | |
{ | |
fontColor = Color.white; | |
backgroundColor = new Color(0.24f, 0.48f, 0.90f); | |
} | |
Rect offsetRect = new Rect(selectionRect.position + offset, selectionRect.size); | |
EditorGUI.DrawRect(selectionRect, backgroundColor); | |
EditorGUI.LabelField(offsetRect, obj.name, new GUIStyle() | |
{ | |
normal = new GUIStyleState() { textColor = fontColor }, | |
fontStyle = FontStyle.Bold | |
} | |
); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment