HotUpdateCodeLoader.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. //ET.Log.Debug("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. var pdbPath = "Assets/Res/Code/Game.HotUpdate.pdb.bytes";
  28. asset = GFGAsset.Load<TextAsset>(pdbPath);
  29. byte[] pdbBytes = asset.bytes;
  30. if (LauncherConfig.ILRuntimeMode)
  31. {
  32. }
  33. else
  34. {
  35. StartCoroutine(LoadAssemblyJustInTime(assBytes, pdbBytes));
  36. }
  37. GFGAsset.Release(dllPath);
  38. GFGAsset.Release(pdbPath);
  39. }
  40. IEnumerator LoadAssemblyJustInTime(byte[] assBytes, byte[] pdbBytes)
  41. {
  42. //mono模式
  43. var assembly = Assembly.Load(assBytes, pdbBytes);
  44. this.allTypes = assembly.GetTypes();
  45. System.Type type = assembly.GetType("GFGGame.HotUpdate.HotUpdateEntry");
  46. type.GetMethod("Start").Invoke(type, null);
  47. yield break;
  48. }
  49. }
  50. }