Init.cs 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using System;
  2. using System.Threading;
  3. using UnityEngine;
  4. namespace ETModel
  5. {
  6. public class Init : MonoBehaviour
  7. {
  8. private readonly OneThreadSynchronizationContext contex = new OneThreadSynchronizationContext();
  9. private async void Start()
  10. {
  11. try
  12. {
  13. if (Application.unityVersion != "2017.1.0p5")
  14. {
  15. Log.Warning($"当前版本:{Application.unityVersion}, 最好使用运行指南推荐版本!");
  16. }
  17. SynchronizationContext.SetSynchronizationContext(this.contex);
  18. DontDestroyOnLoad(gameObject);
  19. Game.EventSystem.Add(DLLType.Model, typeof(Init).Assembly);
  20. Game.Scene.AddComponent<GlobalConfigComponent>();
  21. Game.Scene.AddComponent<NetOuterComponent>();
  22. Game.Scene.AddComponent<ResourcesComponent>();
  23. Game.Scene.AddComponent<BehaviorTreeComponent>();
  24. Game.Scene.AddComponent<PlayerComponent>();
  25. Game.Scene.AddComponent<UnitComponent>();
  26. Game.Scene.AddComponent<ClientFrameComponent>();
  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<MessageDispatherComponent>();
  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. this.contex.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. }