Init.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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(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. // 加载配置
  29. Game.Scene.GetComponent<ResourcesComponent>().LoadBundle("config.unity3d");
  30. Game.Scene.AddComponent<ConfigComponent>();
  31. Game.Scene.GetComponent<ResourcesComponent>().UnloadBundle("config.unity3d");
  32. Game.Scene.AddComponent<OpcodeTypeComponent>();
  33. Game.Scene.AddComponent<MessageDispatcherComponent>();
  34. }
  35. catch (Exception e)
  36. {
  37. Log.Error(e);
  38. }
  39. }
  40. private void Update()
  41. {
  42. OneThreadSynchronizationContext.Instance.Update();
  43. Game.EventSystem.Update();
  44. }
  45. private void LateUpdate()
  46. {
  47. Game.EventSystem.LateUpdate();
  48. }
  49. private void OnApplicationQuit()
  50. {
  51. Game.Close();
  52. }
  53. }
  54. }