Init.cs 2.1 KB

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