Files
BABA_YAGA/Assets/Editors/HierarchySeparators.cs
2026-06-09 02:05:00 +07:00

84 lines
3.5 KiB
C#

// // ===============================================================================
// // HierarchySeparators - Visual Organization for Unity Hierarchy
// //
// // Creator: Scove
// // Last Updated: 2024-05-08
// // Version: 2.0
// //
// // Purpose:
// // Converts GameObjects starting with "//" into visual separators or headers.
// // This helps organize large scenes by creating clear, readable sections.
// //
// // Key Features:
// // 1. Automatic formatting: "// player" becomes a bold, centered "PLAYER" header.
// // 2. Custom background: Draws a distinctive bar to separate different logic groups.
// // 3. Clean UI: Strips out the "//" prefix for a professional look in the editor.
// //
// // How to Use:
// // 1. Place this script in an 'Editor' folder.
// // 2. Create an Empty GameObject in your Hierarchy.
// // 3. Rename it starting with "//" (e.g., "// --- ENVIRONMENT ---").
// // ===============================================================================
//
// using UnityEditor;
// using UnityEngine;
//
// namespace Editor
// {
// [InitializeOnLoad]
// public class HierarchySeparators
// {
// // Custom styling colors
// private static readonly Color HeaderBackgroundColor = new Color(0.22f, 0.22f, 0.22f, 1f);
// private static readonly Color TextColor = new Color(0.9f, 0.9f, 0.9f, 1f);
// private static readonly Color BorderColor = new Color(0.15f, 0.15f, 0.15f, 1f);
//
// static HierarchySeparators()
// {
// // Subscribe to the hierarchy item GUI event
// EditorApplication.hierarchyWindowItemOnGUI += OnHierarchyItemGUI;
// }
//
// private static void OnHierarchyItemGUI(int instanceID, Rect selectionRect)
// {
// // Get the object from the instance ID
// GameObject obj = EditorUtility.EntityIdToObject(instanceID) as GameObject;
//
// // Trigger only if the name starts with "//"
// if (obj != null && obj.name.StartsWith("//"))
// {
// // 1. Draw Background
// EditorGUI.DrawRect(selectionRect, HeaderBackgroundColor);
//
// // 2. Draw Subtle Bottom Border for better depth
// Rect borderRect = new Rect(selectionRect.x, selectionRect.yMax - 1f, selectionRect.width, 1f);
// EditorGUI.DrawRect(borderRect, BorderColor);
//
// // 3. Configure Text Style
// GUIStyle headerStyle = new GUIStyle(EditorStyles.boldLabel)
// {
// alignment = TextAnchor.MiddleCenter,
// normal = { textColor = TextColor },
// fontSize = 11,
// fontStyle = FontStyle.Bold
// };
//
// // 4. Clean and Format the string
// // Removes "//", trims spaces, and converts to Uppercase
// string headerName = obj.name.Replace("//", "").Trim().ToUpper();
//
// // 5. Draw the Header Label
// EditorGUI.LabelField(selectionRect, headerName, headerStyle);
//
// // Optional: To prevent selecting the separator as a normal object
// // (keeps focus on actual game objects), uncomment the lines below:
//
// if (Event.current.type == EventType.MouseDown && selectionRect.Contains(Event.current.mousePosition))
// {
// Selection.activeGameObject = null;
// }
//
// }
// }
// }
// }