-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #91 from pancake-llc/main
Add: tree map and row separator for hierarchy
- Loading branch information
Showing
17 changed files
with
953 additions
and
2 deletions.
There are no files selected for viewing
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
24 changes: 24 additions & 0 deletions
24
Alchemy/Assets/Alchemy/Editor/Hierarchy/HierarchyRowSeparatorDrawer.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
namespace Alchemy.Editor | ||
{ | ||
public class HierarchyRowSeparatorDrawer : HierarchyDrawer | ||
{ | ||
public override void OnGUI(int instanceID, Rect selectionRect) | ||
{ | ||
var settings = AlchemySettings.GetOrCreateSettings(); | ||
if (!settings.ShowSeparator) return; | ||
var rect = new Rect {y = selectionRect.y, width = selectionRect.width + selectionRect.x, height = 1, x = 0}; | ||
|
||
EditorGUI.DrawRect(rect, settings.SeparatorColor); | ||
|
||
if (!settings.ShowRowShading) return; | ||
selectionRect.width += selectionRect.x; | ||
selectionRect.x = 0; | ||
selectionRect.height -= 1; | ||
selectionRect.y += 1; | ||
EditorGUI.DrawRect(selectionRect, Mathf.FloorToInt((selectionRect.y - 4) / 16 % 2) == 0 ? settings.EvenRowColor : settings.OddRowColor); | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Alchemy/Assets/Alchemy/Editor/Hierarchy/HierarchyRowSeparatorDrawer.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
137 changes: 137 additions & 0 deletions
137
Alchemy/Assets/Alchemy/Editor/Hierarchy/HierarchyTreeMapDrawer.cs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
using System.Collections.Generic; | ||
using Alchemy.Hierarchy; | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
namespace Alchemy.Editor | ||
{ | ||
public class HierarchyTreeMapDrawer : HierarchyDrawer | ||
{ | ||
private static readonly Dictionary<string, Texture2D> TextureCached = new(); | ||
|
||
public static Texture2D TreeMapCurrent | ||
{ | ||
get | ||
{ | ||
TextureCached.TryGetValue(nameof(TreeMapCurrent), out var tex); | ||
|
||
if (tex != null) return tex; | ||
tex = AssetHelper.FindAssetWithPath<Texture2D>("tree_map_current.png", "Editor/Hierarchy/Textures"); | ||
TextureCached[nameof(TreeMapCurrent)] = tex; | ||
return tex; | ||
} | ||
} | ||
|
||
public static Texture2D TreeMapLast | ||
{ | ||
get | ||
{ | ||
TextureCached.TryGetValue(nameof(TreeMapLast), out var tex); | ||
|
||
if (tex != null) return tex; | ||
tex = AssetHelper.FindAssetWithPath<Texture2D>("tree_map_last.png", "Editor/Hierarchy/Textures"); | ||
TextureCached[nameof(TreeMapLast)] = tex; | ||
return tex; | ||
} | ||
} | ||
|
||
public static Texture2D TreeMapLevel | ||
{ | ||
get | ||
{ | ||
TextureCached.TryGetValue(nameof(TreeMapLevel), out var tex); | ||
|
||
if (tex != null) return tex; | ||
tex = AssetHelper.FindAssetWithPath<Texture2D>("tree_map_level.png", "Editor/Hierarchy/Textures"); | ||
TextureCached[nameof(TreeMapLevel)] = tex; | ||
return tex; | ||
} | ||
} | ||
|
||
public static Texture2D TreeMapLine | ||
{ | ||
get | ||
{ | ||
TextureCached.TryGetValue(nameof(TreeMapLine), out var tex); | ||
|
||
if (tex != null) return tex; | ||
tex = AssetHelper.FindAssetWithPath<Texture2D>("tree_map_line.png", "Editor/Hierarchy/Textures"); | ||
TextureCached[nameof(TreeMapLine)] = tex; | ||
return tex; | ||
} | ||
} | ||
|
||
public override void OnGUI(int instanceID, Rect selectionRect) | ||
{ | ||
var gameObject = EditorUtility.InstanceIDToObject(instanceID) as GameObject; | ||
if (gameObject == null) return; | ||
|
||
var settings = AlchemySettings.GetOrCreateSettings(); | ||
if (settings.ShowTreeMap) | ||
{ | ||
selectionRect.width = 14; | ||
selectionRect.height = 16; | ||
|
||
int childCount = gameObject.transform.childCount; | ||
int level = Mathf.RoundToInt(selectionRect.x / 14f); | ||
var t = gameObject.transform; | ||
Transform parent = null; | ||
|
||
for (int i = 0, j = level - 1; j >= 0; i++, j--) | ||
{ | ||
selectionRect.x = 14 * j; | ||
if (i == 0) | ||
{ | ||
if (childCount == 0) | ||
{ | ||
GUI.color = settings.TreeMapColor; | ||
GUI.DrawTexture(selectionRect, TreeMapLine); | ||
} | ||
|
||
t = gameObject.transform; | ||
} | ||
else if (i == 1) | ||
{ | ||
GUI.color = settings.TreeMapColor; | ||
if (parent == null) | ||
{ | ||
if (t.GetSiblingIndex() == gameObject.scene.rootCount - 1) | ||
{ | ||
GUI.DrawTexture(selectionRect, TreeMapLast); | ||
} | ||
else | ||
{ | ||
GUI.DrawTexture(selectionRect, TreeMapCurrent); | ||
} | ||
} | ||
else if (t.GetSiblingIndex() == parent.childCount - 1) | ||
{ | ||
GUI.DrawTexture(selectionRect, TreeMapLast); | ||
} | ||
else | ||
{ | ||
GUI.DrawTexture(selectionRect, TreeMapCurrent); | ||
} | ||
|
||
t = parent; | ||
} | ||
else | ||
{ | ||
if (parent == null) | ||
{ | ||
if (t.GetSiblingIndex() != gameObject.scene.rootCount - 1) GUI.DrawTexture(selectionRect, TreeMapLevel); | ||
} | ||
else if (t.GetSiblingIndex() != parent.childCount - 1) GUI.DrawTexture(selectionRect, TreeMapLevel); | ||
|
||
t = parent; | ||
} | ||
|
||
if (t != null) parent = t.parent; | ||
else break; | ||
} | ||
|
||
GUI.color = Color.white; | ||
} | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
Alchemy/Assets/Alchemy/Editor/Hierarchy/HierarchyTreeMapDrawer.cs.meta
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file added
BIN
+1.53 KB
Alchemy/Assets/Alchemy/Editor/Hierarchy/Textures/tree_map_current.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.