Init.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. using System;
  2. using ETModel;
  3. namespace ETHotfix
  4. {
  5. public static class Init
  6. {
  7. public static void Start()
  8. {
  9. #if ILRuntime
  10. if (!Define.IsILRuntime)
  11. {
  12. Log.Error("mono层是mono模式, 但是Hotfix层是ILRuntime模式");
  13. }
  14. #else
  15. if (Define.IsILRuntime)
  16. {
  17. Log.Error("mono层是ILRuntime模式, Hotfix层是mono模式");
  18. }
  19. #endif
  20. try
  21. {
  22. // 注册热更层回调
  23. ETModel.Game.Hotfix.Update = () => { Update(); };
  24. ETModel.Game.Hotfix.LateUpdate = () => { LateUpdate(); };
  25. ETModel.Game.Hotfix.OnApplicationQuit = () => { OnApplicationQuit(); };
  26. Game.Scene.AddComponent<UIComponent>();
  27. Game.Scene.AddComponent<OpcodeTypeComponent>();
  28. Game.Scene.AddComponent<MessageDispatcherComponent>();
  29. // 加载热更配置
  30. ETModel.Game.Scene.GetComponent<ResourcesComponent>().LoadBundle("config.unity3d");
  31. Game.Scene.AddComponent<ConfigComponent>();
  32. ETModel.Game.Scene.GetComponent<ResourcesComponent>().UnloadBundle("config.unity3d");
  33. UnitConfig unitConfig = (UnitConfig)Game.Scene.GetComponent<ConfigComponent>().Get(typeof(UnitConfig), 1001);
  34. Log.Debug($"config {JsonHelper.ToJson(unitConfig)}");
  35. Game.EventSystem.Run(EventIdType.InitSceneStart);
  36. }
  37. catch (Exception e)
  38. {
  39. Log.Error(e);
  40. }
  41. }
  42. public static void Update()
  43. {
  44. try
  45. {
  46. Game.EventSystem.Update();
  47. }
  48. catch (Exception e)
  49. {
  50. Log.Error(e);
  51. }
  52. }
  53. public static void LateUpdate()
  54. {
  55. try
  56. {
  57. Game.EventSystem.LateUpdate();
  58. }
  59. catch (Exception e)
  60. {
  61. Log.Error(e);
  62. }
  63. }
  64. public static void OnApplicationQuit()
  65. {
  66. Game.Close();
  67. }
  68. }
  69. }