using PhxhSDK; using PhxhSDK.AOT; using PhxhSDK.AOT.Aspect; using System; using System.Reflection; using UnityEngine; namespace Gameplay { public class Main : SingletonMono
{ private const string GAME_TYPE_NAME = "MyGame, GamePlay"; private BaseGame _game; private float _lastSecondUpdate; private float _lastTenthSecondUpdate; private float _lastTenSecondsUpdate; public bool isInited { get; private set; } private void _InitGame() { SDKManager.GetSingleton().InitEarly(); Type type = Type.GetType(GAME_TYPE_NAME); if (null == type) { Debug.LogError($"{GAME_TYPE_NAME} Type found"); return; } _game = Activator.CreateInstance(type) as BaseGame; if (_game == null) { DebugUtil.LogError("PhxhSDK.Main: no game instance created"); } SDKManager.GetSingleton().Init(); _game.Init(); _game.Start(); } private async void _InitAsync() { isInited = false; #if USE_YOO await YooAssetHelper.Init(); #endif isInited = true; _InitGame(); } private void Awake() { if (null == AspectManager.Instance) gameObject.AddComponent(); } private void Start() { #if DEBUG || DEVELOPMENT_BUILD Debug.unityLogger.logEnabled = true; #else Debug.unityLogger.logEnabled = false; #endif _lastSecondUpdate = Time.time; _lastTenthSecondUpdate = Time.time; _lastTenSecondsUpdate = Time.time; _InitAsync(); } private void Update() { if (!isInited) return; float currentTime = Time.time; // 每秒更新 if (currentTime - _lastSecondUpdate >= 1.0f) { _game.UpdatePerSecond(currentTime - _lastSecondUpdate); _lastSecondUpdate = currentTime; } // 每0.1秒更新 if (currentTime - _lastTenthSecondUpdate >= 0.1f) { _game.UpdatePerTenthSecond(currentTime - _lastTenthSecondUpdate); _lastTenthSecondUpdate = currentTime; } // 每10秒更新 if (currentTime - _lastTenSecondsUpdate >= 10.0f) { _game.UpdatePerTenSeconds(currentTime - _lastTenSecondsUpdate); _lastTenSecondsUpdate = currentTime; } _game.Update(Time.deltaTime); SDKManager.Instance.Update(); } private void OnApplicationPause(bool pauseStatus) { if (!isInited) return; _game.OnApplicationPause(pauseStatus); } private void OnDestroy() { _game.Release(); SDKManager.Instance.Release(); } } }