-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHierarchyCustomizationManager
77 lines (63 loc) · 2.9 KB
/
HierarchyCustomizationManager
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using UnityEngine;
using UnityEditor;
using Scripts.Utility;
namespace Assets.Editor
{
[InitializeOnLoad]
public class HierachyCustomizationManager : MonoBehaviour
{
public static readonly Color DEFAULT_COLOR_HIERARCHY_SELECTED = new Color(0.243f, 0.4901f, 0.9058f, 1f);
static HierachyCustomizationManager()
{
EditorApplication.hierarchyWindowItemOnGUI -= HierarchyHighlight_OnGUI;
EditorApplication.hierarchyWindowItemOnGUI += HierarchyHighlight_OnGUI;
}
private static void HierarchyHighlight_OnGUI(int inSelectionID, Rect inSelectionRect)
{
GameObject GO_Label = EditorUtility.InstanceIDToObject(inSelectionID) as GameObject;
if (GO_Label != null)
{
HierachyCustomization Label = GO_Label.GetComponent<HierachyCustomization>();
if (Label != null && Event.current.type == EventType.Repaint)
{
#region Style
bool ObjectIsSelected = Selection.instanceIDs.Contains(inSelectionID);
Color BKCol = Label.Background_Color;
Color TextCol = Label.Text_Color;
FontStyle TextStyle = Label.TextStyle;
if (!Label.isActiveAndEnabled)
{
if (BKCol != HierachyCustomization.DEFAULT_BACKGROUND_COLOR) // Reduce opacity
BKCol.a = BKCol.a * 0.5f;
TextCol.a = TextCol.a * 0.5f;
}
#endregion
Rect Offset = new Rect(inSelectionRect.position + new Vector2(2f, 0f), inSelectionRect.size);
#region Background
if (BKCol.a > 0f)
{
Rect BackgroundOffset = new Rect(inSelectionRect.position, inSelectionRect.size);
if (Label.Background_Color.a < 1f || ObjectIsSelected)
{
EditorGUI.DrawRect(BackgroundOffset, HierachyCustomization.DEFAULT_BACKGROUND_COLOR);
}
if (ObjectIsSelected)
EditorGUI.DrawRect(BackgroundOffset, Color.Lerp(GUI.skin.settings.selectionColor, BKCol, 0.3f));
else
EditorGUI.DrawRect(BackgroundOffset, BKCol);
}
#endregion
EditorGUI.LabelField(Offset, GO_Label.name, new GUIStyle()
{
normal = new GUIStyleState() { textColor = TextCol },
fontStyle = TextStyle
});
EditorApplication.RepaintHierarchyWindow();
}
}
}
}
}