forked from MattRix/UnityDecompiled
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDefaultPluginImporterExtension.cs
More file actions
233 lines (233 loc) · 6.42 KB
/
Copy pathDefaultPluginImporterExtension.cs
File metadata and controls
233 lines (233 loc) · 6.42 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
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Text;
using UnityEngine;
namespace UnityEditor.Modules
{
internal class DefaultPluginImporterExtension : IPluginImporterExtension
{
internal class Property
{
internal GUIContent name
{
get;
set;
}
internal string key
{
get;
set;
}
internal object defaultValue
{
get;
set;
}
internal Type type
{
get;
set;
}
internal string platformName
{
get;
set;
}
internal object value
{
get;
set;
}
internal Property(string name, string key, object defaultValue, string platformName) : this(new GUIContent(name), key, defaultValue, platformName)
{
}
internal Property(GUIContent name, string key, object defaultValue, string platformName)
{
this.name = name;
this.key = key;
this.defaultValue = defaultValue;
this.type = defaultValue.GetType();
this.platformName = platformName;
}
internal virtual void Reset(PluginImporterInspector inspector)
{
string platformData = inspector.importer.GetPlatformData(this.platformName, this.key);
try
{
this.value = TypeDescriptor.GetConverter(this.type).ConvertFromString(platformData);
}
catch
{
this.value = this.defaultValue;
if (!string.IsNullOrEmpty(platformData))
{
Debug.LogWarning(string.Concat(new object[]
{
"Failed to parse value ('",
platformData,
"') for ",
this.key,
", platform: ",
this.platformName,
", type: ",
this.type,
". Default value will be set '",
this.defaultValue,
"'"
}));
}
}
}
internal virtual void Apply(PluginImporterInspector inspector)
{
inspector.importer.SetPlatformData(this.platformName, this.key, this.value.ToString());
}
internal virtual void OnGUI(PluginImporterInspector inspector)
{
if (this.type == typeof(bool))
{
this.value = EditorGUILayout.Toggle(this.name, (bool)this.value, new GUILayoutOption[0]);
}
else
{
if (this.type.IsEnum)
{
this.value = EditorGUILayout.EnumPopup(this.name, (Enum)this.value, new GUILayoutOption[0]);
}
else
{
if (this.type != typeof(string))
{
throw new NotImplementedException("Don't know how to display value.");
}
this.value = EditorGUILayout.TextField(this.name, (string)this.value, new GUILayoutOption[0]);
}
}
}
}
protected bool hasModified;
protected DefaultPluginImporterExtension.Property[] properties;
internal bool propertiesRefreshed;
public DefaultPluginImporterExtension(DefaultPluginImporterExtension.Property[] properties)
{
this.properties = properties;
}
public virtual void ResetValues(PluginImporterInspector inspector)
{
this.hasModified = false;
this.RefreshProperties(inspector);
}
public virtual bool HasModified(PluginImporterInspector inspector)
{
return this.hasModified;
}
public virtual void Apply(PluginImporterInspector inspector)
{
if (!this.propertiesRefreshed)
{
return;
}
DefaultPluginImporterExtension.Property[] array = this.properties;
for (int i = 0; i < array.Length; i++)
{
DefaultPluginImporterExtension.Property property = array[i];
property.Apply(inspector);
}
}
public virtual void OnEnable(PluginImporterInspector inspector)
{
this.RefreshProperties(inspector);
}
public virtual void OnDisable(PluginImporterInspector inspector)
{
}
public virtual void OnPlatformSettingsGUI(PluginImporterInspector inspector)
{
if (!this.propertiesRefreshed)
{
this.RefreshProperties(inspector);
}
EditorGUI.BeginChangeCheck();
DefaultPluginImporterExtension.Property[] array = this.properties;
for (int i = 0; i < array.Length; i++)
{
DefaultPluginImporterExtension.Property property = array[i];
property.OnGUI(inspector);
}
if (EditorGUI.EndChangeCheck())
{
this.hasModified = true;
}
}
protected virtual void RefreshProperties(PluginImporterInspector inspector)
{
DefaultPluginImporterExtension.Property[] array = this.properties;
for (int i = 0; i < array.Length; i++)
{
DefaultPluginImporterExtension.Property property = array[i];
property.Reset(inspector);
}
this.propertiesRefreshed = true;
}
public virtual string CalculateFinalPluginPath(string platformName, PluginImporter imp)
{
return Path.GetFileName(imp.assetPath);
}
protected Dictionary<string, List<PluginImporter>> GetCompatiblePlugins(string buildTargetName)
{
PluginImporter[] array = (
from imp in PluginImporter.GetAllImporters()
where (imp.GetCompatibleWithPlatform(buildTargetName) || imp.GetCompatibleWithAnyPlatform()) && !string.IsNullOrEmpty(imp.assetPath)
select imp).ToArray<PluginImporter>();
Dictionary<string, List<PluginImporter>> dictionary = new Dictionary<string, List<PluginImporter>>();
PluginImporter[] array2 = array;
for (int i = 0; i < array2.Length; i++)
{
PluginImporter pluginImporter = array2[i];
if (!string.IsNullOrEmpty(pluginImporter.assetPath))
{
string text = this.CalculateFinalPluginPath(buildTargetName, pluginImporter);
if (!string.IsNullOrEmpty(text))
{
List<PluginImporter> list = null;
if (!dictionary.TryGetValue(text, out list))
{
list = new List<PluginImporter>();
dictionary[text] = list;
}
list.Add(pluginImporter);
}
}
}
return dictionary;
}
public virtual bool CheckFileCollisions(string buildTargetName)
{
Dictionary<string, List<PluginImporter>> compatiblePlugins = this.GetCompatiblePlugins(buildTargetName);
bool flag = false;
StringBuilder stringBuilder = new StringBuilder();
foreach (KeyValuePair<string, List<PluginImporter>> current in compatiblePlugins)
{
List<PluginImporter> value = current.Value;
if (value.Count != 1)
{
flag = true;
stringBuilder.AppendLine(string.Format("Plugin '{0}' is used from several locations:", Path.GetFileName(current.Key)));
foreach (PluginImporter current2 in value)
{
stringBuilder.AppendLine(" " + current2.assetPath + " would be copied to <PluginPath>/" + current.Key.Replace("\\", "/"));
}
}
}
if (flag)
{
stringBuilder.AppendLine("Please fix plugin settings and try again.");
Debug.LogError(stringBuilder.ToString());
}
return flag;
}
}
}