Init.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using System;
  2. using System.IO;
  3. using Base;
  4. using ILRuntime.CLR.Method;
  5. using UnityEngine;
  6. namespace Model
  7. {
  8. public class Init: MonoBehaviour
  9. {
  10. private ILRuntime.Runtime.Enviorment.AppDomain appDomain;
  11. private readonly object[] param0 = new object[0];
  12. private IMethod start;
  13. private IMethod update;
  14. private void Start()
  15. {
  16. appDomain = new ILRuntime.Runtime.Enviorment.AppDomain();
  17. Game.EntityEventManager.Register("Model", typeof (Game).Assembly);
  18. GameObject code = (GameObject)Resources.Load("Code");
  19. byte[] assBytes = code.Get<TextAsset>("Hotfix.dll").bytes;
  20. byte[] mdbBytes = code.Get<TextAsset>("Hotfix.pdb").bytes;
  21. using (MemoryStream fs = new MemoryStream(assBytes))
  22. using (MemoryStream p = new MemoryStream(mdbBytes))
  23. {
  24. appDomain.LoadAssembly(fs, p, new Mono.Cecil.Pdb.PdbReaderProvider());
  25. }
  26. appDomain.RegisterCrossBindingAdaptor(new IAsyncStateMachineClassInheritanceAdaptor());
  27. this.start = appDomain.LoadedTypes["Hotfix.Init"].GetMethod("Start", 0);
  28. this.update = appDomain.LoadedTypes["Hotfix.Init"].GetMethod("Update", 0);
  29. appDomain.Invoke(this.start, null, param0);
  30. }
  31. private void Update()
  32. {
  33. try
  34. {
  35. appDomain.Invoke(this.update, null, param0);
  36. Game.EntityEventManager.Update();
  37. }
  38. catch (Exception e)
  39. {
  40. Log.Error(e.ToString());
  41. }
  42. }
  43. private void OnApplicationQuit()
  44. {
  45. Game.CloseScene();
  46. }
  47. }
  48. }