Skip to content

Instantly share code, notes, and snippets.

@belzecue
Forked from giacomelli/HierarchyWindowLayerInfo.cs
Last active August 22, 2019 14:33
Show Gist options
  • Save belzecue/4a50e2997de991aaa2b6bf15060fd4ec to your computer and use it in GitHub Desktop.
Save belzecue/4a50e2997de991aaa2b6bf15060fd4ec 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
{
// Margin on right, to allow for showing object icons.
const int paddingRight = 12;
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)
{
selectionRect.xMax = selectionRect.width + paddingRight;
EditorGUI.LabelField(selectionRect, LayerMask.LayerToName(gameObject.layer), _style);
}
}
}
@belzecue
Copy link
Author

Updated to allow padding for simultaneous use of both HierarchyWindowLayerInfo.cs and HierarchyWindowGameObjectIcon.cs
See https://gist.github.com/giacomelli/a73c947508ee0b32eef7c422620ec6b6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment