HotUpdateCodeLoader.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using System;
  2. using System.Collections;
  3. using System.Reflection;
  4. using UnityEngine;
  5. using GFGGame.Launcher;
  6. namespace GFGGame
  7. {
  8. public class HotUpdateCodeLoader : SingletonMonoBase<HotUpdateCodeLoader>
  9. {
  10. public Type[] allTypes;
  11. public Type[] GetTypes()
  12. {
  13. return this.allTypes;
  14. }
  15. public void StartLoad()
  16. {
  17. StartCoroutine(StartLoadAssemblyHotfix());
  18. }
  19. IEnumerator StartLoadAssemblyHotfix()
  20. {
  21. Debug.LogFormat("ILRuntimeLauncher StartLoadAssemblyHotfix");
  22. yield return new WaitForSeconds(0.1f);
  23. var dllPath = "Assets/Res/Code/Game.HotUpdate.dll.bytes";
  24. var asset = GFGAsset.Load<TextAsset>(dllPath);
  25. byte[] assBytes = asset.bytes;
  26. //Debug.LogFormat("assBytes != null {0}", assBytes != null);
  27. //Debug.LogFormat("assBytes.Length {0}", assBytes.Length);
  28. //yield return new WaitForSeconds(0.1f);
  29. var pdbPath = "Assets/Res/Code/Game.HotUpdate.pdb.bytes";
  30. asset = GFGAsset.Load<TextAsset>(pdbPath);
  31. byte[] pdbBytes = asset.bytes;
  32. //Debug.LogFormat("pdbBytes != null {0}", pdbBytes != null);
  33. //Debug.LogFormat("pdbBytes.Length {0}", pdbBytes.Length);
  34. if (LauncherConfig.ILRuntimeMode)
  35. {
  36. Debug.LogFormat("Assembly Mode ILRuntime");
  37. ILRuntimeLauncher.Instance.LoadAssembly(assBytes, pdbBytes);
  38. }
  39. else
  40. {
  41. Debug.LogFormat("Assembly Mode Jit");
  42. StartCoroutine(LoadAssemblyJustInTime(assBytes, pdbBytes));
  43. }
  44. GFGAsset.Release(dllPath);
  45. GFGAsset.Release(pdbPath);
  46. }
  47. IEnumerator LoadAssemblyJustInTime(byte[] assBytes, byte[] pdbBytes)
  48. {
  49. //yield return new WaitForSeconds(0.1f);
  50. //mono模式
  51. var assembly = Assembly.Load(assBytes, pdbBytes);
  52. this.allTypes = assembly.GetTypes();
  53. //Debug.LogFormat("assembly != null {0}", assembly != null);
  54. //yield return new WaitForSeconds(0.1f);
  55. System.Type type = assembly.GetType("GFGGame.HotUpdate.HotUpdateEntry");
  56. //Debug.LogFormat("type != null {0}", type != null);
  57. //yield return new WaitForSeconds(0.1f);
  58. type.GetMethod("Start").Invoke(type, null);
  59. yield break;
  60. }
  61. }
  62. }