-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHierachyUI.cs
More file actions
57 lines (46 loc) · 1.56 KB
/
HierachyUI.cs
File metadata and controls
57 lines (46 loc) · 1.56 KB
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
using UnityEngine;
using System.Collections;
using UnityEditor;
[InitializeOnLoad]
public class HierachyUI
{
static HierachyUI()
{
EditorApplication.hierarchyWindowItemOnGUI += HierarchyWindowItemGui;
}
private static bool needShowUI=true;
private const string ToggleShowUI = "Tools/ShowAdditionalHierachyUI";
[MenuItem(ToggleShowUI)]
static void ToggleShow()
{
needShowUI = !needShowUI;
}
[MenuItem(ToggleShowUI,true)]
static bool ToggleShowValidate() //the function name doesnt matter here
{
Menu.SetChecked(ToggleShowUI,needShowUI);
return true;
}
static void HierarchyWindowItemGui(int instanceID, Rect selectionRect)
{
if (needShowUI == false)
{
return;
}
GameObject go = EditorUtility.InstanceIDToObject(instanceID) as GameObject;
if (go)
{
bool selected = Selection.activeObject == go;
//实际用的时候可以根据GameObject上面是否有某种Component或者其他条件来选择是否绘制这个对象的内容
GUIStyle style = GUI.skin.label;
GUIContent content = new GUIContent(go.name);
float width = style.CalcSize(content).x;
selectionRect.x = selectionRect.xMax - width;
//Debug.Log("X max"+selectionRect.xMax+"X w"+width);
Color defaltColor = GUI.color;
GUI.color = selected ? Color.green : Color.cyan;
GUI.Label(selectionRect, go.name);
GUI.color = defaltColor;
}
}
}