Nessuna descrizione
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.

SetupCloudProjectId.cs 2.8KB

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