Init.cs 1007 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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(World.Instance.AddSingleton);
  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. }