mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-03-23 03:04:29 +08:00
- 实现了 PauseStackManager 核心管理器,支持嵌套暂停和分组管理 - 添加了 PauseToken 暂停令牌和 PauseGroup 暂停组枚举 - 创建了 PauseScope 作用域类,支持 using 语法自动管理暂停生命周期 - 实现了线程安全的暂停栈操作,包括 Push、Pop 和状态查询 - 添加了暂停处理器接口 IPauseHandler 和 Godot 平台具体实现 - 提供了完整的单元测试覆盖基础功能、嵌套暂停、分组管理和线程安全场景
42 lines
1.1 KiB
C#
42 lines
1.1 KiB
C#
using GFramework.Core.Abstractions.pause;
|
|
using Godot;
|
|
|
|
namespace GFramework.Godot.pause;
|
|
|
|
/// <summary>
|
|
/// Godot 引擎的暂停处理器
|
|
/// 响应暂停栈状态变化,控制 SceneTree.Paused
|
|
/// </summary>
|
|
public class GodotPauseHandler : IPauseHandler
|
|
{
|
|
private readonly SceneTree _tree;
|
|
|
|
/// <summary>
|
|
/// 创建 Godot 暂停处理器
|
|
/// </summary>
|
|
/// <param name="tree">场景树</param>
|
|
public GodotPauseHandler(SceneTree tree)
|
|
{
|
|
_tree = tree ?? throw new ArgumentNullException(nameof(tree));
|
|
}
|
|
|
|
/// <summary>
|
|
/// 处理器优先级
|
|
/// </summary>
|
|
public int Priority => 0;
|
|
|
|
/// <summary>
|
|
/// 当暂停状态变化时调用
|
|
/// </summary>
|
|
/// <param name="group">暂停组</param>
|
|
/// <param name="isPaused">是否暂停</param>
|
|
public void OnPauseStateChanged(PauseGroup group, bool isPaused)
|
|
{
|
|
// 只有 Global 组影响 Godot 的全局暂停
|
|
if (group == PauseGroup.Global)
|
|
{
|
|
_tree.Paused = isPaused;
|
|
GD.Print($"[GodotPauseHandler] SceneTree.Paused = {isPaused}");
|
|
}
|
|
}
|
|
} |