SetupCloudProjectId.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. //disable Warning CS0618 'PlayerSettings.cloudProjectId' is obsolete: 'cloudProjectId is deprecated
  16. #pragma warning disable 0618
  17. return !string.IsNullOrEmpty(PlayerSettings.cloudProjectId);
  18. }
  19. internal static void ForWorkspace(
  20. WorkspaceInfo wkInfo,
  21. IPlasticAPI plasticApi)
  22. {
  23. RepositoryInfo repInfo = null;
  24. IThreadWaiter waiter = ThreadWaiter.GetWaiter(10);
  25. waiter.Execute(
  26. /*threadOperationDelegate*/ delegate
  27. {
  28. RepositorySpec repSpec = plasticApi.GetRepositorySpec(wkInfo);
  29. repInfo = plasticApi.GetRepositoryInfo(repSpec);
  30. },
  31. /*afterOperationDelegate*/ delegate
  32. {
  33. if (waiter.Exception != null)
  34. {
  35. ExceptionsHandler.LogException(
  36. "SetupCloudProjectId",
  37. waiter.Exception);
  38. return;
  39. }
  40. SetupCloudProjectId.ForRepository(repInfo);
  41. });
  42. }
  43. internal static void ForRepository(RepositoryInfo repInfo)
  44. {
  45. string projectId = repInfo.GUID.ToString();
  46. // Invokes PlayerSettings.SetCloudProjectId(projectId)
  47. SetCloudProjectId(projectId);
  48. AssetDatabase.SaveAssets();
  49. }
  50. internal static void SetCloudProjectId(string projectId)
  51. {
  52. MethodInfo InternalSetCloudProjectId = PlayerSettingsType.GetMethod(
  53. "SetCloudProjectId",
  54. BindingFlags.NonPublic | BindingFlags.Static);
  55. if (InternalSetCloudProjectId == null)
  56. {
  57. Debug.LogWarning(PlasticLocalization.GetString(
  58. PlasticLocalization.Name.CannotWriteCloudProjectId));
  59. return;
  60. }
  61. InternalSetCloudProjectId.Invoke(
  62. null, new object[] { projectId });
  63. }
  64. static readonly Type PlayerSettingsType =
  65. typeof(UnityEditor.PlayerSettings);
  66. static readonly ILog mLog = LogManager.GetLogger("SetupCloudProjectId");
  67. }
  68. }