Init.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using System;
  2. using CommandLine;
  3. using ET.Client;
  4. using UnityEngine;
  5. using UnityEngine.AddressableAssets;
  6. using UnityEngine.AddressableAssets.ResourceLocators;
  7. namespace ET
  8. {
  9. public class Init: MonoBehaviour
  10. {
  11. private void Start()
  12. {
  13. this.StartAsync().Coroutine();
  14. }
  15. private async ETTask StartAsync()
  16. {
  17. DontDestroyOnLoad(gameObject);
  18. AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
  19. {
  20. Log.Error(e.ExceptionObject.ToString());
  21. };
  22. // 命令行参数
  23. string[] args = "".Split(" ");
  24. Parser.Default.ParseArguments<Options>(args)
  25. .WithNotParsed(error => throw new Exception($"命令行格式错误! {error}"))
  26. .WithParsed((o)=>World.Instance.AddSingleton(o));
  27. Options.Instance.StartConfig = $"StartConfig/Localhost";
  28. World.Instance.AddSingleton<Logger>().Log = new UnityLogger();
  29. ETTask.ExceptionHandler += Log.Error;
  30. World.Instance.AddSingleton<TimeInfo>();
  31. World.Instance.AddSingleton<FiberManager>();
  32. World.Instance.AddSingleton<ResourcesComponent>();
  33. await AssetsBundleHelper.InitializeAsync();
  34. await AssetsBundleHelper.LoadCodeAsync();
  35. await AssetsBundleHelper.LoadAotDllAsync();
  36. World.Instance.AddSingleton<CodeLoader>().Start();
  37. }
  38. private void Update()
  39. {
  40. TimeInfo.Instance.Update();
  41. FiberManager.Instance.Update();
  42. }
  43. private void LateUpdate()
  44. {
  45. FiberManager.Instance.LateUpdate();
  46. }
  47. private void OnApplicationQuit()
  48. {
  49. World.Instance.Dispose();
  50. }
  51. }
  52. }