Init.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. Game.AddSingleton<MainThreadSynchronizationContext>();
  16. // 命令行参数
  17. string[] args = "".Split(" ");
  18. Parser.Default.ParseArguments<Options>(args)
  19. .WithNotParsed(error => throw new Exception($"命令行格式错误! {error}"))
  20. .WithParsed(Game.AddSingleton);
  21. Game.AddSingleton<TimeInfo>();
  22. Game.AddSingleton<Logger>().ILog = new UnityLogger();
  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. //if (SerializeHelper.UseMemoryPack && !Define.EnableCodes)
  30. //{
  31. // Log.Error("MemoryPack must use ENABLE_CODES mode");
  32. // return;
  33. //}
  34. Game.AddSingleton<CodeLoader>().Start();
  35. }
  36. private void Update()
  37. {
  38. Game.Update();
  39. }
  40. private void LateUpdate()
  41. {
  42. Game.LateUpdate();
  43. Game.FrameFinishUpdate();
  44. }
  45. private void OnApplicationQuit()
  46. {
  47. Game.Close();
  48. }
  49. }
  50. }