using Cysharp.Threading.Tasks; using UnityEngine; namespace ZC { public class ZCGame { private GameObject _self; private bool isDisposed; private bool isPause; private float gameTime; public static ZCGame _zcGame; public static GameObject Self => _zcGame._self; public static float GameTime => _zcGame.gameTime; public ZCGame(GameObject self) { _zcGame = this; this._self = self; this.UpdateGame().Forget(); } async UniTask UpdateGame() { this.Init(); while (!this.isDisposed) { await UniTask.Yield(); if (!Application.isPlaying) // 关闭应用的时候自动调用 { this.isDisposed = true; this.Dispose(); break; } if (this.isPause) continue; this.gameTime += Time.fixedTime; this.Update(this.gameTime); this.LateUpdate(this.gameTime); } } public void Pause() { this.isPause = true; } public void Resume() { this.isPause = false; } void Init() { UniTask.Void(async () => { await ResourcesLocalComponent.Instance.LoadSceneAsync(AssetsConst.Assets_DemoGame_GameRes_Scene_Game_unity); var loadAssetAsync = await ResourcesLocalComponent.Instance.LoadAssetAndInsAsync(AssetsConst.Assets_DemoGame_GameRes_Entity_Cube_prefab); Debug.Log("加载的是:" + loadAssetAsync); }); } void Update(float time) { } void LateUpdate(float time) { } void Dispose() { Debug.Log("关闭应用了"); } } }