Init.cs 1.4 KB

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