DockEditorWindow.cs 1.2 KB

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