HAARFTE/Assets/DemoGame/GameScript/Hotfix/ZCGame.cs

104 lines
2.9 KiB
C#

using Cysharp.Threading.Tasks;
using UnityEngine;
namespace ZC
{
public class ZCGame
{
private GameObject _self;
private Transform _objectPool;
private bool isDisposed;
private bool isPause;
private float gameTime;
public static ZCGame _zcGame;
private ObjectManager _objectManager;
private UIManager _uiManager;
private ProcedureManager _procedureManager;
private ResourcesLocalComponent _resourcesLocalComponent;
public static GameObject Self => _zcGame._self;
public static Transform ObjectPool => _zcGame._objectPool;
public static float GameTime => _zcGame.gameTime;
public static IObjectManager ObjectManager => _zcGame._objectManager;
public static IUIManager UIManager => _zcGame._uiManager;
public static IProcedureManager ProcedureManager => _zcGame._procedureManager;
public static IResourcesLocalComponent ResourcesLocalComponent => _zcGame._resourcesLocalComponent;
public ZCGame(GameObject self)
{
_zcGame = this;
this._self = self;
this._objectPool = self.transform.Find("ObjectPool");
this.isDisposed = false;
this.isPause = false;
AssemblyManager.Initialize();
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()
{
this._objectManager = new ObjectManager();
this._objectManager.OnInit();
this._uiManager = new UIManager();
this._procedureManager = new ProcedureManager();
this._resourcesLocalComponent = new ResourcesLocalComponent();
this._objectManager.Add(this._uiManager);
this._objectManager.Add(this._procedureManager);
this._procedureManager.ChangeProcedure(ProcedureType.LoadingGameSceneProcedure);
}
void Update(float time)
{
this._objectManager.OnUpdate(time);
}
void LateUpdate(float time)
{
}
void Dispose()
{
this._objectManager.OnDispose();
_resourcesLocalComponent.Dispose();
Debug.Log("关闭应用了");
}
}
}