Init.cs 1.3 KB

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