Skip to content

Instantly share code, notes, and snippets.

@giacomelli
Last active October 17, 2020 17:17
Show Gist options
  • Save giacomelli/096005d0d0df79b94321f950138220a3 to your computer and use it in GitHub Desktop.
Save giacomelli/096005d0d0df79b94321f950138220a3 to your computer and use it in GitHub Desktop.
using UnityEditor;
using UnityEngine;
// <summary>
/// Hierarchy Window Layer Info
/// http://diegogiacomelli.com.br/unitytips-hierarchy-window-layer-info/
/// </summary>
[InitializeOnLoad]
public static class HierarchyWindowLayerInfo
{
static readonly int IgnoreLayer = LayerMask.NameToLayer("Default");
static readonly GUIStyle _style = new GUIStyle()
{
fontSize = 9,
alignment = TextAnchor.MiddleRight
};
static HierarchyWindowLayerInfo()
{
EditorApplication.hierarchyWindowItemOnGUI += HandleHierarchyWindowItemOnGUI;
}
static void HandleHierarchyWindowItemOnGUI(int instanceID, Rect selectionRect)
{
var gameObject = EditorUtility.InstanceIDToObject(instanceID) as GameObject;
if (gameObject != null && gameObject.layer != IgnoreLayer)
{
EditorGUI.LabelField(selectionRect, LayerMask.LayerToName(gameObject.layer), _style);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment