SplitterGUILayout.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member
  2. using System;
  3. using System.Linq;
  4. using System.Reflection;
  5. using UnityEditor;
  6. using UnityEngine;
  7. namespace Cysharp.Threading.Tasks.Editor
  8. {
  9. // reflection call of UnityEditor.SplitterGUILayout
  10. internal static class SplitterGUILayout
  11. {
  12. static BindingFlags flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Static;
  13. static Lazy<Type> splitterStateType = new Lazy<Type>(() =>
  14. {
  15. var type = typeof(EditorWindow).Assembly.GetTypes().First(x => x.FullName == "UnityEditor.SplitterState");
  16. return type;
  17. });
  18. static Lazy<ConstructorInfo> splitterStateCtor = new Lazy<ConstructorInfo>(() =>
  19. {
  20. var type = splitterStateType.Value;
  21. return type.GetConstructor(flags, null, new Type[] { typeof(float[]), typeof(int[]), typeof(int[]) }, null);
  22. });
  23. static Lazy<Type> splitterGUILayoutType = new Lazy<Type>(() =>
  24. {
  25. var type = typeof(EditorWindow).Assembly.GetTypes().First(x => x.FullName == "UnityEditor.SplitterGUILayout");
  26. return type;
  27. });
  28. static Lazy<MethodInfo> beginVerticalSplit = new Lazy<MethodInfo>(() =>
  29. {
  30. var type = splitterGUILayoutType.Value;
  31. return type.GetMethod("BeginVerticalSplit", flags, null, new Type[] { splitterStateType.Value, typeof(GUILayoutOption[]) }, null);
  32. });
  33. static Lazy<MethodInfo> endVerticalSplit = new Lazy<MethodInfo>(() =>
  34. {
  35. var type = splitterGUILayoutType.Value;
  36. return type.GetMethod("EndVerticalSplit", flags, null, Type.EmptyTypes, null);
  37. });
  38. public static object CreateSplitterState(float[] relativeSizes, int[] minSizes, int[] maxSizes)
  39. {
  40. return splitterStateCtor.Value.Invoke(new object[] { relativeSizes, minSizes, maxSizes });
  41. }
  42. public static void BeginVerticalSplit(object splitterState, params GUILayoutOption[] options)
  43. {
  44. beginVerticalSplit.Value.Invoke(null, new object[] { splitterState, options });
  45. }
  46. public static void EndVerticalSplit()
  47. {
  48. endVerticalSplit.Value.Invoke(null, Type.EmptyTypes);
  49. }
  50. }
  51. }