40 lines
1.0 KiB
C#
40 lines
1.0 KiB
C#
using System;
|
|
using UnityEngine;
|
|
|
|
namespace GameFramework
|
|
{
|
|
/// <summary>
|
|
/// 全局游戏状态管理器(持久化单例)。
|
|
/// 维护 GameState,提供 GameOver 触发入口与 onGameOver 事件。
|
|
/// </summary>
|
|
public class GameManager : PersistentSingleton<GameManager>
|
|
{
|
|
/// <summary>游戏结束时触发(GameOverScreen 等订阅)。</summary>
|
|
public static Action onGameOver;
|
|
|
|
public static GameState GameState
|
|
{
|
|
get => Instance.gameState;
|
|
set => Instance.gameState = value;
|
|
}
|
|
|
|
[SerializeField] private GameState gameState = GameState.Playing;
|
|
|
|
/// <summary>触发游戏结束:设状态 + 触发事件。玩家被敌人抓到时调用。</summary>
|
|
public static void GameOver()
|
|
{
|
|
if (Instance == null) return;
|
|
GameState = GameState.GameOver;
|
|
onGameOver?.Invoke();
|
|
}
|
|
}
|
|
|
|
public enum GameState
|
|
{
|
|
Playing,
|
|
Paused,
|
|
GameOver,
|
|
Scoring
|
|
}
|
|
}
|