HotUpdateCodeLoader.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. LogServerHelperHttp.SendNodeLog((int)LogNode.StartLoadGameDll);
  22. Debug.LogFormat("ILRuntimeLauncher StartLoadAssemblyHotfix");
  23. yield return new WaitForSeconds(0.1f);
  24. var dllPath = "Assets/Res/Code/Game.HotUpdate.dll.bytes";
  25. var asset = GFGAsset.Load<TextAsset>(dllPath);
  26. byte[] assBytes = asset.bytes;
  27. //Debug.LogFormat("assBytes != null {0}", assBytes != null);
  28. //Debug.LogFormat("assBytes.Length {0}", assBytes.Length);
  29. //yield return new WaitForSeconds(0.1f);
  30. var pdbPath = "Assets/Res/Code/Game.HotUpdate.pdb.bytes";
  31. asset = GFGAsset.Load<TextAsset>(pdbPath);
  32. byte[] pdbBytes = asset.bytes;
  33. //Debug.LogFormat("pdbBytes != null {0}", pdbBytes != null);
  34. //Debug.LogFormat("pdbBytes.Length {0}", pdbBytes.Length);
  35. if (LauncherConfig.ILRuntimeMode)
  36. {
  37. Debug.LogFormat("Assembly Mode ILRuntime");
  38. ILRuntimeLauncher.Instance.LoadAssembly(assBytes, pdbBytes);
  39. }
  40. else
  41. {
  42. Debug.LogFormat("Assembly Mode Jit");
  43. StartCoroutine(LoadAssemblyJustInTime(assBytes, pdbBytes));
  44. }
  45. GFGAsset.Release(dllPath);
  46. GFGAsset.Release(pdbPath);
  47. }
  48. IEnumerator LoadAssemblyJustInTime(byte[] assBytes, byte[] pdbBytes)
  49. {
  50. //yield return new WaitForSeconds(0.1f);
  51. //mono模式
  52. var assembly = Assembly.Load(assBytes, pdbBytes);
  53. this.allTypes = assembly.GetTypes();
  54. //Debug.LogFormat("assembly != null {0}", assembly != null);
  55. //yield return new WaitForSeconds(0.1f);
  56. System.Type type = assembly.GetType("GFGGame.HotUpdate.HotUpdateEntry");
  57. //Debug.LogFormat("type != null {0}", type != null);
  58. //yield return new WaitForSeconds(0.1f);
  59. type.GetMethod("Start").Invoke(type, null);
  60. yield break;
  61. }
  62. }
  63. }