unitytips: Hierarchy Window GameObject Icon
16/07/2019
You can show the game objects icons in hierarchy window using EditorGUIUtility.ObjectContent
Code
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 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); | |
} | |
} |
The icons used in the video are Font Awesome icons and I used fa2png.io to convert them to .png.
Remember that you need to save the above .cs inside any Editor
folder
Loading comments...