Script de la hiérarchie d'effondrement de l'unité

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>();
    }
}
Omadel