Init.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. DontDestroyOnLoad(gameObject);
  14. #if UNITY_EDITOR
  15. //Editor模式下去掉debug浮窗插件
  16. var debugObj = GameObject.Find("IngameDebugConsole");
  17. if(debugObj != null)
  18. {
  19. GameObject.Destroy(debugObj);
  20. }
  21. #endif
  22. //登陆过程限定帧率为30fps
  23. Application.targetFrameRate = (int)FPS.Login;
  24. AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
  25. {
  26. Log.Error(e.ExceptionObject.ToString());
  27. };
  28. Game.AddSingleton<MainThreadSynchronizationContext>();
  29. // 命令行参数
  30. string[] args = "".Split(" ");
  31. Parser.Default.ParseArguments<Options>(args)
  32. .WithNotParsed(error => throw new Exception($"命令行格式错误! {error}"))
  33. .WithParsed(Game.AddSingleton);
  34. Game.AddSingleton<TimeInfo>();
  35. Game.AddSingleton<Logger>().ILog = new UnityLogger();
  36. Game.AddSingleton<ObjectPool>();
  37. Game.AddSingleton<IdGenerater>();
  38. Game.AddSingleton<EventSystem>();
  39. Game.AddSingleton<TimerComponent>();
  40. Game.AddSingleton<CoroutineLockComponent>();
  41. ETTask.ExceptionHandler += Log.Error;
  42. Game.AddSingleton<CodeLoader>().Start();
  43. }
  44. private void Update()
  45. {
  46. Game.Update();
  47. }
  48. private void LateUpdate()
  49. {
  50. Game.LateUpdate();
  51. Game.FrameFinishUpdate();
  52. }
  53. private void OnApplicationQuit()
  54. {
  55. Game.Close();
  56. }
  57. }
  58. }