Init.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using System;
  2. using CommandLine;
  3. namespace ET
  4. {
  5. public static class Init
  6. {
  7. public static void Start()
  8. {
  9. try
  10. {
  11. AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
  12. {
  13. Log.Error(e.ExceptionObject.ToString());
  14. };
  15. // 异步方法全部会回掉到主线程
  16. Game.AddSingleton<MainThreadSynchronizationContext>();
  17. // 命令行参数
  18. Parser.Default.ParseArguments<Options>(System.Environment.GetCommandLineArgs())
  19. .WithNotParsed(error => throw new Exception($"命令行格式错误! {error}"))
  20. .WithParsed(Game.AddSingleton);
  21. Game.AddSingleton<TimeInfo>();
  22. Game.AddSingleton<Logger>().ILog = new NLogger(Options.Instance.AppType.ToString(), Options.Instance.Process, "../Config/NLog/NLog.config");
  23. Game.AddSingleton<ObjectPool>();
  24. Game.AddSingleton<IdGenerater>();
  25. Game.AddSingleton<EventSystem>();
  26. Game.AddSingleton<TimerComponent>();
  27. Game.AddSingleton<CoroutineLockComponent>();
  28. ETTask.ExceptionHandler += Log.Error;
  29. Log.Console($"{Parser.Default.FormatCommandLine(Options.Instance)}");
  30. Game.AddSingleton<CodeLoader>().Start();
  31. }
  32. catch (Exception e)
  33. {
  34. Log.Error(e);
  35. }
  36. }
  37. public static void Update(int timeMS)
  38. {
  39. Game.Update(timeMS);
  40. }
  41. public static void LateUpdate()
  42. {
  43. Game.LateUpdate();
  44. }
  45. public static void FrameFinishUpdate()
  46. {
  47. Game.FrameFinishUpdate();
  48. }
  49. }
  50. }