broken
This commit is contained in:
@@ -5,39 +5,42 @@ using UnityEngine.Assertions;
|
||||
|
||||
namespace RebootKit.Engine.Services.Game {
|
||||
public class GameService : IService {
|
||||
private static readonly Logger Logger = new(nameof(GameService));
|
||||
static readonly Logger s_logger = new(nameof(GameService));
|
||||
|
||||
[Inject] DIContext m_DIContext;
|
||||
GameMode m_GameMode;
|
||||
|
||||
GameModeAsset m_GameModeAsset;
|
||||
bool m_isRunning;
|
||||
|
||||
[Inject]
|
||||
private DIContext _diContext;
|
||||
|
||||
private GameModeAsset _gameModeAsset;
|
||||
private GameMode _gameMode;
|
||||
private bool _running;
|
||||
|
||||
public void Dispose() {
|
||||
_running = false;
|
||||
_gameMode.Dispose();
|
||||
m_isRunning = false;
|
||||
m_GameMode.Dispose();
|
||||
}
|
||||
|
||||
public async UniTask Start(GameModeAsset asset, CancellationToken cancellationToken) {
|
||||
Assert.IsNotNull(asset);
|
||||
|
||||
_gameMode = asset.Create(_diContext);
|
||||
await _gameMode.Start(cancellationToken);
|
||||
|
||||
m_GameMode = asset.Create(m_DIContext);
|
||||
await m_GameMode.Start(cancellationToken);
|
||||
|
||||
Run(cancellationToken).Forget();
|
||||
}
|
||||
|
||||
private async UniTask Run(CancellationToken cancellationToken) {
|
||||
if (_gameMode == null) {
|
||||
Logger.Error("Trying to run game without game mode");
|
||||
async UniTask Run(CancellationToken cancellationToken) {
|
||||
if (m_GameMode == null) {
|
||||
s_logger.Error("Trying to run game without game mode");
|
||||
return;
|
||||
}
|
||||
|
||||
_running = true;
|
||||
while (_running) {
|
||||
|
||||
m_isRunning = true;
|
||||
while (m_isRunning) {
|
||||
await UniTask.Yield(PlayerLoopTiming.Update, cancellationToken);
|
||||
_gameMode.Tick();
|
||||
m_GameMode.Tick();
|
||||
|
||||
if (cancellationToken.IsCancellationRequested) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user