Init.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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<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. OneThreadSynchronizationContext.Instance.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. }