GeWuYou 22c1d08dc3 feat(state): 实现异步状态基类的同步方法限制
- 为 AsyncContextAwareStateBase 添加同步方法异常抛出机制
- 禁止在异步状态中使用 OnEnter、OnExit 和 CanTransitionTo 同步方法
- 提供清晰的错误提示引导使用对应的异步方法
- 修复 StateMachine 中的状态转换逻辑确保线程安全
- 更新 IAsyncState 接口继承 IState 接口统一状态管理
2026-02-15 21:00:38 +08:00

39 lines
1.5 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Copyright (c) 2026 GeWuYou
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
namespace GFramework.Core.Abstractions.state;
/// <summary>
/// 异步状态机状态接口,定义了状态的异步行为和转换规则
/// </summary>
public interface IAsyncState : IState
{
/// <summary>
/// 当状态被激活进入时异步调用
/// </summary>
/// <param name="from">从哪个状态转换而来可能为null表示初始状态</param>
Task OnEnterAsync(IState? from);
/// <summary>
/// 当状态退出时异步调用
/// </summary>
/// <param name="to">将要转换到的目标状态可能为null表示结束状态</param>
Task OnExitAsync(IState? to);
/// <summary>
/// 异步判断当前状态是否可以转换到目标状态
/// </summary>
/// <param name="target">目标状态</param>
/// <returns>如果可以转换则返回true否则返回false</returns>
Task<bool> CanTransitionToAsync(IState target);
}