using UnityEngine; namespace FlappyBird.Core { /// /// 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) /// public sealed class GameStateManager : IGameStateManager { // ── IGameStateManager ────────────────────────────────────────────── /// public GameState CurrentState { get; private set; } = GameState.Menu; /// public event System.Action OnStateChanged; // ── Constructor ──────────────────────────────────────────────────── public GameStateManager() { // Start frozen; gameplay begins only when ChangeState(Playing) is called. Time.timeScale = 0f; } // ── IGameStateManager ────────────────────────────────────────────── /// public void ChangeState(GameState newState) { if (CurrentState == newState) return; CurrentState = newState; ApplyTimeScale(newState); OnStateChanged?.Invoke(newState); } // ── Private helpers ──────────────────────────────────────────────── /// /// Only Playing runs at normal speed. /// Menu and GameOver both freeze Time so no physics or Update logic runs. /// private static void ApplyTimeScale(GameState state) { Time.timeScale = state == GameState.Playing ? 1f : 0f; } } }