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