This repository has been archived by the owner on Jan 18, 2022. It is now read-only.
/
PluginCompatibilitySetting.cs
142 lines (126 loc) · 4.68 KB
/
PluginCompatibilitySetting.cs
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
using System.Collections.Generic;
using System.IO;
using UnityEditor;
namespace Improbable.Gdk.Tools
{
internal enum PluginType
{
Core,
Sdk,
}
internal enum CpuType
{
ARMv7,
Arm64,
X86_64,
X86,
Agnostic,
}
internal struct PluginCompatibilitySetting
{
public readonly string CPU;
public readonly string PluginPath;
public readonly PluginType PluginType;
public readonly BuildTarget CompatiblePlatform;
public readonly List<BuildTarget> IncompatiblePlatforms;
public readonly bool CompatibleWithAnyPlatform;
public readonly bool CompatibleWithEditor;
private static readonly Dictionary<BuildTarget, string> BuildTargetToFolder =
new Dictionary<BuildTarget, string>
{
{ BuildTarget.StandaloneOSX, "OSX" },
{ BuildTarget.StandaloneLinux64, "Linux" },
{ BuildTarget.StandaloneWindows64, "Windows" },
{ BuildTarget.StandaloneWindows, "Windows" },
{ BuildTarget.Android, "Android" },
{ BuildTarget.iOS, "iOS" },
};
private static readonly Dictionary<CpuType, string> CpuToFolder =
new Dictionary<CpuType, string>
{
{ CpuType.ARMv7, "armv7" },
{ CpuType.Arm64, "arm64" },
{ CpuType.X86, "x86" },
{ CpuType.X86_64, "x86_64" },
};
public PluginCompatibilitySetting(
PluginType pluginType,
BuildTarget compatiblePlatform,
CpuType cpuType = CpuType.Agnostic,
bool compatibleWithEditor = true)
{
PluginType = pluginType;
PluginPath = Path.Combine(DownloadCoreSdk.ImprobablePluginsPath, pluginType.ToString(), BuildTargetToFolder[compatiblePlatform]);
CompatibleWithAnyPlatform = false;
CompatibleWithEditor = compatibleWithEditor;
CompatiblePlatform = compatiblePlatform;
if (cpuType == CpuType.Agnostic)
{
CPU = string.Empty;
}
else
{
PluginPath = Path.Combine(PluginPath, CpuToFolder[cpuType]);
CPU = CpuToFolder[cpuType];
}
IncompatiblePlatforms = new List<BuildTarget>();
}
public PluginCompatibilitySetting(
PluginType pluginType,
List<BuildTarget> incompatiblePlatforms,
bool compatibleWithEditor = true)
{
PluginType = pluginType;
PluginPath = Path.Combine(DownloadCoreSdk.ImprobablePluginsPath, pluginType.ToString(), "Common");
CompatibleWithAnyPlatform = true;
IncompatiblePlatforms = incompatiblePlatforms;
CompatibleWithEditor = compatibleWithEditor;
CompatiblePlatform = 0;
CPU = string.Empty;
}
internal bool UpdateCompatibleWithAnyPlatform(PluginImporter pluginImporter)
{
if (CompatibleWithAnyPlatform != pluginImporter.GetCompatibleWithAnyPlatform())
{
pluginImporter.SetCompatibleWithAnyPlatform(CompatibleWithAnyPlatform);
return true;
}
return false;
}
internal bool UpdateCompatibleWithEditor(PluginImporter pluginImporter)
{
if (CompatibleWithEditor != pluginImporter.GetCompatibleWithEditor())
{
pluginImporter.SetCompatibleWithEditor(CompatibleWithEditor);
return true;
}
return false;
}
internal bool UpdateCompatibleWithPlatform(PluginImporter pluginImporter)
{
if (CompatiblePlatform != 0 && !pluginImporter.GetCompatibleWithPlatform(CompatiblePlatform))
{
pluginImporter.SetCompatibleWithPlatform(CompatiblePlatform, true);
if (!string.IsNullOrEmpty(CPU))
{
pluginImporter.SetPlatformData(CompatiblePlatform, "CPU", CPU);
}
return true;
}
return false;
}
internal bool UpdateIncompatibleWithPlatforms(PluginImporter pluginImporter)
{
var hasUpdated = false;
foreach (var incompatiblePlatform in IncompatiblePlatforms)
{
if (!pluginImporter.GetExcludeFromAnyPlatform(incompatiblePlatform))
{
pluginImporter.SetExcludeFromAnyPlatform(incompatiblePlatform, true);
hasUpdated = true;
}
}
return hasUpdated;
}
}
}