This commit is contained in:
2026-05-17 15:12:16 +07:00
parent 93da00c206
commit bf0ebe447d
902 changed files with 142169 additions and 31515 deletions

View File

@@ -0,0 +1,47 @@
using UnityEngine;
using UnityEngine.SceneManagement;
namespace DA_Assets.Extensions
{
public static class ReflectedExtensions
{
/// <summary>
/// <para><see href="https://forum.unity.com/threads/how-to-collapse-hierarchy-scene-nodes-via-script.605245/#post-6551890"/></para>
/// </summary>
public static void SetExpanded(this Scene scene, bool expand)
{
#if UNITY_EDITOR
foreach (var window in Resources.FindObjectsOfTypeAll<UnityEditor.SearchableEditorWindow>())
{
if (window.GetType().Name != "SceneHierarchyWindow")
continue;
var method = window.GetType().GetMethod("SetExpandedRecursive",
System.Reflection.BindingFlags.Public |
System.Reflection.BindingFlags.NonPublic |
System.Reflection.BindingFlags.Instance, null,
new[] { typeof(int), typeof(bool) }, null);
if (method == null)
{
Debug.LogError(
"Could not find method 'UnityEditor.SceneHierarchyWindow.SetExpandedRecursive(int, bool)'.");
return;
}
var field = scene.GetType().GetField("m_Handle",
System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
if (field == null)
{
Debug.LogError("Could not find field 'int UnityEngine.SceneManagement.Scene.m_Handle'.");
return;
}
var sceneHandle = field.GetValue(scene);
method.Invoke(window, new[] { sceneHandle, expand });
}
#endif
}
}
}