feat(TimePause):时间暂停管理器

This commit is contained in:
2025-10-18 09:13:25 +08:00
parent 0be7ccceba
commit da7ba72698
6 changed files with 182 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: e9bc159ddf0a48aba6e9338d92c5e724
timeCreated: 1760749356

View File

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

View File

@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: e0328f8bde4442bd8b7e093b40c1306e
timeCreated: 1760749366