feat(fix-system): 为读档添加状态机即时切换与快照支持

This commit is contained in:
2026-06-11 21:49:18 +08:00
parent c67d988365
commit 4bb0215f3d
7 changed files with 125 additions and 22 deletions
@@ -6,11 +6,13 @@ namespace AibisDream.Framework
public class StateMachine<T> where T : Enum
{
public T CurState => _curState.GetState;
public bool HasState => _curState != null;
public IState<T> CurrentStateObj => _curState;
public event Action<T> OnStateSwitch;
private IState<T> _curState;
private readonly Func<T, string, IState<T>> _createState;
public StateMachine(Func<T, string, IState<T>> createState)
{
_createState = createState;
@@ -30,7 +32,16 @@ namespace AibisDream.Framework
OnStateSwitch?.Invoke(nextState);
yield return _curState.Enter();
}
/// <summary>
/// 强制设置内部状态对象,不触发 Exit / Enter / OnStateSwitch。
/// 用于读档等需要绕过正常状态过渡的场景。
/// </summary>
public void SetStateImmediate(T state, string args = "")
{
_curState = _createState.Invoke(state, args);
}
public IEnumerator QuitState()
{
yield return _curState?.Exit();