HotUpdateCodeLoader.cs 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using System;
  2. using System.Collections.Generic;
  3. using GFGGame.HotUpdate;
  4. using GFGGame.Launcher;
  5. using UnityEngine;
  6. namespace GFGGame
  7. {
  8. public class HotUpdateCodeLoaderHotUpdate : SingletonMonoBase<HotUpdateCodeLoaderHotUpdate>
  9. {
  10. public Type[] GetAllTypes()
  11. {
  12. var result = new List<Type>();
  13. foreach (string typeName in PreGeneratedTypes.AllTypeNames)
  14. {
  15. // 方法1:先尝试简单获取
  16. Type type = Type.GetType(typeName);
  17. // 方法2:如果失败,尝试从所有已加载程序集查找
  18. if (type == null)
  19. {
  20. foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
  21. {
  22. type = assembly.GetType(typeName);
  23. if (type != null) break;
  24. }
  25. }
  26. // 方法3:处理泛型类型(如`Namespace.Type`1, Assembly)
  27. if (type == null && typeName.Contains("`"))
  28. {
  29. try
  30. {
  31. int index = typeName.IndexOf(',');
  32. string shortName = index > 0 ? typeName.Substring(0, index) : typeName;
  33. type = Type.GetType(shortName);
  34. }
  35. catch
  36. {
  37. }
  38. }
  39. if (type != null)
  40. {
  41. result.Add(type);
  42. }
  43. else
  44. {
  45. Debug.LogWarning($"Type not found: {typeName}");
  46. }
  47. }
  48. return result.ToArray();
  49. }
  50. }
  51. }