52 lines
1.3 KiB
C#
52 lines
1.3 KiB
C#
using System;
|
|
using UnityEngine;
|
|
|
|
namespace GameFramework
|
|
{
|
|
/// <summary>
|
|
/// 全局游戏状态管理器(持久化单例)。
|
|
/// 维护 GameState,提供 GameOver / Win 触发入口与对应事件。
|
|
/// </summary>
|
|
public class GameManager : PersistentSingleton<GameManager>
|
|
{
|
|
/// <summary>游戏结束(失败)时触发。</summary>
|
|
public static Action onGameOver;
|
|
|
|
/// <summary>游戏胜利时触发。</summary>
|
|
public static Action onGameWin;
|
|
|
|
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();
|
|
}
|
|
|
|
/// <summary>触发游戏胜利:设状态 + 触发事件。</summary>
|
|
public static void Win()
|
|
{
|
|
if (Instance == null) return;
|
|
GameState = GameState.Victory;
|
|
onGameWin?.Invoke();
|
|
}
|
|
}
|
|
|
|
public enum GameState
|
|
{
|
|
Playing,
|
|
Paused,
|
|
GameOver,
|
|
Victory,
|
|
Scoring
|
|
}
|
|
}
|