12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- using System;
- using System.Linq;
- using System.Reflection;
- using UnityEngine;
- using UnityEditor;
- namespace LitMotion.Editor
- {
- internal static class SplitterGUILayout
- {
- static readonly BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static;
- static readonly Lazy<Type> splitterStateType = new(() =>
- {
- var type = typeof(EditorWindow).Assembly.GetTypes().First(x => x.FullName == "UnityEditor.SplitterState");
- return type;
- });
- static readonly Lazy<ConstructorInfo> splitterStateCtor = new(() =>
- {
- var type = splitterStateType.Value;
- return type.GetConstructor(flags, null, new Type[] { typeof(float[]), typeof(int[]), typeof(int[]) }, null);
- });
- static readonly Lazy<Type> splitterGUILayoutType = new(() =>
- {
- var type = typeof(EditorWindow).Assembly.GetTypes().First(x => x.FullName == "UnityEditor.SplitterGUILayout");
- return type;
- });
- static readonly Lazy<MethodInfo> beginVerticalSplit = new(() =>
- {
- var type = splitterGUILayoutType.Value;
- return type.GetMethod("BeginVerticalSplit", flags, null, new Type[] { splitterStateType.Value, typeof(GUILayoutOption[]) }, null);
- });
- static readonly Lazy<MethodInfo> endVerticalSplit = new(() =>
- {
- var type = splitterGUILayoutType.Value;
- return type.GetMethod("EndVerticalSplit", flags, null, Type.EmptyTypes, null);
- });
- public static object CreateSplitterState(float[] relativeSizes, int[] minSizes, int[] maxSizes)
- {
- return splitterStateCtor.Value.Invoke(new object[] { relativeSizes, minSizes, maxSizes });
- }
- public static void BeginVerticalSplit(object splitterState, params GUILayoutOption[] options)
- {
- beginVerticalSplit.Value.Invoke(null, new object[] { splitterState, options });
- }
- public static void EndVerticalSplit()
- {
- endVerticalSplit.Value.Invoke(null, Type.EmptyTypes);
- }
- }
- }
|