Forked from giacomelli/HierarchyWindowLayerInfo.cs
Last active
August 22, 2019 14:33
-
-
Save belzecue/4a50e2997de991aaa2b6bf15060fd4ec to your computer and use it in GitHub Desktop.
#unitytips: Hierarchy Window Layer Info: http://diegogiacomelli.com.br/unitytips-hierarchy-window-layer-info/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated to allow padding for simultaneous use of both HierarchyWindowLayerInfo.cs and HierarchyWindowGameObjectIcon.cs
See https://gist.github.com/giacomelli/a73c947508ee0b32eef7c422620ec6b6