Skip to content

Instantly share code, notes, and snippets.

@farukcan
Last active September 18, 2023 08:19
Show Gist options
  • Save farukcan/fbed41147735c799466d95550c3216db to your computer and use it in GitHub Desktop.
Save farukcan/fbed41147735c799466d95550c3216db to your computer and use it in GitHub Desktop.
Colorfull Hierarchy Window Group Header
using UnityEngine;
using UnityEditor;
/// <summary>
/// Colorful Hierarchy Window Group Header
/// Author: github.com/farukcan
/// Thanks for concept of idea :
/// http://diegogiacomelli.com.br/unitytips-hierarchy-window-group-header
/// Sample GameObject Names: "#red CAMERA" , "#" , "##E7A5F6 Hex" , "# "
/// </summary>
[InitializeOnLoad]
public static class HierarchyWindowGroupHeader
{
static HierarchyWindowGroupHeader()
{
EditorApplication.hierarchyWindowItemOnGUI += HierarchyWindowItemOnGUI;
}
static void HierarchyWindowItemOnGUI(int instanceID, Rect selectionRect)
{
var gameObject = EditorUtility.InstanceIDToObject(instanceID) as GameObject;
if (gameObject != null && gameObject.name.StartsWith("#", System.StringComparison.Ordinal))
{
// format is #color
var colorName = gameObject.name.Substring(1).Split(' ')[0];
// covert colorname to unity color
var color = Color.gray;
if(ColorUtility.TryParseHtmlString(colorName.ToLower(),out var _color)){
color = _color;
}
EditorGUI.DrawRect(selectionRect, color);
EditorGUI.DropShadowLabel(selectionRect, gameObject.name.Replace("#"+colorName+" ", "").ToUpperInvariant());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment