Skip to content

Commit c8348c6

Browse files
authored
Merge pull request #91 from pancake-llc/main
Add: tree map and row separator for hierarchy
2 parents e12798c + 8cc5448 commit c8348c6

17 files changed

+953
-2
lines changed

Alchemy/Assets/Alchemy/Editor/AlchemySettings.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,32 @@ internal static SettingsProvider CreateSettingsProvider()
6868
EditorGUILayout.PropertyField(serializedObject.FindProperty("hierarchyObjectMode"));
6969
EditorGUILayout.PropertyField(serializedObject.FindProperty("showHierarchyToggles"), new GUIContent("Show Toggles"));
7070
EditorGUILayout.PropertyField(serializedObject.FindProperty("showComponentIcons"));
71+
var showTreeMap = serializedObject.FindProperty("showTreeMap");
72+
EditorGUILayout.PropertyField(showTreeMap);
73+
if (showTreeMap.boolValue)
74+
{
75+
EditorGUI.indentLevel++;
76+
EditorGUILayout.PropertyField(serializedObject.FindProperty("treeMapColor"), new GUIContent("Color"));
77+
EditorGUI.indentLevel--;
78+
}
79+
80+
var showSeparator = serializedObject.FindProperty("showSeparator");
81+
EditorGUILayout.PropertyField(showSeparator, new GUIContent("Show Row Separator"));
82+
if (showSeparator.boolValue)
83+
{
84+
EditorGUI.indentLevel++;
85+
EditorGUILayout.PropertyField(serializedObject.FindProperty("separatorColor"), new GUIContent("Color"));
86+
EditorGUI.indentLevel--;
87+
var showRowShading = serializedObject.FindProperty("showRowShading");
88+
EditorGUILayout.PropertyField(showRowShading);
89+
if (showRowShading.boolValue)
90+
{
91+
EditorGUI.indentLevel++;
92+
EditorGUILayout.PropertyField(serializedObject.FindProperty("evenRowColor"));
93+
EditorGUILayout.PropertyField(serializedObject.FindProperty("oddRowColor"));
94+
EditorGUI.indentLevel--;
95+
}
96+
}
7197

7298
if (changeCheck.changed)
7399
{
@@ -84,9 +110,23 @@ internal static SettingsProvider CreateSettingsProvider()
84110
[SerializeField] HierarchyObjectMode hierarchyObjectMode = HierarchyObjectMode.RemoveInBuild;
85111
[SerializeField] bool showHierarchyToggles;
86112
[SerializeField] bool showComponentIcons;
113+
[SerializeField] bool showTreeMap;
114+
[SerializeField] Color treeMapColor = new(0.53f, 0.53f, 0.53f, 0.45f);
115+
[SerializeField] bool showSeparator;
116+
[SerializeField] bool showRowShading;
117+
[SerializeField] Color separatorColor = new(0.19f, 0.19f, 0.19f, 0f);
118+
[SerializeField] Color evenRowColor = new(0f, 0f, 0f, 0.07f);
119+
[SerializeField] Color oddRowColor = Color.clear;
87120

88121
public HierarchyObjectMode HierarchyObjectMode => hierarchyObjectMode;
89122
public bool ShowHierarchyToggles => showHierarchyToggles;
90123
public bool ShowComponentIcons => showComponentIcons;
124+
public bool ShowTreeMap => showTreeMap;
125+
public Color TreeMapColor => treeMapColor;
126+
public bool ShowSeparator => showSeparator;
127+
public bool ShowRowShading => showRowShading;
128+
public Color SeparatorColor => separatorColor;
129+
public Color EvenRowColor => evenRowColor;
130+
public Color OddRowColor => oddRowColor;
91131
}
92132
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using UnityEditor;
2+
using UnityEngine;
3+
4+
namespace Alchemy.Editor
5+
{
6+
public class HierarchyRowSeparatorDrawer : HierarchyDrawer
7+
{
8+
public override void OnGUI(int instanceID, Rect selectionRect)
9+
{
10+
var settings = AlchemySettings.GetOrCreateSettings();
11+
if (!settings.ShowSeparator) return;
12+
var rect = new Rect {y = selectionRect.y, width = selectionRect.width + selectionRect.x, height = 1, x = 0};
13+
14+
EditorGUI.DrawRect(rect, settings.SeparatorColor);
15+
16+
if (!settings.ShowRowShading) return;
17+
selectionRect.width += selectionRect.x;
18+
selectionRect.x = 0;
19+
selectionRect.height -= 1;
20+
selectionRect.y += 1;
21+
EditorGUI.DrawRect(selectionRect, Mathf.FloorToInt((selectionRect.y - 4) / 16 % 2) == 0 ? settings.EvenRowColor : settings.OddRowColor);
22+
}
23+
}
24+
}

Alchemy/Assets/Alchemy/Editor/Hierarchy/HierarchyRowSeparatorDrawer.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
using System.Collections.Generic;
2+
using Alchemy.Hierarchy;
3+
using UnityEditor;
4+
using UnityEngine;
5+
6+
namespace Alchemy.Editor
7+
{
8+
public class HierarchyTreeMapDrawer : HierarchyDrawer
9+
{
10+
private static readonly Dictionary<string, Texture2D> TextureCached = new();
11+
12+
public static Texture2D TreeMapCurrent
13+
{
14+
get
15+
{
16+
TextureCached.TryGetValue(nameof(TreeMapCurrent), out var tex);
17+
18+
if (tex != null) return tex;
19+
tex = AssetHelper.FindAssetWithPath<Texture2D>("tree_map_current.png", "Editor/Hierarchy/Textures");
20+
TextureCached[nameof(TreeMapCurrent)] = tex;
21+
return tex;
22+
}
23+
}
24+
25+
public static Texture2D TreeMapLast
26+
{
27+
get
28+
{
29+
TextureCached.TryGetValue(nameof(TreeMapLast), out var tex);
30+
31+
if (tex != null) return tex;
32+
tex = AssetHelper.FindAssetWithPath<Texture2D>("tree_map_last.png", "Editor/Hierarchy/Textures");
33+
TextureCached[nameof(TreeMapLast)] = tex;
34+
return tex;
35+
}
36+
}
37+
38+
public static Texture2D TreeMapLevel
39+
{
40+
get
41+
{
42+
TextureCached.TryGetValue(nameof(TreeMapLevel), out var tex);
43+
44+
if (tex != null) return tex;
45+
tex = AssetHelper.FindAssetWithPath<Texture2D>("tree_map_level.png", "Editor/Hierarchy/Textures");
46+
TextureCached[nameof(TreeMapLevel)] = tex;
47+
return tex;
48+
}
49+
}
50+
51+
public static Texture2D TreeMapLine
52+
{
53+
get
54+
{
55+
TextureCached.TryGetValue(nameof(TreeMapLine), out var tex);
56+
57+
if (tex != null) return tex;
58+
tex = AssetHelper.FindAssetWithPath<Texture2D>("tree_map_line.png", "Editor/Hierarchy/Textures");
59+
TextureCached[nameof(TreeMapLine)] = tex;
60+
return tex;
61+
}
62+
}
63+
64+
public override void OnGUI(int instanceID, Rect selectionRect)
65+
{
66+
var gameObject = EditorUtility.InstanceIDToObject(instanceID) as GameObject;
67+
if (gameObject == null) return;
68+
69+
var settings = AlchemySettings.GetOrCreateSettings();
70+
if (settings.ShowTreeMap)
71+
{
72+
selectionRect.width = 14;
73+
selectionRect.height = 16;
74+
75+
int childCount = gameObject.transform.childCount;
76+
int level = Mathf.RoundToInt(selectionRect.x / 14f);
77+
var t = gameObject.transform;
78+
Transform parent = null;
79+
80+
for (int i = 0, j = level - 1; j >= 0; i++, j--)
81+
{
82+
selectionRect.x = 14 * j;
83+
if (i == 0)
84+
{
85+
if (childCount == 0)
86+
{
87+
GUI.color = settings.TreeMapColor;
88+
GUI.DrawTexture(selectionRect, TreeMapLine);
89+
}
90+
91+
t = gameObject.transform;
92+
}
93+
else if (i == 1)
94+
{
95+
GUI.color = settings.TreeMapColor;
96+
if (parent == null)
97+
{
98+
if (t.GetSiblingIndex() == gameObject.scene.rootCount - 1)
99+
{
100+
GUI.DrawTexture(selectionRect, TreeMapLast);
101+
}
102+
else
103+
{
104+
GUI.DrawTexture(selectionRect, TreeMapCurrent);
105+
}
106+
}
107+
else if (t.GetSiblingIndex() == parent.childCount - 1)
108+
{
109+
GUI.DrawTexture(selectionRect, TreeMapLast);
110+
}
111+
else
112+
{
113+
GUI.DrawTexture(selectionRect, TreeMapCurrent);
114+
}
115+
116+
t = parent;
117+
}
118+
else
119+
{
120+
if (parent == null)
121+
{
122+
if (t.GetSiblingIndex() != gameObject.scene.rootCount - 1) GUI.DrawTexture(selectionRect, TreeMapLevel);
123+
}
124+
else if (t.GetSiblingIndex() != parent.childCount - 1) GUI.DrawTexture(selectionRect, TreeMapLevel);
125+
126+
t = parent;
127+
}
128+
129+
if (t != null) parent = t.parent;
130+
else break;
131+
}
132+
133+
GUI.color = Color.white;
134+
}
135+
}
136+
}
137+
}

Alchemy/Assets/Alchemy/Editor/Hierarchy/HierarchyTreeMapDrawer.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Alchemy/Assets/Alchemy/Editor/Hierarchy/Textures.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Loading

0 commit comments

Comments
 (0)