com.xd.sdk.common 7.1.1 → 7.1.2

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.
Files changed (80) hide show
  1. package/Editor/Android/XDCommonAndroidGradleProcessor.cs +2 -0
  2. package/Plugins/Android/libs/XDGBridgeCommon_v7_7.1.2.aar +0 -0
  3. package/Plugins/Android/libs/XDGCommon_7.1.2.aar +0 -0
  4. package/Plugins/Android/libs/XDGTapTapWrapperInternal_7.1.2.aar +0 -0
  5. package/Plugins/iOS/Resource/TapTapLoginResource.bundle/userProfile/dark/tap_profile_chat.png +0 -0
  6. package/Plugins/iOS/Resource/TapTapLoginResource.bundle/userProfile/dark/tap_profile_invite.png +0 -0
  7. package/Plugins/iOS/Resource/TapTapLoginResource.bundle/userProfile/dark/tap_profile_unfollow.png +0 -0
  8. package/Plugins/iOS/Resource/TapTapLoginResource.bundle/userProfile/light/tap_profile_chat.png +0 -0
  9. package/Plugins/iOS/Resource/TapTapLoginResource.bundle/userProfile/light/tap_profile_invite.png +0 -0
  10. package/Plugins/iOS/Resource/TapTapLoginResource.bundle/userProfile/light/tap_profile_unfollow.png +0 -0
  11. package/Plugins/iOS/Resource/TapTapLoginResource.bundle/userProfile/tap_profile_achievement.png +0 -0
  12. package/Plugins/iOS/Resource/TapTapLoginResource.bundle/userProfile/tap_profile_achievement_platinum.png +0 -0
  13. package/Plugins/iOS/Resource/TapTapLoginResource.bundle/userProfile/tap_profile_arrow.png +0 -0
  14. package/Plugins/iOS/Resource/TapTapLoginResource.bundle/userProfile/tap_profile_close.png +0 -0
  15. package/Plugins/iOS/Resource/TapTapLoginResource.bundle/userProfile/tap_profile_default_background.png +0 -0
  16. package/Plugins/iOS/Resource/TapTapLoginResource.bundle/userProfile/tap_profile_logo.png +0 -0
  17. package/Plugins/iOS/XDCommonSDK.framework/Headers/XDConfigManager.h +1 -1
  18. package/Plugins/iOS/XDCommonSDK.framework/Headers/XDGAnnouncementConfig.h.meta +7 -0
  19. package/Plugins/iOS/XDCommonSDK.framework/Headers/XDGAnnouncementManager.h.meta +7 -0
  20. package/Plugins/iOS/XDCommonSDK.framework/Headers/XDGConfig.h +2 -0
  21. package/Plugins/iOS/XDCommonSDK.framework/Headers/XDGInitParam.h +5 -0
  22. package/Plugins/iOS/XDCommonSDK.framework/Headers/XDTapTapInfo.h +4 -1
  23. package/Plugins/iOS/XDCommonSDK.framework/Headers/XDVersion.h +3 -3
  24. package/Plugins/iOS/XDCommonSDK.framework/Info.plist +0 -0
  25. package/Plugins/iOS/XDCommonSDK.framework/XDCommonSDK +0 -0
  26. package/Plugins/iOS/XDTapSDK4WrapperSDK.framework/Headers/XDTapSDK4WrapperSDK.h +3 -3
  27. package/Plugins/iOS/XDTapSDK4WrapperSDK.framework/Info.plist +0 -0
  28. package/Plugins/iOS/XDTapSDK4WrapperSDK.framework/XDTapSDK4WrapperSDK +0 -0
  29. package/Runtime/Internal/Events/XDGEventBus.cs +8 -7
  30. package/Runtime/Internal/Mobile/CommonFeaturesImpl.cs +11 -10
  31. package/Runtime/Internal/Mobile/Http/CommonParamsInterceptor.cs +1 -1
  32. package/Runtime/Internal/Standalone/Agreement/AgreementModule.cs +4 -4
  33. package/Runtime/Internal/Standalone/CommonFeaturesImpl.cs +7 -5
  34. package/Runtime/Internal/Standalone/Config/AppConfig.cs +3 -1
  35. package/Runtime/Internal/Standalone/Config/ConfigModule.cs +5 -2
  36. package/Runtime/Internal/Standalone/Http/Interceptor/MacAuthenticationInterceptor.cs +4 -4
  37. package/Runtime/Internal/Standalone/Http/Interceptor/StandaloneErrorHandlingInterceptor.cs +5 -5
  38. package/Runtime/Internal/Standalone/Http/XDHttpUtils.cs +39 -16
  39. package/Runtime/Internal/Standalone/IPInfo/IPInfoModule.cs +42 -20
  40. package/Runtime/Internal/Standalone/IPInfo/XDGAreaCode.cs +1 -1
  41. package/Runtime/Internal/Standalone/Persistence/Persistence.cs +42 -22
  42. package/Runtime/Internal/Standalone/Steam/SteamUtils.cs +14 -7
  43. package/Runtime/Internal/Standalone/Track/AliyunTrack.cs +5 -5
  44. package/Runtime/Internal/Standalone/UI/Base/UIManager.cs +3 -2
  45. package/Runtime/Internal/Standalone/UI/Controllers/CancelAccountAlert.cs +69 -33
  46. package/Runtime/Internal/Standalone/UI/Controllers/GeneralAgreementAlert.cs +29 -22
  47. package/Runtime/Internal/Standalone/UI/Controllers/XDWebViewAlert.cs +4 -5
  48. package/Runtime/Internal/Standalone/Utils/SteamWrapper.cs +2 -2
  49. package/Runtime/Internal/Standalone/Utils/TaskDispatcher.cs +1 -1
  50. package/Runtime/Internal/Standalone/Utils/WindowsRegistryAccess.cs +7 -7
  51. package/Runtime/Internal/Standalone/Web/Function/BackgroundColorWebFunction.cs +1 -1
  52. package/Runtime/Internal/Standalone/Web/Function/ClipboardWebFunction.cs +1 -1
  53. package/Runtime/Internal/Standalone/Web/Function/CloseWebFunction.cs +3 -3
  54. package/Runtime/Internal/Standalone/Web/Function/DeviceInfoWebFunction.cs +1 -1
  55. package/Runtime/Internal/Standalone/Web/Function/GameMessageWebFunction.cs +1 -1
  56. package/Runtime/Internal/Standalone/Web/Function/GetSafeAreaWebFunction.cs +1 -1
  57. package/Runtime/Internal/Standalone/Web/Function/GetStorageWebFunction.cs +1 -1
  58. package/Runtime/Internal/Standalone/Web/Function/HttpRequestWebFunction.cs +1 -1
  59. package/Runtime/Internal/Standalone/Web/Function/LoadingWebFunction.cs +1 -1
  60. package/Runtime/Internal/Standalone/Web/Function/LogWebFunction.cs +5 -5
  61. package/Runtime/Internal/Standalone/Web/Function/NavigationWebFunction.cs +1 -1
  62. package/Runtime/Internal/Standalone/Web/Function/OpenPageWebFunction.cs +1 -1
  63. package/Runtime/Internal/Standalone/Web/Function/PutStorageWebFunction.cs +1 -1
  64. package/Runtime/Internal/Standalone/Web/Function/ToastWebFunction.cs +1 -1
  65. package/Runtime/Internal/Standalone/Web/Function/TrackEventWebFunction.cs +1 -1
  66. package/Runtime/Internal/Standalone/Web/WebBridgeController.cs +6 -7
  67. package/Runtime/Internal/Standalone/Web/WebRequest.cs +2 -2
  68. package/Runtime/Internal/Standalone/Web/XDWebBridgeView.cs +1 -1
  69. package/Runtime/Internal/XDGCommonInternal.cs +1 -1
  70. package/package.json +2 -2
  71. package/Plugins/Android/libs/XDGBridgeCommon_v7_7.1.0.aar +0 -0
  72. package/Plugins/Android/libs/XDGCommon_7.1.0.aar +0 -0
  73. package/Plugins/Android/libs/XDGTapTapWrapperInternal_7.1.0.aar +0 -0
  74. package/Runtime/Internal/Core/ReflectionUtils.cs +0 -640
  75. package/Runtime/Internal/Core/ReflectionUtils.cs.meta +0 -3
  76. /package/Plugins/Android/libs/{XDGBridgeCommon_v7_7.1.0.aar.meta → XDGBridgeCommon_v7_7.1.2.aar.meta} +0 -0
  77. /package/Plugins/Android/libs/{XDGCommon_7.1.0.aar.meta → XDGCommon_7.1.2.aar.meta} +0 -0
  78. /package/Plugins/Android/libs/{XDGTapTapWrapperInternal_7.1.0.aar.meta → XDGTapTapWrapperInternal_7.1.2.aar.meta} +0 -0
  79. /package/Plugins/Android/libs/{XDTapTapWrapper_7.1.0.aar → XDTapTapWrapper_7.1.2.aar} +0 -0
  80. /package/Plugins/Android/libs/{XDTapTapWrapper_7.1.0.aar.meta → XDTapTapWrapper_7.1.2.aar.meta} +0 -0
@@ -1,640 +0,0 @@
1
- using System;
2
- using System.Reflection;
3
- using System.Collections.Generic;
4
- using UnityEngine;
5
-
6
- namespace XD.SDK.Common.Internal
7
- {
8
- /// <summary>
9
- /// 反射工具类,用于在不直接依赖的情况下调用其他模块的方法
10
- /// </summary>
11
- public static class ReflectionUtils
12
- {
13
- // 缓存已查找的类型,提高性能
14
- private static Dictionary<string, Type> _typeCache = new Dictionary<string, Type>();
15
-
16
- /// <summary>
17
- /// 查找一个类型
18
- /// </summary>
19
- /// <param name="fullTypeName">完整类型名称,包含命名空间</param>
20
- /// <param name="assemblyName">程序集名称,不含.dll后缀</param>
21
- /// <returns>找到的类型,未找到返回null</returns>
22
- public static Type FindType(string fullTypeName, string assemblyName = null)
23
- {
24
- string cacheKey = assemblyName != null ? $"{fullTypeName},{assemblyName}" : fullTypeName;
25
-
26
- // 检查缓存
27
- if (_typeCache.TryGetValue(cacheKey, out Type cachedType))
28
- {
29
- return cachedType;
30
- }
31
-
32
- Type type = null;
33
-
34
- try
35
- {
36
- // 尝试直接查找类型(如果程序集已加载)
37
- if (assemblyName != null)
38
- {
39
- type = Type.GetType($"{fullTypeName}, {assemblyName}");
40
- }
41
- else
42
- {
43
- type = Type.GetType(fullTypeName);
44
- }
45
-
46
- // 如果未找到,在所有加载的程序集中查找
47
- if (type == null)
48
- {
49
- Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
50
- foreach (Assembly assembly in assemblies)
51
- {
52
- type = assembly.GetType(fullTypeName);
53
- if (type != null)
54
- {
55
- break;
56
- }
57
- }
58
- }
59
- }
60
- catch (Exception ex)
61
- {
62
- Debug.LogError($"查找类型 {fullTypeName} 时出错: {ex.Message}");
63
- }
64
-
65
- // 更新缓存
66
- if (type != null)
67
- {
68
- _typeCache[cacheKey] = type;
69
- }
70
-
71
- return type;
72
- }
73
-
74
- /// <summary>
75
- /// 创建类型的实例
76
- /// </summary>
77
- /// <param name="type">要创建的类型</param>
78
- /// <param name="parameters">构造函数参数</param>
79
- /// <returns>创建的实例,失败返回null</returns>
80
- public static object CreateInstance(Type type, params object[] parameters)
81
- {
82
- if (type == null) return null;
83
-
84
- try
85
- {
86
- return Activator.CreateInstance(type, parameters);
87
- }
88
- catch (Exception ex)
89
- {
90
- Debug.LogError($"创建 {type.Name} 实例时出错: {ex.Message}");
91
- return null;
92
- }
93
- }
94
-
95
- /// <summary>
96
- /// 查找并调用静态方法
97
- /// </summary>
98
- /// <param name="type">类型</param>
99
- /// <param name="methodName">方法名</param>
100
- /// <param name="parameters">方法参数</param>
101
- /// <returns>方法返回值,失败返回null</returns>
102
- public static object InvokeStaticMethod(Type type, string methodName, params object[] parameters)
103
- {
104
- if (type == null) return null;
105
-
106
- try
107
- {
108
- // 直接按方法名查找,不做复杂匹配
109
- MethodInfo method = type.GetMethod(methodName,
110
- BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.IgnoreCase);
111
-
112
- if (method != null)
113
- {
114
- return method.Invoke(null, parameters);
115
- }
116
- else
117
- {
118
- Debug.LogError($"找不到方法: {type.Name}.{methodName}");
119
- }
120
- }
121
- catch (Exception ex)
122
- {
123
- Debug.LogError($"调用 {type.Name}.{methodName} 静态方法时出错: {ex.Message}");
124
- }
125
-
126
- return null;
127
- }
128
-
129
- /// <summary>
130
- /// 调用实例方法
131
- /// </summary>
132
- /// <param name="instance">实例对象</param>
133
- /// <param name="methodName">方法名</param>
134
- /// <param name="parameters">方法参数</param>
135
- /// <returns>方法返回值,失败返回null</returns>
136
- public static object InvokeMethod(object instance, string methodName, params object[] parameters)
137
- {
138
- if (instance == null) return null;
139
-
140
- Type type = instance.GetType();
141
-
142
- try
143
- {
144
- // 直接按方法名查找,不做复杂匹配
145
- MethodInfo method = type.GetMethod(methodName,
146
- BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.IgnoreCase);
147
-
148
- if (method != null)
149
- {
150
- return method.Invoke(instance, parameters);
151
- }
152
- else
153
- {
154
- Debug.LogError($"找不到方法: {type.Name}.{methodName}");
155
- }
156
- }
157
- catch (Exception ex)
158
- {
159
- Debug.LogError($"调用 {type.Name}.{methodName} 实例方法时出错: {ex.Message}");
160
- }
161
-
162
- return null;
163
- }
164
-
165
- /// <summary>
166
- /// 获取静态属性值
167
- /// </summary>
168
- /// <param name="type">类型</param>
169
- /// <param name="propertyName">属性名称</param>
170
- /// <returns>属性值,失败返回null</returns>
171
- public static object GetStaticProperty(Type type, string propertyName)
172
- {
173
- if (type == null) return null;
174
-
175
- try
176
- {
177
- PropertyInfo property = type.GetProperty(propertyName,
178
- BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
179
-
180
- if (property != null)
181
- {
182
- return property.GetValue(null);
183
- }
184
- }
185
- catch (Exception ex)
186
- {
187
- Debug.LogError($"获取 {type.Name}.{propertyName} 静态属性时出错: {ex.Message}");
188
- }
189
-
190
- return null;
191
- }
192
-
193
- /// <summary>
194
- /// 获取静态字段值
195
- /// </summary>
196
- /// <param name="type">类型</param>
197
- /// <param name="fieldName">字段名称</param>
198
- /// <returns>字段值,失败返回null</returns>
199
- public static object GetStaticField(Type type, string fieldName)
200
- {
201
- if (type == null) return null;
202
-
203
- try
204
- {
205
- FieldInfo field = type.GetField(fieldName,
206
- BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
207
-
208
- if (field != null)
209
- {
210
- return field.GetValue(null);
211
- }
212
- }
213
- catch (Exception ex)
214
- {
215
- Debug.LogError($"获取 {type.Name}.{fieldName} 静态字段时出错: {ex.Message}");
216
- }
217
-
218
- return null;
219
- }
220
-
221
- /// <summary>
222
- /// 获取实例属性值
223
- /// </summary>
224
- /// <param name="instance">实例对象</param>
225
- /// <param name="propertyName">属性名称</param>
226
- /// <returns>属性值,失败返回null</returns>
227
- public static object GetProperty(object instance, string propertyName)
228
- {
229
- if (instance == null) return null;
230
-
231
- Type type = instance.GetType();
232
-
233
- try
234
- {
235
- PropertyInfo property = type.GetProperty(propertyName,
236
- BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
237
-
238
- if (property != null)
239
- {
240
- return property.GetValue(instance);
241
- }
242
- }
243
- catch (Exception ex)
244
- {
245
- Debug.LogError($"获取 {type.Name}.{propertyName} 实例属性时出错: {ex.Message}");
246
- }
247
-
248
- return null;
249
- }
250
-
251
- /// <summary>
252
- /// 获取实例字段值
253
- /// </summary>
254
- /// <param name="instance">实例对象</param>
255
- /// <param name="fieldName">字段名称</param>
256
- /// <returns>字段值,失败返回null</returns>
257
- public static object GetField(object instance, string fieldName)
258
- {
259
- if (instance == null) return null;
260
-
261
- Type type = instance.GetType();
262
-
263
- try
264
- {
265
- FieldInfo field = type.GetField(fieldName,
266
- BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
267
-
268
- if (field != null)
269
- {
270
- return field.GetValue(instance);
271
- }
272
- }
273
- catch (Exception ex)
274
- {
275
- Debug.LogError($"获取 {type.Name}.{fieldName} 实例字段时出错: {ex.Message}");
276
- }
277
-
278
- return null;
279
- }
280
-
281
- /// <summary>
282
- /// 为静态属性设置值
283
- /// </summary>
284
- /// <param name="type">类型</param>
285
- /// <param name="propertyName">属性名称</param>
286
- /// <param name="value">要设置的值</param>
287
- /// <returns>是否设置成功</returns>
288
- public static bool SetStaticProperty(Type type, string propertyName, object value)
289
- {
290
- if (type == null) return false;
291
-
292
- try
293
- {
294
- PropertyInfo property = type.GetProperty(propertyName,
295
- BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
296
-
297
- if (property != null)
298
- {
299
- property.SetValue(null, value);
300
- return true;
301
- }
302
- }
303
- catch (Exception ex)
304
- {
305
- Debug.LogError($"设置 {type.Name}.{propertyName} 静态属性时出错: {ex.Message}");
306
- }
307
-
308
- return false;
309
- }
310
-
311
- /// <summary>
312
- /// 为静态字段设置值
313
- /// </summary>
314
- /// <param name="type">类型</param>
315
- /// <param name="fieldName">字段名称</param>
316
- /// <param name="value">要设置的值</param>
317
- /// <returns>是否设置成功</returns>
318
- public static bool SetStaticField(Type type, string fieldName, object value)
319
- {
320
- if (type == null) return false;
321
-
322
- try
323
- {
324
- FieldInfo field = type.GetField(fieldName,
325
- BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
326
-
327
- if (field != null)
328
- {
329
- field.SetValue(null, value);
330
- return true;
331
- }
332
- }
333
- catch (Exception ex)
334
- {
335
- Debug.LogError($"设置 {type.Name}.{fieldName} 静态字段时出错: {ex.Message}");
336
- }
337
-
338
- return false;
339
- }
340
-
341
- /// <summary>
342
- /// 为实例字段设置值
343
- /// </summary>
344
- /// <param name="instance">实例对象</param>
345
- /// <param name="fieldName">字段名称</param>
346
- /// <param name="value">要设置的值</param>
347
- /// <returns>是否设置成功</returns>
348
- public static bool SetField(object instance, string fieldName, object value)
349
- {
350
- if (instance == null) return false;
351
-
352
- Type type = instance.GetType();
353
-
354
- try
355
- {
356
- FieldInfo field = type.GetField(fieldName,
357
- BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
358
-
359
- if (field != null)
360
- {
361
- field.SetValue(instance, value);
362
- return true;
363
- }
364
- }
365
- catch (Exception ex)
366
- {
367
- Debug.LogError($"设置 {type.Name}.{fieldName} 实例字段时出错: {ex.Message}");
368
- }
369
-
370
- return false;
371
- }
372
-
373
- /// <summary>
374
- /// 为实例属性设置值
375
- /// </summary>
376
- /// <param name="instance">实例对象</param>
377
- /// <param name="propertyName">属性名称</param>
378
- /// <param name="value">要设置的值</param>
379
- /// <returns>是否设置成功</returns>
380
- public static bool SetProperty(object instance, string propertyName, object value)
381
- {
382
- if (instance == null) return false;
383
-
384
- Type type = instance.GetType();
385
-
386
- try
387
- {
388
- PropertyInfo property = type.GetProperty(propertyName,
389
- BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
390
-
391
- if (property != null)
392
- {
393
- property.SetValue(instance, value);
394
- return true;
395
- }
396
- }
397
- catch (Exception ex)
398
- {
399
- Debug.LogError($"设置 {type.Name}.{propertyName} 实例属性时出错: {ex.Message}");
400
- }
401
-
402
- return false;
403
- }
404
-
405
- /// <summary>
406
- /// 创建一个泛型类型
407
- /// </summary>
408
- /// <param name="genericTypeDefinition">泛型类型定义</param>
409
- /// <param name="typeArguments">泛型参数</param>
410
- /// <returns>构造的泛型类型</returns>
411
- public static Type MakeGenericType(Type genericTypeDefinition, params Type[] typeArguments)
412
- {
413
- if (genericTypeDefinition == null || !genericTypeDefinition.IsGenericTypeDefinition)
414
- return null;
415
-
416
- try
417
- {
418
- return genericTypeDefinition.MakeGenericType(typeArguments);
419
- }
420
- catch (Exception ex)
421
- {
422
- Debug.LogError($"创建泛型类型 {genericTypeDefinition.Name} 时出错: {ex.Message}");
423
- return null;
424
- }
425
- }
426
-
427
- /// <summary>
428
- /// 创建委托
429
- /// </summary>
430
- /// <param name="delegateType">委托类型</param>
431
- /// <param name="target">目标实例</param>
432
- /// <param name="methodName">方法名</param>
433
- /// <returns>创建的委托</returns>
434
- public static Delegate CreateDelegate(Type delegateType, object target, string methodName)
435
- {
436
- if (delegateType == null || target == null) return null;
437
-
438
- try
439
- {
440
- MethodInfo method = target.GetType().GetMethod(methodName,
441
- BindingFlags.Public | BindingFlags.NonPublic |
442
- BindingFlags.Instance | BindingFlags.Static);
443
-
444
- if (method != null)
445
- {
446
- return Delegate.CreateDelegate(delegateType, target, method);
447
- }
448
- }
449
- catch (Exception ex)
450
- {
451
- Debug.LogError($"创建委托 {delegateType.Name} 指向 {target.GetType().Name}.{methodName} 时出错: {ex.Message}");
452
- }
453
-
454
- return null;
455
- }
456
-
457
- /// <summary>
458
- /// 异步调用静态方法并返回结果
459
- /// </summary>
460
- /// <typeparam name="T">返回值类型</typeparam>
461
- /// <param name="type">类型</param>
462
- /// <param name="methodName">方法名</param>
463
- /// <param name="parameters">方法参数</param>
464
- /// <returns>异步任务结果</returns>
465
- public static async System.Threading.Tasks.Task<T> InvokeStaticMethodAsync<T>(Type type, string methodName, params object[] parameters)
466
- {
467
- if (type == null) return default(T);
468
-
469
- try
470
- {
471
- var result = InvokeStaticMethod(type, methodName, parameters);
472
- if (result is System.Threading.Tasks.Task task)
473
- {
474
- await task;
475
-
476
- // 检查是否是 Task<T>
477
- if (task.GetType().IsGenericType)
478
- {
479
- var resultProperty = task.GetType().GetProperty("Result");
480
- if (resultProperty != null)
481
- {
482
- var taskResult = resultProperty.GetValue(task);
483
- return ConvertToType<T>(taskResult);
484
- }
485
- }
486
- }
487
-
488
- // 如果不是异步方法,直接返回结果
489
- return ConvertToType<T>(result);
490
- }
491
- catch (Exception ex)
492
- {
493
- Debug.LogError($"异步调用 {type.Name}.{methodName} 静态方法时出错: {ex.Message}");
494
- return default(T);
495
- }
496
- }
497
-
498
- /// <summary>
499
- /// 异步调用静态方法(无返回值)
500
- /// </summary>
501
- /// <param name="type">类型</param>
502
- /// <param name="methodName">方法名</param>
503
- /// <param name="parameters">方法参数</param>
504
- /// <returns>异步任务</returns>
505
- public static async System.Threading.Tasks.Task InvokeStaticMethodAsync(Type type, string methodName, params object[] parameters)
506
- {
507
- if (type == null) return;
508
-
509
- try
510
- {
511
- var result = InvokeStaticMethod(type, methodName, parameters);
512
- if (result is System.Threading.Tasks.Task task)
513
- {
514
- await task;
515
- }
516
- }
517
- catch (Exception ex)
518
- {
519
- Debug.LogError($"异步调用 {type.Name}.{methodName} 静态方法时出错: {ex.Message}");
520
- }
521
- }
522
-
523
- /// <summary>
524
- /// 异步调用实例方法并返回结果
525
- /// </summary>
526
- /// <typeparam name="T">返回值类型</typeparam>
527
- /// <param name="instance">实例对象</param>
528
- /// <param name="methodName">方法名</param>
529
- /// <param name="parameters">方法参数</param>
530
- /// <returns>异步任务结果</returns>
531
- public static async System.Threading.Tasks.Task<T> InvokeMethodAsync<T>(object instance, string methodName, params object[] parameters)
532
- {
533
- if (instance == null) return default(T);
534
-
535
- try
536
- {
537
- var result = InvokeMethod(instance, methodName, parameters);
538
- if (result is System.Threading.Tasks.Task task)
539
- {
540
- await task;
541
-
542
- // 检查是否是 Task<T>
543
- if (task.GetType().IsGenericType)
544
- {
545
- var resultProperty = task.GetType().GetProperty("Result");
546
- if (resultProperty != null)
547
- {
548
- var taskResult = resultProperty.GetValue(task);
549
- return ConvertToType<T>(taskResult);
550
- }
551
- }
552
- }
553
-
554
- // 如果不是异步方法,直接返回结果
555
- return ConvertToType<T>(result);
556
- }
557
- catch (Exception ex)
558
- {
559
- Debug.LogError($"异步调用 {instance.GetType().Name}.{methodName} 实例方法时出错: {ex.Message}");
560
- return default(T);
561
- }
562
- }
563
-
564
- /// <summary>
565
- /// 异步调用实例方法(无返回值)
566
- /// </summary>
567
- /// <param name="instance">实例对象</param>
568
- /// <param name="methodName">方法名</param>
569
- /// <param name="parameters">方法参数</param>
570
- /// <returns>异步任务</returns>
571
- public static async System.Threading.Tasks.Task InvokeMethodAsync(object instance, string methodName, params object[] parameters)
572
- {
573
- if (instance == null) return;
574
-
575
- try
576
- {
577
- var result = InvokeMethod(instance, methodName, parameters);
578
- if (result is System.Threading.Tasks.Task task)
579
- {
580
- await task;
581
- }
582
- }
583
- catch (Exception ex)
584
- {
585
- Debug.LogError($"异步调用 {instance.GetType().Name}.{methodName} 实例方法时出错: {ex.Message}");
586
- }
587
- }
588
-
589
- /// <summary>
590
- /// 通用异步方法调用辅助方法,自动处理 Task 和 Task<T> 类型
591
- /// </summary>
592
- /// <param name="taskResult">方法调用返回的对象</param>
593
- /// <returns>异步任务结果</returns>
594
- public static async System.Threading.Tasks.Task<object> HandleAsyncResult(object taskResult)
595
- {
596
- if (taskResult is System.Threading.Tasks.Task task)
597
- {
598
- await task;
599
-
600
- // 检查是否是 Task<T>
601
- if (task.GetType().IsGenericType)
602
- {
603
- var resultProperty = task.GetType().GetProperty("Result");
604
- if (resultProperty != null)
605
- {
606
- return resultProperty.GetValue(task);
607
- }
608
- }
609
-
610
- return null; // Task 类型无返回值
611
- }
612
-
613
- return taskResult; // 同步方法的直接返回值
614
- }
615
-
616
- /// <summary>
617
- /// 简化的类型转换方法
618
- /// </summary>
619
- /// <typeparam name="T">目标类型</typeparam>
620
- /// <param name="value">要转换的值</param>
621
- /// <returns>转换后的值</returns>
622
- private static T ConvertToType<T>(object value)
623
- {
624
- if (value == null)
625
- return default(T);
626
-
627
- if (value is T directMatch)
628
- return directMatch;
629
-
630
- try
631
- {
632
- return (T)value;
633
- }
634
- catch
635
- {
636
- return default(T);
637
- }
638
- }
639
- }
640
- }
@@ -1,3 +0,0 @@
1
- fileFormatVersion: 2
2
- guid: 3bc624b04151420c8e71a0a7d1310aa6
3
- timeCreated: 1744785847