using Unity.Entities;
namespace TinyKitchen
{
///
/// Show Victory UI when the player scores
///
public class ShowScoredMessage : SystemBase
{
// Time between the player scored and change to the next level
private float m_CountDownTimer;
protected override void OnStartRunning()
{
ResetTimer();
}
protected override void OnUpdate()
{
var game = GetSingleton();
if (game.gameState == GameState.Scored)
{
if (m_CountDownTimer < 0)
{
// Change to the next level and then, reset timer if time limit is reached
game.currentLevel++;
game.gameState = GameState.Initialization;
// Hide Victory UI
Entities.WithEntityQueryOptions(EntityQueryOptions.IncludeDisabled)
.ForEach((ref Entity entity, in UIVictory uiVictory) =>
{
EntityManager.AddComponent(entity);
}).WithoutBurst().WithStructuralChanges().Run();
SetSingleton(game);
ResetTimer();
}
else
{
// Show Victory UI
Entities.WithEntityQueryOptions(EntityQueryOptions.IncludeDisabled)
.ForEach((ref Entity entity, in UIVictory uiVictory) =>
{
EntityManager.RemoveComponent(entity);
}).WithoutBurst().WithStructuralChanges().Run();
m_CountDownTimer -= Time.DeltaTime;
}
}
}
void ResetTimer()
{
var settings = GetSingleton();
m_CountDownTimer = settings.changeLevelTime;
}
}
}