using UnityEngine;
using System;
using Core;
namespace Script.Gameplay.Global
{
///
/// 全局时间暂停管理器。
/// 单例,挂载到场景里任意常驻 GameObject(如 Managers)。
///
public class TimePauseManager : MonoSingleton
{
/// 当前是否处于暂停状态
public bool IsPaused { get; private set; }
/// 暂停/恢复时触发,参数 true=暂停,false=恢复
public event Action OnPauseStateChanged;
[Header("调试按钮")]
[SerializeField] private bool _pauseToggle;
private void OnValidate()
{
// Inspector 里打钩立即生效(仅 Editor)
if (Application.isPlaying && Instance == this)
SetPaused(_pauseToggle);
}
///
/// 外部调用:设置暂停状态
///
public void SetPaused(bool pause)
{
if (IsPaused == pause) return;
IsPaused = pause;
Time.timeScale = pause ? 0f : 1f;
OnPauseStateChanged?.Invoke(pause);
}
///
/// 快捷暂停
///
public static void Pause() => Instance.SetPaused(true);
///
/// 快捷恢复
///
public static void Resume() => Instance.SetPaused(false);
}
}