Last active
August 6, 2023 21:57
-
-
Save giacomelli/a73c947508ee0b32eef7c422620ec6b6 to your computer and use it in GitHub Desktop.
#unitytips: Hierarchy window game object icon - http://diegogiacomelli.com.br/unitytips-hierarchy-window-gameobject-icon/
This file contains 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 game object icon. | |
/// http://diegogiacomelli.com.br/unitytips-hierarchy-window-gameobject-icon/ | |
/// </summary> | |
[InitializeOnLoad] | |
public static class HierarchyWindowGameObjectIcon | |
{ | |
const string IgnoreIcons = "GameObject Icon, Prefab Icon"; | |
static HierarchyWindowGameObjectIcon() | |
{ | |
EditorApplication.hierarchyWindowItemOnGUI += HandleHierarchyWindowItemOnGUI; | |
} | |
static void HandleHierarchyWindowItemOnGUI(int instanceID, Rect selectionRect) | |
{ | |
var content = EditorGUIUtility.ObjectContent(EditorUtility.InstanceIDToObject(instanceID), null); | |
if (content.image != null && !IgnoreIcons.Contains(content.image.name)) | |
GUI.DrawTexture(new Rect(selectionRect.xMax - 16, selectionRect.yMin, 16, 16), content.image); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment