A game about forced loneliness, made by TACStudios
1using System;
2using System.Reflection;
3
4using UnityEditor;
5
6namespace Unity.PlasticSCM.Editor.UI
7{
8 internal static class DockEditorWindow
9 {
10 static DockEditorWindow()
11 {
12 InitializeInfo();
13 }
14
15 internal static bool IsAvailable()
16 {
17 return mParentField != null
18 && mAddTabMethod != null;
19 }
20
21 internal static void To(EditorWindow dockWindow, EditorWindow window)
22 {
23 var dockArea = mParentField.GetValue(dockWindow);
24
25 mAddTabMethod.Invoke(dockArea, new object[] { window, true });
26 }
27
28 static void InitializeInfo()
29 {
30 var flags = BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public | BindingFlags.Static;
31
32 mParentField = typeof(EditorWindow).GetField("m_Parent", flags);
33
34 var dockAreaType = typeof(EditorWindow).Assembly.GetType("UnityEditor.DockArea");
35
36 if (dockAreaType == null)
37 return;
38
39 mAddTabMethod = dockAreaType.GetMethod("AddTab", flags,
40 null, new Type[] { typeof(EditorWindow), typeof(bool) }, null);
41 }
42
43 static MethodInfo mAddTabMethod;
44 static FieldInfo mParentField;
45 }
46}