Init.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using System;
  2. using UnityEngine;
  3. namespace Model
  4. {
  5. public class Init : MonoBehaviour
  6. {
  7. private async void Start()
  8. {
  9. try
  10. {
  11. if (Application.unityVersion != "2017.1.0p5")
  12. {
  13. Log.Warning($"当前版本:{Application.unityVersion}, 最好使用运行指南推荐版本!");
  14. }
  15. DontDestroyOnLoad(gameObject);
  16. Game.EventSystem.Add(DLLType.Model, typeof(Init).Assembly);
  17. Game.Scene.AddComponent<GlobalConfigComponent>();
  18. Game.Scene.AddComponent<NetOuterComponent>();
  19. Game.Scene.AddComponent<ResourcesComponent>();
  20. Game.Scene.AddComponent<BehaviorTreeComponent>();
  21. Game.Scene.AddComponent<PlayerComponent>();
  22. Game.Scene.AddComponent<UnitComponent>();
  23. Game.Scene.AddComponent<ClientFrameComponent>();
  24. Game.Scene.AddComponent<UIComponent>();
  25. // 下载ab包
  26. await BundleHelper.DownloadBundle();
  27. Game.Hotfix.LoadHotfixAssembly();
  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<MessageDispatherComponent>();
  34. Game.Hotfix.GotoHotfix();
  35. Game.EventSystem.Run(EventIdType.TestHotfixSubscribMonoEvent, "TestHotfixSubscribMonoEvent");
  36. }
  37. catch (Exception e)
  38. {
  39. Log.Error(e.ToString());
  40. }
  41. }
  42. private void Update()
  43. {
  44. Game.Hotfix.Update?.Invoke();
  45. Game.EventSystem.Update();
  46. }
  47. private void LateUpdate()
  48. {
  49. Game.Hotfix.LateUpdate?.Invoke();
  50. Game.EventSystem.LateUpdate();
  51. }
  52. private void OnApplicationQuit()
  53. {
  54. Game.Hotfix.OnApplicationQuit?.Invoke();
  55. Game.Close();
  56. }
  57. }
  58. }