using GFramework.Core.Abstractions.State; namespace GFramework.Core.Tests.State; /// /// 为 提供可配置转移结果的同步测试状态。 /// public sealed class TestStateV2 : IState { /// /// 获取或设置是否允许向目标状态转移。 /// public bool AllowTransition { get; set; } = true; /// /// 获取进入状态是否已被调用。 /// public bool EnterCalled { get; private set; } /// /// 获取离开状态是否已被调用。 /// public bool ExitCalled { get; private set; } /// /// 获取进入回调被调用的次数。 /// public int EnterCallCount { get; private set; } /// /// 获取离开回调被调用的次数。 /// public int ExitCallCount { get; private set; } /// /// 获取最近一次进入时的来源状态。 /// public IState? EnterFrom { get; private set; } /// /// 获取最近一次离开时的目标状态。 /// public IState? ExitTo { get; private set; } /// /// 记录进入状态时的来源状态与调用次数。 /// /// 触发进入的来源状态。 public void OnEnter(IState? from) { EnterCalled = true; EnterCallCount++; EnterFrom = from; } /// /// 记录离开状态时的目标状态与调用次数。 /// /// 即将切换到的目标状态。 public void OnExit(IState? to) { ExitCalled = true; ExitCallCount++; ExitTo = to; } /// /// 根据 返回是否允许切换。 /// /// 目标状态。 /// 允许切换时返回 ,否则返回 public bool CanTransitionTo(IState target) { return AllowTransition; } }