12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- using System;
- using CommandLine;
- using UnityEngine;
- namespace ET
- {
- public class Init: MonoBehaviour
- {
- private void Awake()
- {
- #if UNITY_EDITOR
- var globalConfig = Resources.Load<GlobalConfig>("GlobalConfig");
- if (globalConfig.PlayMode != YooAsset.YooAssets.EPlayMode.EditorSimulateMode)
- {
- var window = UnityEditor.EditorWindow.GetWindow(typeof(UnityEditor.EditorWindow), true, "Game");
- if(window != null)
- {
- window.ShowNotification(new GUIContent($"PlayMode is {globalConfig.PlayMode}"), 5);
- }
- return;
- }
- #endif
- DontDestroyOnLoad(gameObject);
- //登陆过程限定帧率为30fps
- Application.targetFrameRate = (int)FPS.Login;
- AppDomain.CurrentDomain.UnhandledException += (sender, e) =>
- {
- Log.Error(e.ExceptionObject.ToString());
- };
-
- Game.AddSingleton<MainThreadSynchronizationContext>();
- // 命令行参数
- string[] args = "".Split(" ");
- Parser.Default.ParseArguments<Options>(args)
- .WithNotParsed(error => throw new Exception($"命令行格式错误! {error}"))
- .WithParsed(Game.AddSingleton);
- Game.AddSingleton<TimeInfo>();
- Game.AddSingleton<Logger>().ILog = new UnityLogger();
- Game.AddSingleton<ObjectPool>();
- Game.AddSingleton<IdGenerater>();
- Game.AddSingleton<EventSystem>();
- Game.AddSingleton<TimerComponent>();
- Game.AddSingleton<CoroutineLockComponent>();
-
- ETTask.ExceptionHandler += Log.Error;
- Game.AddSingleton<CodeLoader>().Start();
- }
- private void Update()
- {
- Game.Update((int)(Time.deltaTime * 1000));
- }
- private void LateUpdate()
- {
- Game.LateUpdate();
- Game.FrameFinishUpdate();
- }
- private void OnApplicationQuit()
- {
- Game.Close();
- }
- }
- }
|