Skip to content

Instantly share code, notes, and snippets.

@a1678991
Last active February 21, 2024 11:30
Show Gist options
  • Save a1678991/1741f3898bb79a811b7f0500655ab682 to your computer and use it in GitHub Desktop.
Save a1678991/1741f3898bb79a811b7f0500655ab682 to your computer and use it in GitHub Desktop.
EditorOnlyに指定されているGameObjectをわかりやすく表示するやつ
using UnityEngine;
using UnityEditor;
[InitializeOnLoad]
public class HierarchyHighlighter
{
static HierarchyHighlighter()
{
EditorApplication.hierarchyWindowItemOnGUI += HierarchyItemCB;
}
private static void HierarchyItemCB(int instanceID, Rect selectionRect)
{
var gameObject = EditorUtility.InstanceIDToObject(instanceID) as GameObject;
if (gameObject != null)
{
// Check if the GameObject or any of its children has the "EditorOnly" tag
var hasEditorOnlyTag = gameObject.CompareTag("EditorOnly") || HasEditorOnlyChild(gameObject);
// Apply border based on the tag
if (hasEditorOnlyTag)
{
var borderColor = gameObject.CompareTag("EditorOnly") ? Color.red : Color.yellow;
DrawBorder(selectionRect, borderColor, 2); // 2 is the border thickness
}
}
}
private static bool HasEditorOnlyChild(GameObject gameObject)
{
foreach (Transform child in gameObject.transform)
{
if (child.CompareTag("EditorOnly") || HasEditorOnlyChild(child.gameObject))
{
return true;
}
}
return false;
}
private static void DrawBorder(Rect rect, Color color, float thickness)
{
EditorGUI.DrawRect(new Rect(rect.xMax - rect.width / 4, rect.yMax - thickness, rect.width / 4, thickness),
color);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment