Init.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. // 加载配置
  28. Game.Scene.GetComponent<ResourcesComponent>().LoadBundle("config.unity3d");
  29. Game.Scene.AddComponent<ConfigComponent>();
  30. Game.Scene.GetComponent<ResourcesComponent>().UnloadBundle("config.unity3d");
  31. Game.Scene.AddComponent<OpcodeTypeComponent>();
  32. Game.Scene.AddComponent<MessageDispatherComponent>();
  33. Game.Hotfix.GotoHotfix();
  34. Game.EventSystem.Run(EventIdType.TestHotfixSubscribMonoEvent, "TestHotfixSubscribMonoEvent");
  35. }
  36. catch (Exception e)
  37. {
  38. Log.Error(e.ToString());
  39. }
  40. }
  41. private void Update()
  42. {
  43. Game.Hotfix.Update?.Invoke();
  44. Game.EventSystem.Update();
  45. }
  46. private void LateUpdate()
  47. {
  48. Game.Hotfix.LateUpdate?.Invoke();
  49. Game.EventSystem.LateUpdate();
  50. }
  51. private void OnApplicationQuit()
  52. {
  53. Game.Hotfix.OnApplicationQuit?.Invoke();
  54. Game.Close();
  55. }
  56. }
  57. }