Update Project

This commit is contained in:
2026-03-20 13:04:43 +02:00
parent 9b587e6cba
commit beae2dea89
2295 changed files with 251259 additions and 33 deletions
+45
View File
@@ -0,0 +1,45 @@
using UnityEngine;
namespace FlappyBird.Core
{
/// <summary>
/// Pure C# service — central authority for all game-state transitions.
/// No MonoBehaviour, no Unity lifecycle. Injected via Zenject.
///
/// Transition side-effects:
/// Playing -> Time.timeScale = 1 (unfreeze)
/// GameOver -> Time.timeScale = 0 (freeze everything)
/// Menu -> Time.timeScale = 0 (frozen until game starts)
/// </summary>
public sealed class GameStateManager : IGameStateManager
{
// ── IGameStateManager ──────────────────────────────────────────────
/// <inheritdoc/>
public GameState CurrentState { get; private set; } = GameState.Menu;
/// <inheritdoc/>
public event System.Action<GameState> OnStateChanged;
// ── Constructor ────────────────────────────────────────────────────
public GameStateManager()
{
// Start frozen; gameplay begins only when ChangeState(Playing) is called.
Time.timeScale = 0f;
}
// ── IGameStateManager ──────────────────────────────────────────────
/// <inheritdoc/>
public void ChangeState(GameState newState)
{
if (CurrentState == newState) return;
CurrentState = newState;
ApplyTimeScale(newState);
OnStateChanged?.Invoke(newState);
}
// ── Private helpers ────────────────────────────────────────────────
/// <summary>
/// Only Playing runs at normal speed.
/// Menu and GameOver both freeze Time so no physics or Update logic runs.
/// </summary>
private static void ApplyTimeScale(GameState state)
{
Time.timeScale = state == GameState.Playing ? 1f : 0f;
}
}
}