Init.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. Log.Debug($"111111111111111111111111111111111111111");
  38. await Game.Scene.GetComponent<TimerComponent>().WaitAsync(1000);
  39. Log.Debug($"111111111111111111111111111111111111112");
  40. Game.EventSystem.Run(EventIdType.TestHotfixSubscribMonoEvent, "TestHotfixSubscribMonoEvent");
  41. }
  42. catch (Exception e)
  43. {
  44. Log.Error(e);
  45. }
  46. }
  47. private void Update()
  48. {
  49. OneThreadSynchronizationContext.Instance.Update();
  50. Game.Hotfix.Update?.Invoke();
  51. Game.EventSystem.Update();
  52. }
  53. private void LateUpdate()
  54. {
  55. Game.Hotfix.LateUpdate?.Invoke();
  56. Game.EventSystem.LateUpdate();
  57. }
  58. private void OnApplicationQuit()
  59. {
  60. Game.Hotfix.OnApplicationQuit?.Invoke();
  61. Game.Close();
  62. }
  63. }
  64. }