update
This commit is contained in:
@@ -1,81 +1,81 @@
|
||||
// ===============================================================================
|
||||
// HierarchyEnhancer - Quick Toggle for GameObjects
|
||||
// // ===============================================================================
|
||||
// // HierarchyEnhancer - Quick Toggle for GameObjects
|
||||
// //
|
||||
// // Creator: Scove
|
||||
// // Last Updated: 2024-05-08
|
||||
// // Version: 2.0
|
||||
// //
|
||||
// // Purpose:
|
||||
// // Adds a handy toggle checkbox to the right side of every item in the Hierarchy.
|
||||
// // This allows you to enable or disable GameObjects instantly without selecting them.
|
||||
// //
|
||||
// // Key Features:
|
||||
// // 1. One-click activation/deactivation directly in Hierarchy.
|
||||
// // 2. Full Undo/Redo support integrated with Unity's system.
|
||||
// // 3. Optimized UI placement to avoid overlapping with object names.
|
||||
// // 4. Visual clarity: Helps quickly identify inactive objects in a complex tree.
|
||||
// //
|
||||
// // How to Use:
|
||||
// // 1. Place this script in an 'Editor' folder.
|
||||
// // 2. Look at your Hierarchy window; a small checkbox will appear on the far right.
|
||||
// // 3. Click the checkbox to toggle the Active/Inactive state of any GameObject.
|
||||
// // ===============================================================================
|
||||
//
|
||||
// Creator: Scove
|
||||
// Last Updated: 2024-05-08
|
||||
// Version: 2.0
|
||||
// using UnityEditor;
|
||||
// using UnityEngine;
|
||||
//
|
||||
// Purpose:
|
||||
// Adds a handy toggle checkbox to the right side of every item in the Hierarchy.
|
||||
// This allows you to enable or disable GameObjects instantly without selecting them.
|
||||
// namespace Editor
|
||||
// {
|
||||
// [InitializeOnLoad]
|
||||
// public class HierarchyEnhancer
|
||||
// {
|
||||
// // Define the width of the toggle area
|
||||
// private const float TOGGLE_WIDTH = 16f;
|
||||
//
|
||||
// Key Features:
|
||||
// 1. One-click activation/deactivation directly in Hierarchy.
|
||||
// 2. Full Undo/Redo support integrated with Unity's system.
|
||||
// 3. Optimized UI placement to avoid overlapping with object names.
|
||||
// 4. Visual clarity: Helps quickly identify inactive objects in a complex tree.
|
||||
// static HierarchyEnhancer()
|
||||
// {
|
||||
// // Subscribe to the hierarchy item GUI event
|
||||
// EditorApplication.hierarchyWindowItemOnGUI += OnHierarchyItemGUI;
|
||||
// }
|
||||
//
|
||||
// How to Use:
|
||||
// 1. Place this script in an 'Editor' folder.
|
||||
// 2. Look at your Hierarchy window; a small checkbox will appear on the far right.
|
||||
// 3. Click the checkbox to toggle the Active/Inactive state of any GameObject.
|
||||
// ===============================================================================
|
||||
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Editor
|
||||
{
|
||||
[InitializeOnLoad]
|
||||
public class HierarchyEnhancer
|
||||
{
|
||||
// Define the width of the toggle area
|
||||
private const float TOGGLE_WIDTH = 16f;
|
||||
|
||||
static HierarchyEnhancer()
|
||||
{
|
||||
// Subscribe to the hierarchy item GUI event
|
||||
EditorApplication.hierarchyWindowItemOnGUI += OnHierarchyItemGUI;
|
||||
}
|
||||
|
||||
private static void OnHierarchyItemGUI(int instanceID, Rect selectionRect)
|
||||
{
|
||||
// Get the GameObject associated with this instance ID
|
||||
GameObject obj = EditorUtility.EntityIdToObject(instanceID) as GameObject;
|
||||
if (obj == null) return;
|
||||
|
||||
// Calculate the position for the Toggle (Aligned to the far right)
|
||||
// selectionRect.xMax gives us the right boundary of the Hierarchy row
|
||||
Rect toggleRect = new Rect(selectionRect);
|
||||
toggleRect.x = selectionRect.xMax - TOGGLE_WIDTH;
|
||||
toggleRect.width = TOGGLE_WIDTH;
|
||||
|
||||
// Check current active state
|
||||
bool isActive = obj.activeSelf;
|
||||
|
||||
// Handle UI and changes
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
// Set the color based on active state (Optional polish)
|
||||
Color originalColor = GUI.color;
|
||||
if (!isActive) GUI.color = new Color(1f, 1f, 1f, 0.5f); // Dim the toggle if inactive
|
||||
|
||||
bool newActive = EditorGUI.Toggle(toggleRect, isActive);
|
||||
|
||||
GUI.color = originalColor; // Restore original color for other elements
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
{
|
||||
// Record undo before applying the change
|
||||
Undo.RecordObject(obj, "Toggle GameObject Active State");
|
||||
obj.SetActive(newActive);
|
||||
|
||||
// If it's a Prefab, mark the scene as dirty to ensure it saves
|
||||
if (!Application.isPlaying)
|
||||
{
|
||||
EditorUtility.SetDirty(obj);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// private static void OnHierarchyItemGUI(int instanceID, Rect selectionRect)
|
||||
// {
|
||||
// // Get the GameObject associated with this instance ID
|
||||
// GameObject obj = EditorUtility.EntityIdToObject(instanceID) as GameObject;
|
||||
// if (obj == null) return;
|
||||
//
|
||||
// // Calculate the position for the Toggle (Aligned to the far right)
|
||||
// // selectionRect.xMax gives us the right boundary of the Hierarchy row
|
||||
// Rect toggleRect = new Rect(selectionRect);
|
||||
// toggleRect.x = selectionRect.xMax - TOGGLE_WIDTH;
|
||||
// toggleRect.width = TOGGLE_WIDTH;
|
||||
//
|
||||
// // Check current active state
|
||||
// bool isActive = obj.activeSelf;
|
||||
//
|
||||
// // Handle UI and changes
|
||||
// EditorGUI.BeginChangeCheck();
|
||||
//
|
||||
// // Set the color based on active state (Optional polish)
|
||||
// Color originalColor = GUI.color;
|
||||
// if (!isActive) GUI.color = new Color(1f, 1f, 1f, 0.5f); // Dim the toggle if inactive
|
||||
//
|
||||
// bool newActive = EditorGUI.Toggle(toggleRect, isActive);
|
||||
//
|
||||
// GUI.color = originalColor; // Restore original color for other elements
|
||||
//
|
||||
// if (EditorGUI.EndChangeCheck())
|
||||
// {
|
||||
// // Record undo before applying the change
|
||||
// Undo.RecordObject(obj, "Toggle GameObject Active State");
|
||||
// obj.SetActive(newActive);
|
||||
//
|
||||
// // If it's a Prefab, mark the scene as dirty to ensure it saves
|
||||
// if (!Application.isPlaying)
|
||||
// {
|
||||
// EditorUtility.SetDirty(obj);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
@@ -1,84 +1,84 @@
|
||||
// ===============================================================================
|
||||
// HierarchySeparators - Visual Organization for Unity Hierarchy
|
||||
// // ===============================================================================
|
||||
// // 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 ---").
|
||||
// // ===============================================================================
|
||||
//
|
||||
// Creator: Scove
|
||||
// Last Updated: 2024-05-08
|
||||
// Version: 2.0
|
||||
// using UnityEditor;
|
||||
// using UnityEngine;
|
||||
//
|
||||
// Purpose:
|
||||
// Converts GameObjects starting with "//" into visual separators or headers.
|
||||
// This helps organize large scenes by creating clear, readable sections.
|
||||
// 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);
|
||||
//
|
||||
// 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.
|
||||
// static HierarchySeparators()
|
||||
// {
|
||||
// // Subscribe to the hierarchy item GUI event
|
||||
// EditorApplication.hierarchyWindowItemOnGUI += OnHierarchyItemGUI;
|
||||
// }
|
||||
//
|
||||
// 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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// 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;
|
||||
// }
|
||||
//
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
23
Assets/Editor/ReflectTreeViewState.cs
Normal file
23
Assets/Editor/ReflectTreeViewState.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEditor.IMGUI.Controls;
|
||||
using System.Reflection;
|
||||
|
||||
public class ReflectTreeViewState : EditorWindow
|
||||
{
|
||||
[MenuItem("Tools/Reflect TreeViewState")]
|
||||
public static void ShowWindow()
|
||||
{
|
||||
var type = typeof(TreeViewState);
|
||||
var sb = new System.Text.StringBuilder();
|
||||
foreach (var p in type.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
|
||||
{
|
||||
sb.AppendLine("Prop: " + p.Name + " - " + p.PropertyType.FullName);
|
||||
}
|
||||
foreach (var f in type.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
|
||||
{
|
||||
sb.AppendLine("Field: " + f.Name + " - " + f.FieldType.FullName);
|
||||
}
|
||||
Debug.Log(sb.ToString());
|
||||
}
|
||||
}
|
||||
2
Assets/Editor/ReflectTreeViewState.cs.meta
Normal file
2
Assets/Editor/ReflectTreeViewState.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 52d65087605ff1841a952350f53f3a3e
|
||||
Reference in New Issue
Block a user