com.typhoon.unitysdk 1.0.31 → 1.0.33

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,31 +1,77 @@
1
1
  using System;
2
2
  using System.Collections.Generic;
3
+ using System.Reflection;
3
4
  using UnityEditor;
4
- #if TYPHOON_ADDRESSABLE
5
- using UnityEditor.AddressableAssets.Build;
6
- using UnityEditor.AddressableAssets;
7
- using UnityEditor.AddressableAssets.Settings;
8
5
  using UnityEngine;
9
- using UnityEngine.AddressableAssets;
10
- #endif
11
6
 
12
7
  namespace TyphoonUnitySDK
13
8
  {
14
9
  /// <summary>
15
10
  /// addressable 支持
16
11
  /// </summary>
17
- public partial class AddressableSupport
12
+ public class AddressableSupport
18
13
  {
14
+ public const string TYPE_NAME_ADDRESSABLE_ASSET_SETTINGS =
15
+ "UnityEditor.AddressableAssets.Settings.AddressableAssetSettings";
16
+
17
+ public const string TYPE_NAME_BUNDLED_ASSET_GROUP_SCHEMA =
18
+ "UnityEditor.AddressableAssets.Settings.GroupSchemas.BundledAssetGroupSchema";
19
+
20
+ private static string _addressableAssetSettingsDefaultObjectTypeName = null;
21
+
22
+ private static Type _addressableAssetSettingsDefaultObjectType = null;
23
+
24
+ public static Type AddressableAssetSettingsDefaultObjectType
25
+ {
26
+ get
27
+ {
28
+ if (_addressableAssetSettingsDefaultObjectTypeName == null)
29
+ {
30
+ _addressableAssetSettingsDefaultObjectTypeName =
31
+ "UnityEditor.AddressableAssets.AddressableAssetSettingsDefaultObject";
32
+ _addressableAssetSettingsDefaultObjectType =
33
+ GetType(_addressableAssetSettingsDefaultObjectTypeName);
34
+ }
35
+
36
+ return _addressableAssetSettingsDefaultObjectType;
37
+ }
38
+ }
39
+
40
+ //是否有addressable模块
41
+ public static bool HasAddressableModule()
42
+ {
43
+ return AddressableAssetSettingsDefaultObjectType != null;
44
+ }
45
+
46
+ //AddressableAssetSettingsDefaultObject.Settings
47
+ public static dynamic DefaultSettings
48
+ {
49
+ get
50
+ {
51
+ if (AddressableAssetSettingsDefaultObjectType != null)
52
+ {
53
+ PropertyInfo propertyInfo =
54
+ AddressableAssetSettingsDefaultObjectType.GetProperty("Settings",
55
+ BindingFlags.Public | BindingFlags.Static);
56
+ if (propertyInfo != null)
57
+ {
58
+ return propertyInfo.GetValue(null);
59
+ }
60
+ }
61
+
62
+ return null;
63
+ }
64
+ }
65
+
19
66
  /// <summary>
20
67
  /// 弹出菜单,选择Profile
21
68
  /// </summary>
22
69
  public static void PopUpProfileSelectorMenu(PublishSetting publish)
23
70
  {
24
- #if TYPHOON_ADDRESSABLE
25
- var settings = AddressableAssetSettingsDefaultObject.Settings;
71
+ var settings = DefaultSettings;
26
72
  if (settings == null)
27
73
  {
28
- Debug.LogError("找不到Settings,请先初始化Addressables");
74
+ Debug.LogError("找不到Settings,请先初始化 Addressables");
29
75
  return;
30
76
  }
31
77
 
@@ -42,7 +88,6 @@ namespace TyphoonUnitySDK
42
88
  }
43
89
 
44
90
  menu.ShowAsContext();
45
- #endif
46
91
  }
47
92
 
48
93
 
@@ -51,11 +96,7 @@ namespace TyphoonUnitySDK
51
96
  /// </summary>
52
97
  public static bool HasDefaultSettings()
53
98
  {
54
- #if TYPHOON_ADDRESSABLE
55
- var settings = AddressableAssetSettingsDefaultObject.Settings;
56
- return settings != null;
57
- #endif
58
- return false;
99
+ return DefaultSettings != null;
59
100
  }
60
101
 
61
102
  /// <summary>
@@ -73,13 +114,11 @@ namespace TyphoonUnitySDK
73
114
  return;
74
115
  }
75
116
 
76
- #if TYPHOON_ADDRESSABLE
77
- var settings = AddressableAssetSettingsDefaultObject.Settings;
117
+ var settings = DefaultSettings;
78
118
  //激活profile
79
119
  settings.activeProfileId =
80
120
  settings.profileSettings.GetProfileId(publish.AAUseProfile);
81
121
  ModifyVariable(publish);
82
- #endif
83
122
  }
84
123
 
85
124
  /// <summary>
@@ -87,7 +126,6 @@ namespace TyphoonUnitySDK
87
126
  /// </summary>
88
127
  public static void SetVariable(PublishSetting publish, string variableName, string value, bool save = false)
89
128
  {
90
- #if TYPHOON_ADDRESSABLE
91
129
  if (string.IsNullOrEmpty(publish.AAUseProfile))
92
130
  {
93
131
  Debug.LogError("未关联profile");
@@ -95,12 +133,11 @@ namespace TyphoonUnitySDK
95
133
  }
96
134
 
97
135
  var success = SetVariable(publish.AAUseProfile, variableName, value);
98
- EditorUtility.SetDirty(AddressableAssetSettingsDefaultObject.Settings);
136
+ EditorUtility.SetDirty(DefaultSettings);
99
137
  if (save && success)
100
138
  {
101
139
  AssetDatabase.SaveAssets();
102
140
  }
103
- #endif
104
141
  }
105
142
 
106
143
  /// <summary>
@@ -108,15 +145,13 @@ namespace TyphoonUnitySDK
108
145
  /// </summary>
109
146
  public static void ModifyVariable(PublishSetting publish)
110
147
  {
111
- #if TYPHOON_ADDRESSABLE
112
148
  var modifies = publish.AAVariableModify;
113
149
  foreach (var modify in modifies)
114
150
  {
115
151
  SetVariable(publish.AAUseProfile, modify.VariableName, modify.VariableValue);
116
152
  }
117
153
 
118
- EditorUtility.SetDirty(AddressableAssetSettingsDefaultObject.Settings);
119
- #endif
154
+ EditorUtility.SetDirty(DefaultSettings);
120
155
  }
121
156
 
122
157
  /// <summary>
@@ -124,10 +159,9 @@ namespace TyphoonUnitySDK
124
159
  /// </summary>
125
160
  public static bool SetVariable(string profileName, string variableName, string value)
126
161
  {
127
- #if TYPHOON_ADDRESSABLE
128
162
  try
129
163
  {
130
- var settings = AddressableAssetSettingsDefaultObject.Settings;
164
+ var settings = DefaultSettings;
131
165
  var profileId = settings.profileSettings.GetProfileId(profileName);
132
166
  settings.profileSettings.SetValue(profileId, variableName, value);
133
167
  return true;
@@ -136,7 +170,7 @@ namespace TyphoonUnitySDK
136
170
  {
137
171
  Debug.LogError($"设置aa参数失败,profile:{profileName} vaiableName:{variableName} value:{value}");
138
172
  }
139
- #endif
173
+
140
174
  return false;
141
175
  }
142
176
 
@@ -145,7 +179,6 @@ namespace TyphoonUnitySDK
145
179
  /// </summary>
146
180
  public static bool ContainProfile(string profile)
147
181
  {
148
- #if TYPHOON_ADDRESSABLE
149
182
  try
150
183
  {
151
184
  if (string.IsNullOrEmpty(profile))
@@ -153,15 +186,13 @@ namespace TyphoonUnitySDK
153
186
  return false;
154
187
  }
155
188
 
156
- var settings = AddressableAssetSettingsDefaultObject.Settings;
189
+ var settings = DefaultSettings;
157
190
  return settings.profileSettings.GetAllProfileNames().Contains(profile);
158
191
  }
159
192
  catch (Exception e)
160
193
  {
161
194
  return false;
162
195
  }
163
- #endif
164
- return false;
165
196
  }
166
197
 
167
198
  /// <summary>
@@ -169,14 +200,13 @@ namespace TyphoonUnitySDK
169
200
  /// </summary>
170
201
  public static void BuildAASource(PublishSetting publish)
171
202
  {
172
- #if TYPHOON_ADDRESSABLE
173
203
  if (!HasDefaultSettings())
174
204
  {
175
205
  throw new Exception("未初始化Addresable");
176
206
  }
177
207
 
178
208
  //选择激活的参数
179
- var settings = AddressableAssetSettingsDefaultObject.Settings;
209
+ var settings = DefaultSettings;
180
210
  var profileId = settings.activeProfileId;
181
211
  if (publish.AASupportEnable && ContainProfile(publish.AAUseProfile))
182
212
  {
@@ -192,13 +222,16 @@ namespace TyphoonUnitySDK
192
222
 
193
223
  foreach (var builder in settings.DataBuilders)
194
224
  {
195
- AddressableAssetSettings.CleanPlayerContent(builder as IDataBuilder);
225
+ CallStaticMethod(TYPE_NAME_ADDRESSABLE_ASSET_SETTINGS,
226
+ "CleanPlayerContent", BindingFlags.Static | BindingFlags.Public,
227
+ new[] { builder });
228
+ // AddressableAssetSettings.CleanPlayerContent(builder as IDataBuilder);
196
229
  }
197
230
 
198
231
  Debug.Log($"profile:{settings.profileSettings.GetProfileName(profileId)}");
199
232
 
200
233
  //触发AA回调
201
- var sub = UniEditor.GetSubClasTypes(typeof(OnBuildAAProcessor));
234
+ var sub = GetSubClassTypes(typeof(OnBuildAAProcessor));
202
235
  var match = new List<OnBuildAAProcessor>();
203
236
  foreach (var type in sub)
204
237
  {
@@ -211,26 +244,34 @@ namespace TyphoonUnitySDK
211
244
  processor.OnBeforeBuild(publish);
212
245
  }
213
246
 
214
- AddressableAssetSettings.BuildPlayerContent();
247
+ var method = GetMethod(TYPE_NAME_ADDRESSABLE_ASSET_SETTINGS,
248
+ "BuildPlayerContent", BindingFlags.Static | BindingFlags.Public, 1);
249
+ if (method != null)
250
+ {
251
+ var outResult = new object[] { null };
252
+ method.Invoke(null, outResult);
253
+ }
215
254
 
255
+ // CallStaticMethod(TYPE_NAME_ADDRESSABLE_ASSET_SETTINGS,
256
+ // "BuildPlayerContent", BindingFlags.Static | BindingFlags.Public, null);
257
+ // AddressableAssetSettings.BuildPlayerContent();
216
258
  foreach (var processor in match)
217
259
  {
218
260
  processor.OnAfterBuild(publish);
219
261
  }
220
- #endif
221
262
  }
222
263
 
223
264
  /// <summary>
224
- /// 获取可能参数名
265
+ /// 获取参数名
225
266
  /// </summary>
226
267
  public static List<string> GetVariables()
227
268
  {
228
- #if TYPHOON_ADDRESSABLE
229
- var settings = AddressableAssetSettingsDefaultObject.Settings;
230
- if(settings!=null){
231
- return settings.profileSettings.GetVariableNames();
269
+ var settings = DefaultSettings;
270
+ if (settings != null)
271
+ {
272
+ return settings.profileSettings.GetVariableNames();
232
273
  }
233
- #endif
274
+
234
275
  var result = new List<string>();
235
276
  return result;
236
277
  }
@@ -241,31 +282,144 @@ namespace TyphoonUnitySDK
241
282
  /// </summary>
242
283
  public static string GetVariableValue(string variableName)
243
284
  {
244
- #if TYPHOON_ADDRESSABLE
245
285
  try
246
286
  {
247
- var settings = AddressableAssetSettingsDefaultObject.Settings;
287
+ var settings = DefaultSettings;
248
288
  return settings.profileSettings.GetValueByName(settings.activeProfileId, variableName);
249
289
  }
250
290
  finally
251
291
  {
252
292
  }
253
- #endif
293
+
254
294
  return string.Empty;
255
295
  }
256
296
 
257
- #if TYPHOON_ADDRESSABLE
258
297
  /// <summary>
259
298
  /// 快捷打开Addressable窗口
260
299
  /// </summary>
261
300
  [MenuItem("Window/Addressable Window", priority = 3)]
262
301
  public static void OpenAddressableWindow()
263
302
  {
264
- var type = UniEditor.GetType("UnityEditor.AddressableAssets.GUI.AddressableAssetsWindow");
265
- var window = UnityEditor.EditorWindow.GetWindow(type);
303
+ var type = GetType("UnityEditor.AddressableAssets.GUI.AddressableAssetsWindow");
304
+ var window = EditorWindow.GetWindow(type);
266
305
  window.titleContent = new GUIContent("Addressables Groups");
267
306
  window.Show();
268
307
  }
269
- #endif
308
+
309
+ [MenuItem("Window/Addressable Window", true)]
310
+ public static bool OpenAddressableWindowFunc()
311
+ {
312
+ return HasAddressableModule();
313
+ }
314
+
315
+ //执行静态方法
316
+ public static void CallStaticMethod(string typeName, string methodName, BindingFlags flags, object[] args,
317
+ int parameters = -1)
318
+ {
319
+ var type = GetType(typeName);
320
+ if (type != null)
321
+ {
322
+ MethodInfo method = null;
323
+ var methods = type.GetMethods();
324
+ if (parameters >= 0)
325
+ {
326
+ foreach (var e in methods)
327
+ {
328
+ if (e.Name == methodName && parameters == e.GetParameters().Length)
329
+ {
330
+ method = e;
331
+ break;
332
+ }
333
+ }
334
+ }
335
+ else
336
+ {
337
+ method = type.GetMethod(methodName, flags);
338
+ }
339
+
340
+ if (method != null)
341
+ {
342
+ method.Invoke(null, args);
343
+ }
344
+ }
345
+ }
346
+
347
+
348
+ //反射获取方法
349
+ public static MethodInfo GetMethod(string typeName, string methodName, BindingFlags flags,
350
+ int parameters = -1)
351
+ {
352
+ MethodInfo method = null;
353
+ var type = GetType(typeName);
354
+ if (type != null)
355
+ {
356
+ var methods = type.GetMethods();
357
+ if (parameters >= 0)
358
+ {
359
+ foreach (var e in methods)
360
+ {
361
+ if (e.Name == methodName && parameters == e.GetParameters().Length)
362
+ {
363
+ method = e;
364
+ return method;
365
+ }
366
+ }
367
+ }
368
+ else
369
+ {
370
+ method = type.GetMethod(methodName, flags);
371
+ }
372
+ }
373
+
374
+ return method;
375
+ }
376
+
377
+
378
+ /// <summary>
379
+ /// 反射获取类型
380
+ /// </summary>
381
+ public static Type GetType(string typeName)
382
+ {
383
+ var assemblies = AppDomain.CurrentDomain.GetAssemblies();
384
+ foreach (var element in assemblies)
385
+ {
386
+ var types = element.GetTypes();
387
+ foreach (var type in types)
388
+ {
389
+ if (type.FullName == typeName)
390
+ {
391
+ return type;
392
+ }
393
+ }
394
+ }
395
+
396
+ return null;
397
+ }
398
+
399
+ /// <summary>
400
+ /// 反射获取子类类型
401
+ /// </summary>
402
+ public static List<Type> GetSubClassTypes(Type check)
403
+ {
404
+ var result = new List<Type>();
405
+ var assemblies = AppDomain.CurrentDomain.GetAssemblies();
406
+ foreach (var element in assemblies)
407
+ {
408
+ var types = element.GetTypes();
409
+ foreach (var type in types)
410
+ {
411
+ if (type == check)
412
+ {
413
+ continue;
414
+ }
415
+ else if (type.IsSubclassOf(check))
416
+ {
417
+ result.Add(type);
418
+ }
419
+ }
420
+ }
421
+
422
+ return result;
423
+ }
270
424
  }
271
425
  }
@@ -273,7 +273,7 @@ namespace TyphoonUnitySDK
273
273
  /// </summary>
274
274
  public static void InvokeOnApplyStart(PublishSetting setting)
275
275
  {
276
- var sub = UniEditor.GetSubClasTypes(typeof(OnApplyProcessor));
276
+ var sub = UniEditor.GetSubClassTypes(typeof(OnApplyProcessor));
277
277
  var match = new List<OnApplyProcessor>();
278
278
  foreach (var type in sub)
279
279
  {
@@ -292,7 +292,7 @@ namespace TyphoonUnitySDK
292
292
  /// </summary>
293
293
  public static void InvokeOnApplyEnd(PublishSetting setting)
294
294
  {
295
- var sub = UniEditor.GetSubClasTypes(typeof(OnApplyProcessor));
295
+ var sub = UniEditor.GetSubClassTypes(typeof(OnApplyProcessor));
296
296
  var match = new List<OnApplyProcessor>();
297
297
  foreach (var type in sub)
298
298
  {
@@ -34,10 +34,6 @@ namespace TyphoonUnitySDK
34
34
  }
35
35
  }
36
36
 
37
-
38
- public bool CheckAddressableSupport = true;
39
-
40
-
41
37
  [Header("gradle目录")] public string GradlePath = string.Empty;
42
38
  }
43
39
  }
@@ -65,24 +65,16 @@ namespace TyphoonUnitySDK
65
65
  new Dictionary<string, Func<Preferences, bool>>()
66
66
  {
67
67
  { "m_Script", DrawProperty_mScript },
68
- { nameof(Preferences.CheckAddressableSupport), DrawProperty_CheckAddressableSupport },
69
68
  { nameof(Preferences.GradlePath), DrawProperty_GradlePath },
70
69
  };
71
70
 
72
- private static bool DrawProperty_CheckAddressableSupport(Preferences arg)
73
- {
74
- GUILayout.Space(10);
75
- Preferences.Default.CheckAddressableSupport =
76
- GUILayout.Toggle(Preferences.Default.CheckAddressableSupport, "检查Addressable支持");
77
- return true;
78
- }
79
71
 
80
72
  private static bool DrawProperty_mScript(Preferences arg)
81
73
  {
82
74
  var temEnable = GUI.enabled;
83
75
  GUI.enabled = true;
84
76
  GUIDrawer.DrawKeynotes("使用须知:");
85
- GUIDrawer.DrawKeynotes("①工具对Addressable有支持,从菜单:'TyphoonSDK/安装拓展...' 中导入");
77
+ GUIDrawer.DrawKeynotes("①工具对Addressable有支持,导入即可开启额外设置");
86
78
  GUI.enabled = temEnable;
87
79
  return true;
88
80
  }
@@ -71,7 +71,7 @@ namespace TyphoonUnitySDK
71
71
 
72
72
  public static void InvokeOnPublishStart(PublishSetting setting)
73
73
  {
74
- var sub = UniEditor.GetSubClasTypes(typeof(OnPublicProcessor));
74
+ var sub = UniEditor.GetSubClassTypes(typeof(OnPublicProcessor));
75
75
  var match = new List<OnPublicProcessor>();
76
76
  foreach (var type in sub)
77
77
  {
@@ -90,7 +90,7 @@ namespace TyphoonUnitySDK
90
90
  /// </summary>
91
91
  public static void InvokeOnPublishEnd(PublishSetting setting, PublishResult publishResult)
92
92
  {
93
- var sub = UniEditor.GetSubClasTypes(typeof(OnPublicProcessor));
93
+ var sub = UniEditor.GetSubClassTypes(typeof(OnPublicProcessor));
94
94
  var match = new List<OnPublicProcessor>();
95
95
  foreach (var type in sub)
96
96
  {
@@ -83,9 +83,6 @@ namespace TyphoonUnitySDK
83
83
  }
84
84
  }
85
85
  }
86
-
87
- //检查一些事情
88
- UniEditor.CheckSomethingsOnPublishWindowShow();
89
86
  }
90
87
 
91
88
  protected void OnGUI()
@@ -217,7 +217,7 @@ namespace TyphoonUnitySDK
217
217
  /// <summary>
218
218
  /// 反射获取子类类型
219
219
  /// </summary>
220
- public static List<Type> GetSubClasTypes(Type check)
220
+ public static List<Type> GetSubClassTypes(Type check)
221
221
  {
222
222
  var result = new List<Type>();
223
223
  var assemblies = AppDomain.CurrentDomain.GetAssemblies();
@@ -240,60 +240,13 @@ namespace TyphoonUnitySDK
240
240
  return result;
241
241
  }
242
242
 
243
- /// <summary>
244
- /// 是否安装了Addressable
245
- /// </summary>
246
- public static bool HasAddressable()
247
- {
248
- return GetType("UnityEngine.AddressableAssets.Addressables") != null;
249
- }
250
243
 
251
244
  /// <summary>
252
245
  /// 是否添加了addressable支持
253
246
  /// </summary>
254
247
  public static bool HasAddressableSupport()
255
248
  {
256
- #if TYPHOON_ADDRESSABLE
257
- return true;
258
- #endif
259
- return false;
260
- }
261
-
262
-
263
- [MenuItem("TyphoonSDK/安装拓展/Addressable 支持", priority = 100)]
264
- public static void InstallAddressableSupport()
265
- {
266
- AppendScriptingDefineSymbol(DEFINE_TYPHOON_ADDRESSABLE_NAME);
267
- AssetDatabase.Refresh();
268
- AssetDatabase.SaveAssets();
269
- Debug.Log("Addressable 支持,安装成功!");
270
- }
271
-
272
- [MenuItem("TyphoonSDK/安装拓展/Addressable 支持", true)]
273
- public static bool InstallAddressableSupportValid()
274
- {
275
- return HasAddressable() && !HasAddressableSupport();
276
- }
277
-
278
- [MenuItem("TyphoonSDK/卸载/Addressable 支持", priority = 100)]
279
- public static void UninstallAddressableSupport()
280
- {
281
- ShowMessageBox("卸载Addressable 支持,可能会导致一些配置丢失,请做好备份,仍然继续吗?", () =>
282
- {
283
- ClearScriptingDefineSymbol(DEFINE_TYPHOON_ADDRESSABLE_NAME);
284
- AssetDatabase.Refresh();
285
- AssetDatabase.SaveAssets();
286
- Debug.Log("Addressable 支持,卸载完毕!");
287
- });
288
- }
289
-
290
- [MenuItem("TyphoonSDK/卸载/Addressable 支持", true)]
291
- public static bool UninstallAddressableSupportValid()
292
- {
293
- #if TYPHOON_ADDRESSABLE
294
- return true;
295
- #endif
296
- return false;
249
+ return AddressableSupport.HasAddressableModule();
297
250
  }
298
251
 
299
252
  [MenuItem("TyphoonSDK/安装拓展/Toast模块", priority = 100)]
@@ -532,15 +485,5 @@ namespace TyphoonUnitySDK
532
485
 
533
486
  File.WriteAllText(path, sb.ToString());
534
487
  }
535
-
536
-
537
- /*发布窗口打开时触发一些事情*/
538
- public static void CheckSomethingsOnPublishWindowShow()
539
- {
540
- if (Preferences.Default.CheckAddressableSupport && HasAddressable() && !HasAddressableSupport())
541
- {
542
- ShowMessageBox("检查到Addressable,是否添加拓展[Addressable支持],可从选项中关闭", InstallAddressableSupport);
543
- }
544
- }
545
488
  }
546
489
  }
package/package.json CHANGED
@@ -1 +1 @@
1
- {"name":"com.typhoon.unitysdk","displayName":"typhoon unity sdk","version":"1.0.31","description":"","unity":"2018.1","type":"tool","hideInEditor":false,"author":{"name":"Jan Zhang","email":"","url":""},"changelogUrl":"","documentationUrl":"","keywords":["typhoon"],"license":"","licensesUrl":"","customDependencies":[{"PackageName":"com.unity.nuget.newtonsoft-json","Value":"2.0.0"}],"dependencies":{"com.unity.nuget.newtonsoft-json":"2.0.0"}}
1
+ {"name":"com.typhoon.unitysdk","displayName":"typhoon unity sdk","version":"1.0.33","description":"","unity":"2018.1","type":"tool","hideInEditor":false,"author":{"name":"Jan Zhang","email":"","url":""},"changelogUrl":"","documentationUrl":"","keywords":["typhoon"],"license":"","licensesUrl":"","customDependencies":[{"PackageName":"com.unity.nuget.newtonsoft-json","Value":"2.0.0"}],"dependencies":{"com.unity.nuget.newtonsoft-json":"2.0.0"}}