Init.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using System;
  2. using System.Threading;
  3. using CommandLine;
  4. using Sirenix.OdinInspector;
  5. using UnityEngine;
  6. using YooAsset;
  7. namespace ET
  8. {
  9. public class Init: MonoBehaviour
  10. {
  11. private void Awake()
  12. {
  13. #if UNITY_STANDALONE_WIN
  14. Screen.SetResolution(540, 960, false);
  15. #endif
  16. #if UNITY_EDITOR
  17. //Editor模式下去掉debug浮窗插件
  18. var debugObj = GameObject.Find("IngameDebugConsole");
  19. if (debugObj != null)
  20. {
  21. GameObject.Destroy(debugObj);
  22. }
  23. #endif
  24. DontDestroyOnLoad(gameObject);
  25. //登陆过程限定帧率为30fps
  26. Application.targetFrameRate = (int)FPS.Login;
  27. AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
  28. {
  29. Log.Error(e.ExceptionObject.ToString());
  30. };
  31. Game.AddSingleton<MainThreadSynchronizationContext>();
  32. // 命令行参数
  33. string[] args = "".Split(" ");
  34. Parser.Default.ParseArguments<Options>(args)
  35. .WithNotParsed(error => throw new Exception($"命令行格式错误! {error}"))
  36. .WithParsed(Game.AddSingleton);
  37. Game.AddSingleton<TimeInfo>();
  38. Game.AddSingleton<Logger>().ILog = new UnityLogger();
  39. Game.AddSingleton<ObjectPool>();
  40. Game.AddSingleton<IdGenerater>();
  41. Game.AddSingleton<EventSystem>();
  42. Game.AddSingleton<TimerComponent>();
  43. Game.AddSingleton<CoroutineLockComponent>();
  44. ETTask.ExceptionHandler += Log.Error;
  45. Game.AddSingleton<CodeLoader>().Start();
  46. }
  47. private void Update()
  48. {
  49. Game.Update();
  50. }
  51. private void LateUpdate()
  52. {
  53. Game.LateUpdate();
  54. Game.FrameFinishUpdate();
  55. }
  56. private void OnApplicationQuit()
  57. {
  58. Game.Close();
  59. }
  60. }
  61. }