Init.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using System;
  2. using System.Threading;
  3. using UnityEngine;
  4. namespace ETModel
  5. {
  6. public class Init : MonoBehaviour
  7. {
  8. private void Start()
  9. {
  10. this.StartAsync().Coroutine();
  11. }
  12. private async ETVoid StartAsync()
  13. {
  14. try
  15. {
  16. SynchronizationContext.SetSynchronizationContext(OneThreadSynchronizationContext.Instance);
  17. DontDestroyOnLoad(gameObject);
  18. Game.EventSystem.Add(DLLType.Model, typeof(Init).Assembly);
  19. Game.Scene.AddComponent<TimerComponent>();
  20. Game.Scene.AddComponent<GlobalConfigComponent>();
  21. Game.Scene.AddComponent<NetOuterComponent>();
  22. Game.Scene.AddComponent<ResourcesComponent>();
  23. Game.Scene.AddComponent<PlayerComponent>();
  24. Game.Scene.AddComponent<UnitComponent>();
  25. Game.Scene.AddComponent<UIComponent>();
  26. // 下载ab包
  27. await BundleHelper.DownloadBundle();
  28. Game.Hotfix.LoadHotfixAssembly();
  29. // 加载配置
  30. Game.Scene.GetComponent<ResourcesComponent>().LoadBundle("config.unity3d");
  31. Game.Scene.AddComponent<ConfigComponent>();
  32. Game.Scene.GetComponent<ResourcesComponent>().UnloadBundle("config.unity3d");
  33. Game.Scene.AddComponent<OpcodeTypeComponent>();
  34. Game.Scene.AddComponent<MessageDispatcherComponent>();
  35. Game.Hotfix.GotoHotfix();
  36. Game.EventSystem.Run(EventIdType.TestHotfixSubscribMonoEvent, "TestHotfixSubscribMonoEvent");
  37. }
  38. catch (Exception e)
  39. {
  40. Log.Error(e);
  41. }
  42. }
  43. private void Update()
  44. {
  45. OneThreadSynchronizationContext.Instance.Update();
  46. Game.Hotfix.Update?.Invoke();
  47. Game.EventSystem.Update();
  48. }
  49. private void LateUpdate()
  50. {
  51. Game.Hotfix.LateUpdate?.Invoke();
  52. Game.EventSystem.LateUpdate();
  53. }
  54. private void OnApplicationQuit()
  55. {
  56. Game.Hotfix.OnApplicationQuit?.Invoke();
  57. Game.Close();
  58. }
  59. }
  60. }