Skip to content

Commit

Permalink
Merge pull request #91 from pancake-llc/main
Browse files Browse the repository at this point in the history
Add: tree map and row separator for hierarchy
  • Loading branch information
AnnulusGames committed Jun 20, 2024
2 parents e12798c + 8cc5448 commit c8348c6
Show file tree
Hide file tree
Showing 17 changed files with 953 additions and 2 deletions.
40 changes: 40 additions & 0 deletions Alchemy/Assets/Alchemy/Editor/AlchemySettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,32 @@ internal static SettingsProvider CreateSettingsProvider()
EditorGUILayout.PropertyField(serializedObject.FindProperty("hierarchyObjectMode"));
EditorGUILayout.PropertyField(serializedObject.FindProperty("showHierarchyToggles"), new GUIContent("Show Toggles"));
EditorGUILayout.PropertyField(serializedObject.FindProperty("showComponentIcons"));
var showTreeMap = serializedObject.FindProperty("showTreeMap");
EditorGUILayout.PropertyField(showTreeMap);
if (showTreeMap.boolValue)
{
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(serializedObject.FindProperty("treeMapColor"), new GUIContent("Color"));
EditorGUI.indentLevel--;
}
var showSeparator = serializedObject.FindProperty("showSeparator");
EditorGUILayout.PropertyField(showSeparator, new GUIContent("Show Row Separator"));
if (showSeparator.boolValue)
{
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(serializedObject.FindProperty("separatorColor"), new GUIContent("Color"));
EditorGUI.indentLevel--;
var showRowShading = serializedObject.FindProperty("showRowShading");
EditorGUILayout.PropertyField(showRowShading);
if (showRowShading.boolValue)
{
EditorGUI.indentLevel++;
EditorGUILayout.PropertyField(serializedObject.FindProperty("evenRowColor"));
EditorGUILayout.PropertyField(serializedObject.FindProperty("oddRowColor"));
EditorGUI.indentLevel--;
}
}
if (changeCheck.changed)
{
Expand All @@ -84,9 +110,23 @@ internal static SettingsProvider CreateSettingsProvider()
[SerializeField] HierarchyObjectMode hierarchyObjectMode = HierarchyObjectMode.RemoveInBuild;
[SerializeField] bool showHierarchyToggles;
[SerializeField] bool showComponentIcons;
[SerializeField] bool showTreeMap;
[SerializeField] Color treeMapColor = new(0.53f, 0.53f, 0.53f, 0.45f);
[SerializeField] bool showSeparator;
[SerializeField] bool showRowShading;
[SerializeField] Color separatorColor = new(0.19f, 0.19f, 0.19f, 0f);
[SerializeField] Color evenRowColor = new(0f, 0f, 0f, 0.07f);
[SerializeField] Color oddRowColor = Color.clear;

public HierarchyObjectMode HierarchyObjectMode => hierarchyObjectMode;
public bool ShowHierarchyToggles => showHierarchyToggles;
public bool ShowComponentIcons => showComponentIcons;
public bool ShowTreeMap => showTreeMap;
public Color TreeMapColor => treeMapColor;
public bool ShowSeparator => showSeparator;
public bool ShowRowShading => showRowShading;
public Color SeparatorColor => separatorColor;
public Color EvenRowColor => evenRowColor;
public Color OddRowColor => oddRowColor;
}
}
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);
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

137 changes: 137 additions & 0 deletions Alchemy/Assets/Alchemy/Editor/Hierarchy/HierarchyTreeMapDrawer.cs
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;
}
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions Alchemy/Assets/Alchemy/Editor/Hierarchy/Textures.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit c8348c6

Please sign in to comment.