Init.cs 983 B

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