Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

unity collapse hierarchy script

using UnityEditor;
using UnityEngine;

internal class MyClass : EditorWindow
{
    private void OnGUI()
    {
        using (var scope = new EditorGUI.DisabledGroupScope(Selection.activeGameObject == null))
        {
            if (GUILayout.Button("Expand Recursive"))
            {
                var type = typeof(EditorWindow).Assembly.GetType("UnityEditor.SceneHierarchyWindow");
                var window = GetWindow(type);
                var exprec = type.GetMethod("SetExpandedRecursive");
                exprec!.Invoke(window, new object[] {Selection.activeGameObject.GetInstanceID(), true});
            }
        }
    }

    [MenuItem("TEST/TEST")]
    private static void Init()
    {
        GetWindow<MyClass>();
    }
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #unity #collapse #hierarchy #script
ADD COMMENT
Topic
Name
6+9 =