Init.cs 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. TimeInfo.Instance.Update();
  29. FiberManager.Instance.Update();
  30. }
  31. private void LateUpdate()
  32. {
  33. FiberManager.Instance.LateUpdate();
  34. }
  35. private void OnApplicationQuit()
  36. {
  37. World.Instance.Dispose();
  38. }
  39. }
  40. }