Init.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. Game.AddSingleton<MainThreadSynchronizationContext>();
  17. // 命令行参数
  18. string[] args = "".Split(" ");
  19. Parser.Default.ParseArguments<Options>(args)
  20. .WithNotParsed(error => throw new Exception($"命令行格式错误! {error}"))
  21. .WithParsed(Game.AddSingleton);
  22. Options.Instance.StartConfig = "StartConfig/LockStep";
  23. Game.AddSingleton<TimeInfo>();
  24. Game.AddSingleton<Logger>().ILog = new UnityLogger();
  25. Game.AddSingleton<ObjectPool>();
  26. Game.AddSingleton<IdGenerater>();
  27. Game.AddSingleton<EventSystem>();
  28. Game.AddSingleton<TimerComponent>();
  29. Game.AddSingleton<CoroutineLockComponent>();
  30. ETTask.ExceptionHandler += Log.Error;
  31. Game.AddSingleton<CodeLoader>().Start();
  32. }
  33. private void Update()
  34. {
  35. Game.Update();
  36. }
  37. private void LateUpdate()
  38. {
  39. Game.LateUpdate();
  40. Game.FrameFinishUpdate();
  41. }
  42. private void OnApplicationQuit()
  43. {
  44. Game.Close();
  45. }
  46. }
  47. }