Init.cs 1.8 KB

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