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 平台具体实现 - 提供了完整的单元测试覆盖基础功能、嵌套暂停、分组管理和线程安全场景
43 lines
1.1 KiB
C#
43 lines
1.1 KiB
C#
namespace GFramework.Core.Abstractions.pause;
|
|
|
|
/// <summary>
|
|
/// 暂停令牌,唯一标识一个暂停请求
|
|
/// </summary>
|
|
public readonly struct PauseToken : IEquatable<PauseToken>
|
|
{
|
|
/// <summary>
|
|
/// 令牌 ID
|
|
/// </summary>
|
|
public Guid Id { get; }
|
|
|
|
/// <summary>
|
|
/// 是否为有效令牌
|
|
/// </summary>
|
|
public bool IsValid => Id != Guid.Empty;
|
|
|
|
/// <summary>
|
|
/// 创建暂停令牌
|
|
/// </summary>
|
|
/// <param name="id">令牌 ID</param>
|
|
public PauseToken(Guid id)
|
|
{
|
|
Id = id;
|
|
}
|
|
|
|
/// <summary>
|
|
/// 创建无效令牌
|
|
/// </summary>
|
|
public static PauseToken Invalid => new(Guid.Empty);
|
|
|
|
public bool Equals(PauseToken other) => Id.Equals(other.Id);
|
|
|
|
public override bool Equals(object? obj) => obj is PauseToken other && Equals(other);
|
|
|
|
public override int GetHashCode() => Id.GetHashCode();
|
|
|
|
public static bool operator ==(PauseToken left, PauseToken right) => left.Equals(right);
|
|
|
|
public static bool operator !=(PauseToken left, PauseToken right) => !left.Equals(right);
|
|
|
|
public override string ToString() => $"PauseToken({Id})";
|
|
} |