Init.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. Game.Scene.ModelScene = ETModel.Game.Scene;
  12. // 注册热更层回调
  13. ETModel.Game.Hotfix.Update = () => { Update(); };
  14. ETModel.Game.Hotfix.LateUpdate = () => { LateUpdate(); };
  15. ETModel.Game.Hotfix.OnApplicationQuit = () => { OnApplicationQuit(); };
  16. Game.Scene.AddComponent<UIComponent>();
  17. Game.Scene.AddComponent<OpcodeTypeComponent>();
  18. Game.Scene.AddComponent<MessageDispatherComponent>();
  19. // 加载热更配置
  20. ETModel.Game.Scene.GetComponent<ResourcesComponent>().LoadBundle("config.unity3d");
  21. Game.Scene.AddComponent<ConfigComponent>();
  22. ETModel.Game.Scene.GetComponent<ResourcesComponent>().UnloadBundle("config.unity3d");
  23. UnitConfig unitConfig = (UnitConfig)Game.Scene.GetComponent<ConfigComponent>().Get(typeof(UnitConfig), 1001);
  24. Log.Debug($"config {JsonHelper.ToJson(unitConfig)}");
  25. Game.EventSystem.Run(EventIdType.InitSceneStart);
  26. }
  27. catch (Exception e)
  28. {
  29. Log.Error(e);
  30. }
  31. }
  32. public static void Update()
  33. {
  34. try
  35. {
  36. Game.EventSystem.Update();
  37. }
  38. catch (Exception e)
  39. {
  40. Log.Error(e);
  41. }
  42. }
  43. public static void LateUpdate()
  44. {
  45. try
  46. {
  47. Game.EventSystem.LateUpdate();
  48. }
  49. catch (Exception e)
  50. {
  51. Log.Error(e);
  52. }
  53. }
  54. public static void OnApplicationQuit()
  55. {
  56. Game.Close();
  57. }
  58. }
  59. }