No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

CollabPlugin.cs 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. using System;
  2. using System.Reflection;
  3. using UnityEditor;
  4. namespace Unity.PlasticSCM.Editor
  5. {
  6. public static class CollabPlugin
  7. {
  8. public static bool IsEnabled()
  9. {
  10. return IsCollabInstanceEnabled();
  11. }
  12. internal static void Disable()
  13. {
  14. SetCollabEnabledInstanceAs(false);
  15. SetCollabEnabledInProjectSettingsAs(false);
  16. }
  17. internal static void Enable()
  18. {
  19. SetCollabEnabledInstanceAs(true);
  20. SetCollabEnabledInProjectSettingsAs(true);
  21. }
  22. static void SetCollabEnabledInstanceAs(bool value)
  23. {
  24. object collabInstance = GetCollabInstance();
  25. if (collabInstance == null)
  26. return;
  27. // Invokes Collab.instance.SetCollabEnabledForCurrentProject(false)
  28. SetCollabEnabledForCurrentProject(collabInstance, value);
  29. }
  30. static void SetCollabEnabledInProjectSettingsAs(bool value)
  31. {
  32. // Invokes PlayerSettings.SetCloudServiceEnabled("Collab", false)
  33. SetCloudServiceEnabled("Collab", value);
  34. AssetDatabase.SaveAssets();
  35. }
  36. static bool IsCollabInstanceEnabled()
  37. {
  38. object collabInstance = GetCollabInstance();
  39. if (collabInstance == null)
  40. return false;
  41. // Invokes Collab.instance.IsCollabEnabledForCurrentProject()
  42. return IsCollabEnabledForCurrentProject(collabInstance);
  43. }
  44. static void SetCollabEnabledForCurrentProject(object collabInstance, bool enable)
  45. {
  46. MethodInfo InternalSetCollabEnabledForCurrentProject =
  47. CollabType.GetMethod("SetCollabEnabledForCurrentProject");
  48. if (InternalSetCollabEnabledForCurrentProject == null)
  49. return;
  50. InternalSetCollabEnabledForCurrentProject.
  51. Invoke(collabInstance, new object[] { enable });
  52. }
  53. static void SetCloudServiceEnabled(string setting, bool enable)
  54. {
  55. MethodInfo InternalSetCloudServiceEnabled = PlayerSettingsType.GetMethod(
  56. "SetCloudServiceEnabled",
  57. BindingFlags.NonPublic | BindingFlags.Static);
  58. if (InternalSetCloudServiceEnabled == null)
  59. return;
  60. InternalSetCloudServiceEnabled.
  61. Invoke(null, new object[] { setting, enable });
  62. }
  63. static object GetCollabInstance()
  64. {
  65. if (CollabType == null)
  66. return null;
  67. PropertyInfo InternalInstance =
  68. CollabType.GetProperty("instance");
  69. if (InternalInstance == null)
  70. return null;
  71. return InternalInstance.GetValue(null, null);
  72. }
  73. static bool IsCollabEnabledForCurrentProject(object collabInstance)
  74. {
  75. MethodInfo InternalIsCollabEnabledForCurrentProject =
  76. CollabType.GetMethod("IsCollabEnabledForCurrentProject");
  77. if (InternalIsCollabEnabledForCurrentProject == null)
  78. return false;
  79. return (bool)InternalIsCollabEnabledForCurrentProject.
  80. Invoke(collabInstance, null);
  81. }
  82. static readonly Type CollabType =
  83. typeof(UnityEditor.Editor).Assembly.
  84. GetType("UnityEditor.Collaboration.Collab");
  85. static readonly Type PlayerSettingsType =
  86. typeof(UnityEditor.PlayerSettings);
  87. }
  88. }