Init.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 async void Start()
  11. {
  12. try
  13. {
  14. if (!Application.unityVersion.StartsWith("2017.4"))
  15. {
  16. Log.Error($"新人请使用Unity2017.4版本,减少跑demo遇到的问题! 下载地址:\n https://unity3d.com/cn/unity/qa/lts-releases?_ga=2.227583646.282345691.1536717255-1119432033.1499739574");
  17. }
  18. SynchronizationContext.SetSynchronizationContext(OneThreadSynchronizationContext.Instance);
  19. DontDestroyOnLoad(gameObject);
  20. Game.EventSystem.Add(DLLType.Model, typeof(Init).Assembly);
  21. Game.Scene.AddComponent<GlobalConfigComponent>();
  22. Game.Scene.AddComponent<NetOuterComponent>();
  23. Game.Scene.AddComponent<ResourcesComponent>();
  24. Game.Scene.AddComponent<PlayerComponent>();
  25. Game.Scene.AddComponent<UnitComponent>();
  26. Game.Scene.AddComponent<UIComponent>();
  27. // 下载ab包
  28. await BundleHelper.DownloadBundle();
  29. Game.Hotfix.LoadHotfixAssembly();
  30. // 加载配置
  31. Game.Scene.GetComponent<ResourcesComponent>().LoadBundle("config.unity3d");
  32. Game.Scene.AddComponent<ConfigComponent>();
  33. Game.Scene.GetComponent<ResourcesComponent>().UnloadBundle("config.unity3d");
  34. Game.Scene.AddComponent<OpcodeTypeComponent>();
  35. Game.Scene.AddComponent<MessageDispatherComponent>();
  36. Game.Hotfix.GotoHotfix();
  37. Game.EventSystem.Run(EventIdType.TestHotfixSubscribMonoEvent, "TestHotfixSubscribMonoEvent");
  38. }
  39. catch (Exception e)
  40. {
  41. Log.Error(e);
  42. }
  43. }
  44. private void Update()
  45. {
  46. OneThreadSynchronizationContext.Instance.Update();
  47. Game.Hotfix.Update?.Invoke();
  48. Game.EventSystem.Update();
  49. }
  50. private void LateUpdate()
  51. {
  52. Game.Hotfix.LateUpdate?.Invoke();
  53. Game.EventSystem.LateUpdate();
  54. }
  55. private void OnApplicationQuit()
  56. {
  57. Game.Hotfix.OnApplicationQuit?.Invoke();
  58. Game.Close();
  59. }
  60. }
  61. }