-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSplitterGUILayout.cs
87 lines (73 loc) · 3.52 KB
/
SplitterGUILayout.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using UnityEngine;
namespace Abuksigun.UnityGitUI
{
[Serializable]
public class SplitterState : ISerializationCallbackReceiver
{
[SerializeField] float[] serializedRelativeSizes;
object splitterStateInstance;
static Type splitterStateType;
static FieldInfo realSizesField;
static FieldInfo relativeSizesField;
internal object SplitterStateInstance => splitterStateInstance;
public IReadOnlyList<float> RealSizes => realSizesField.GetValue(splitterStateInstance) as float[];
public IReadOnlyList<float> RelativeSizes => relativeSizesField.GetValue(splitterStateInstance) as float[];
static SplitterState()
{
var unityEditorAssembly = Assembly.Load("UnityEditor");
splitterStateType = unityEditorAssembly.GetType("UnityEditor.SplitterState");
realSizesField = splitterStateType.GetField("realSizes", BindingFlags.Public | BindingFlags.Instance);
relativeSizesField = splitterStateType.GetField("relativeSizes", BindingFlags.Public | BindingFlags.Instance);
}
public SplitterState(params float[] relativeSizes)
{
splitterStateInstance = Activator.CreateInstance(splitterStateType, new object[] { relativeSizes });
}
public void OnBeforeSerialize()
{
serializedRelativeSizes = RelativeSizes.ToArray();
}
public void OnAfterDeserialize()
{
splitterStateInstance = Activator.CreateInstance(splitterStateType, new object[] { serializedRelativeSizes });
}
}
public class SplitterGUILayout
{
static Type splitterGUILayoutType;
static MethodInfo beginHorizontalSplitMethod;
static MethodInfo endHorizontalSplitMethod;
static MethodInfo beginVerticalSplitMethod;
static MethodInfo endVerticalSplitMethod;
static SplitterGUILayout()
{
var unityEditorAssembly = Assembly.Load("UnityEditor");
splitterGUILayoutType = unityEditorAssembly.GetType("UnityEditor.SplitterGUILayout");
var splitterStateType = unityEditorAssembly.GetType("UnityEditor.SplitterState");
beginHorizontalSplitMethod = splitterGUILayoutType.GetMethod("BeginHorizontalSplit", new[] { splitterStateType, typeof(GUILayoutOption[]) });
endHorizontalSplitMethod = splitterGUILayoutType.GetMethod("EndHorizontalSplit", BindingFlags.Public | BindingFlags.Static);
beginVerticalSplitMethod = splitterGUILayoutType.GetMethod("BeginVerticalSplit", new[] { splitterStateType, typeof(GUILayoutOption[]) });
endVerticalSplitMethod = splitterGUILayoutType.GetMethod("EndVerticalSplit", BindingFlags.Public | BindingFlags.Static);
}
public static void BeginHorizontalSplit(SplitterState state, params GUILayoutOption[] options)
{
beginHorizontalSplitMethod.Invoke(null, new object[] { state.SplitterStateInstance, options });
}
public static void EndHorizontalSplit()
{
endHorizontalSplitMethod.Invoke(null, null);
}
public static void BeginVerticalSplit(SplitterState state, params GUILayoutOption[] options)
{
beginVerticalSplitMethod.Invoke(null, new object[] { state.SplitterStateInstance, options });
}
public static void EndVerticalSplit()
{
endVerticalSplitMethod.Invoke(null, null);
}
}
}