Skip to content

Instantly share code, notes, and snippets.

@heppoko
Created August 14, 2020 06:07
Show Gist options
  • Save heppoko/e0f753a3001a982157bdbb793a725182 to your computer and use it in GitHub Desktop.
Save heppoko/e0f753a3001a982157bdbb793a725182 to your computer and use it in GitHub Desktop.
CustomHierarchy
using UnityEngine;
using UnityEditor;
public class CustomHierarchy : MonoBehaviour
{
[InitializeOnLoadMethod]
private static void AddHierarchyItemOnGUI()
{
EditorApplication.hierarchyWindowItemOnGUI += HierarchyWindowItemOnGUI;
}
private static void HierarchyWindowItemOnGUI(int instanceID, Rect selectionRect)
{
var gameObject = EditorUtility.InstanceIDToObject(instanceID) as GameObject;
if (gameObject == null) return;
Rect leftRect = new Rect(selectionRect.x - 10, selectionRect.y, 10, selectionRect.height);
var originalBgColor = GUI.backgroundColor;
if (gameObject.GetComponent<Light>() != null)
{
GUI.backgroundColor = new Color(1.0f, 1.0f, 0.0f, 0.2f);
GUI.Box(selectionRect, "");
EditorGUI.DrawRect(leftRect, new Color(1.0f, 1.0f, 0.0f, 1.0f));
}
else if (gameObject.GetComponent<Camera>() != null)
{
GUI.backgroundColor = new Color(1.0f, 0.0f, 0.0f, 0.2f);
GUI.Box(selectionRect, "");
EditorGUI.DrawRect(leftRect, new Color(1.0f, 0.0f, 0.0f, 1.0f));
}
else
{
GUI.backgroundColor = new Color(0.0f, 0.0f, 1.0f, 0.2f);
GUI.Box(selectionRect, "");
EditorGUI.DrawRect(leftRect, new Color(0.0f, 0.0f, 1.0f, 1.0f));
}
GUI.backgroundColor = originalBgColor;
}
}
@heppoko
Copy link
Author

heppoko commented Aug 14, 2020

hierarchy

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