Init.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 != "2017.4.3f1")
  15. {
  16. Log.Error($"新人请使用Unity2017.4.3f1,减少跑demo遇到的问题! 下载地址:\n https://download.unity3d.com/download_unity/21ae32b5a9cb/UnityDownloadAssistant-2017.4.3f1.exe");
  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<BehaviorTreeComponent>();
  25. Game.Scene.AddComponent<PlayerComponent>();
  26. Game.Scene.AddComponent<UnitComponent>();
  27. Game.Scene.AddComponent<ClientFrameComponent>();
  28. Game.Scene.AddComponent<UIComponent>();
  29. // 下载ab包
  30. await BundleHelper.DownloadBundle();
  31. Game.Hotfix.LoadHotfixAssembly();
  32. // 加载配置
  33. Game.Scene.GetComponent<ResourcesComponent>().LoadBundle("config.unity3d");
  34. Game.Scene.AddComponent<ConfigComponent>();
  35. Game.Scene.GetComponent<ResourcesComponent>().UnloadBundle("config.unity3d");
  36. Game.Scene.AddComponent<OpcodeTypeComponent>();
  37. Game.Scene.AddComponent<MessageDispatherComponent>();
  38. Game.Hotfix.GotoHotfix();
  39. Game.EventSystem.Run(EventIdType.TestHotfixSubscribMonoEvent, "TestHotfixSubscribMonoEvent");
  40. }
  41. catch (Exception e)
  42. {
  43. Log.Error(e);
  44. }
  45. }
  46. private void Update()
  47. {
  48. OneThreadSynchronizationContext.Instance.Update();
  49. Game.Hotfix.Update?.Invoke();
  50. Game.EventSystem.Update();
  51. }
  52. private void LateUpdate()
  53. {
  54. Game.Hotfix.LateUpdate?.Invoke();
  55. Game.EventSystem.LateUpdate();
  56. }
  57. private void OnApplicationQuit()
  58. {
  59. Game.Hotfix.OnApplicationQuit?.Invoke();
  60. Game.Close();
  61. }
  62. }
  63. }