Init.cs 1019 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System;
  2. using System.Threading;
  3. using CommandLine;
  4. using UnityEngine;
  5. namespace ET
  6. {
  7. public class Init: MonoBehaviour
  8. {
  9. private void Start()
  10. {
  11. DontDestroyOnLoad(gameObject);
  12. AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
  13. {
  14. Log.Error(e.ExceptionObject.ToString());
  15. };
  16. // 命令行参数
  17. string[] args = "".Split(" ");
  18. Parser.Default.ParseArguments<Options>(args)
  19. .WithNotParsed(error => throw new Exception($"命令行格式错误! {error}"))
  20. .WithParsed((o)=>World.Instance.AddSingleton(o));
  21. Options.Instance.StartConfig = $"StartConfig/Localhost";
  22. World.Instance.AddSingleton<Logger>().ILog = new UnityLogger();
  23. ETTask.ExceptionHandler += Log.Error;
  24. World.Instance.AddSingleton<CodeLoader>().Start();
  25. }
  26. private void Update()
  27. {
  28. FiberManager.Instance.Update();
  29. }
  30. private void LateUpdate()
  31. {
  32. FiberManager.Instance.LateUpdate();
  33. }
  34. private void OnApplicationQuit()
  35. {
  36. World.Instance.Dispose();
  37. }
  38. }
  39. }