SetupCloudProjectId.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. using System;
  2. using System.Reflection;
  3. using UnityEditor;
  4. using UnityEngine;
  5. using Codice.Client.Common.Threading;
  6. using Codice.CM.Common;
  7. using Codice.LogWrapper;
  8. using PlasticGui;
  9. namespace Unity.PlasticSCM.Editor
  10. {
  11. static class SetupCloudProjectId
  12. {
  13. internal static bool HasCloudProjectId()
  14. {
  15. return !string.IsNullOrEmpty(GetCloudProjectId());
  16. }
  17. internal static string GetCloudProjectId()
  18. {
  19. //disable Warning CS0618 'PlayerSettings.cloudProjectId' is obsolete: 'cloudProjectId is deprecated
  20. #pragma warning disable 0618
  21. return PlayerSettings.cloudProjectId;
  22. }
  23. internal static void ForWorkspace(
  24. WorkspaceInfo wkInfo,
  25. IPlasticAPI plasticApi)
  26. {
  27. RepositoryInfo repInfo = null;
  28. IThreadWaiter waiter = ThreadWaiter.GetWaiter(10);
  29. waiter.Execute(
  30. /*threadOperationDelegate*/ delegate
  31. {
  32. RepositorySpec repSpec = plasticApi.GetRepositorySpec(wkInfo);
  33. repInfo = plasticApi.GetRepositoryInfo(repSpec);
  34. },
  35. /*afterOperationDelegate*/ delegate
  36. {
  37. if (waiter.Exception != null)
  38. {
  39. ExceptionsHandler.LogException(
  40. "SetupCloudProjectId",
  41. waiter.Exception);
  42. return;
  43. }
  44. SetupCloudProjectId.ForRepository(repInfo);
  45. });
  46. }
  47. internal static void ForRepository(RepositoryInfo repInfo)
  48. {
  49. string projectId = repInfo.GUID.ToString();
  50. // Invokes PlayerSettings.SetCloudProjectId(projectId)
  51. SetCloudProjectId(projectId);
  52. AssetDatabase.SaveAssets();
  53. }
  54. internal static void SetCloudProjectId(string projectId)
  55. {
  56. MethodInfo InternalSetCloudProjectId = PlayerSettingsType.GetMethod(
  57. "SetCloudProjectId",
  58. BindingFlags.NonPublic | BindingFlags.Static);
  59. if (InternalSetCloudProjectId == null)
  60. {
  61. Debug.LogWarning(PlasticLocalization.GetString(
  62. PlasticLocalization.Name.CannotWriteCloudProjectId));
  63. return;
  64. }
  65. InternalSetCloudProjectId.Invoke(
  66. null, new object[] { projectId });
  67. }
  68. static readonly Type PlayerSettingsType =
  69. typeof(UnityEditor.PlayerSettings);
  70. static readonly ILog mLog = LogManager.GetLogger("SetupCloudProjectId");
  71. }
  72. }