Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions HierarchyDecorator/Scripts/Editor/Data/GlobalData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ public class GlobalData
public bool showTags = true;
public bool showLayers = true;
public bool applyChildLayers = true;
public bool coloringTags = true;
public bool coloringLayers = true;
[Range(0, 1)] public float coloringTagLayerS = 0.6f;
[Range(0, 2)] public float coloringTagLayerV = 2f;

// Components

Expand Down
59 changes: 46 additions & 13 deletions HierarchyDecorator/Scripts/Editor/Hierarchy/Info/TagLayerInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ protected override void DrawInfo(Rect rect, HierarchyItem item, Settings setting
{
if (tagEnabled)
{
DrawTag(rect, item.GameObject, settings.globalData.tagLayerLayout);
DrawTag(rect, item.GameObject, settings);
}

if (layerEnabled)
{
DrawLayer(rect, item.GameObject, settings.globalData.tagLayerLayout);
DrawLayer(rect, item.GameObject, settings);
}
}

Expand Down Expand Up @@ -87,21 +87,54 @@ protected override bool ValidateGrid()

// - Drawing elements

private void DrawTag(Rect rect, GameObject instance, TagLayerLayout layout)
private void DrawTag(Rect rect, GameObject instance, Settings settings)
{
rect = GetInfoAreaRect(rect, true, layout);
DrawInstanceInfo(rect, instance.tag, instance, true);
rect = GetInfoAreaRect(rect, true, settings.globalData.tagLayerLayout);
if (settings.globalData.coloringTags)
{
var color = GUI.contentColor;
GUI.contentColor = GetHashColor(instance.tag, settings.globalData.coloringTagLayerS, settings.globalData.coloringTagLayerV);
DrawInstanceInfo(rect, instance.tag, instance, true);
GUI.contentColor = color;
}
else
DrawInstanceInfo(rect, instance.tag, instance, true);
}

private void DrawLayer(Rect rect, GameObject instance, TagLayerLayout layout)
private void DrawLayer(Rect rect, GameObject instance, Settings settings)
{
rect = GetInfoAreaRect(rect, false, layout);
DrawInstanceInfo(rect, LayerMask.LayerToName(instance.layer), instance, false);
rect = GetInfoAreaRect(rect, false, settings.globalData.tagLayerLayout);
var label = LayerMask.LayerToName(instance.layer);
if (settings.globalData.coloringLayers)
{
var color = GUI.contentColor;
GUI.contentColor = GetHashColor(label, settings.globalData.coloringTagLayerS, settings.globalData.coloringTagLayerV);
DrawInstanceInfo(rect, label, instance, false);
GUI.contentColor = color;
}
else
DrawInstanceInfo(rect, label, instance, false);
}

private Color GetHashColor(string label, float s, float v)
{
unchecked
{
int hash = 23;
foreach (char c in label)
hash = hash * 31 + c;
uint uhash = (uint)hash;
float h = (uhash * 0.61803398875f) % 1.0f;
return Color.HSVToRGB(h, s, v);
}
}

private void DrawInstanceInfo(Rect rect, string label, GameObject instance, bool isTag)
{
EditorGUI.LabelField(rect, label, (isVertical && bothShown) ? Style.TinyText : Style.SmallDropdown);
if (!isTag || label != "Untagged")
{
GUI.Label(rect, new GUIContent(label, label), (isVertical && bothShown) ? Style.TinyText : Style.SmallDropdown);
}

Event e = Event.current;
bool hasClicked = rect.Contains(e.mousePosition) && e.type == EventType.MouseDown;
Expand All @@ -114,8 +147,8 @@ private void DrawInstanceInfo(Rect rect, string label, GameObject instance, bool
// Create menu here

GenericMenu menu = isTag
? CreateMenu(InternalEditorUtility.tags, AssignTag)
: CreateMenu(InternalEditorUtility.layers, AssignLayer);
? CreateMenu(InternalEditorUtility.tags, label, AssignTag)
: CreateMenu(InternalEditorUtility.layers, label, AssignLayer);

GameObject[] selection = Selection.gameObjects;
if (selection.Length < 2)
Expand Down Expand Up @@ -172,13 +205,13 @@ private void AssignLayer(string layer)

// - Helpers

private static GenericMenu CreateMenu(string[] items, Action<string> onSelect)
private static GenericMenu CreateMenu(string[] items, string label, Action<string> onSelect)
{
GenericMenu menu = new GenericMenu();
for (int i = 0; i < items.Length; i++)
{
string item = items[i];
menu.AddItem(new GUIContent(item), false, () => onSelect.Invoke(item));
menu.AddItem(new GUIContent(item), label == item, () => onSelect.Invoke(item));
}

return menu;
Expand Down
4 changes: 3 additions & 1 deletion HierarchyDecorator/Scripts/Editor/Tabs/GeneralTab.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public class GeneralTab : SettingsTab
{
private string[] TagFields = new[] { "showTags" };
private string[] LayerFields = new[] { "showLayers", "applyChildLayers" };
private string[] coloringTagLayerFields = new[] { "coloringTags", "coloringLayers", "coloringTagLayerS", "coloringTagLayerV"};

public GeneralTab(Settings settings, SerializedObject serializedSettings) : base (settings, serializedSettings, "globalData", "General", "d_CustomTool")
{
Expand All @@ -21,7 +22,8 @@ public GeneralTab(Settings settings, SerializedObject serializedSettings) : base
CreateDrawableGroup("Tags & Layers")
.RegisterSerializedProperty(serializedTab, TagFields)
.RegisterSerializedProperty(serializedTab, LayerFields).Space()
.RegisterSerializedProperty(serializedTab, "tagLayerLayout");
.RegisterSerializedProperty(serializedTab, "tagLayerLayout")
.RegisterSerializedProperty(serializedTab, coloringTagLayerFields);

// --- Breadcrumbs

Expand Down