mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-03-22 10:34:30 +08:00
- 为 AsyncContextAwareStateBase 添加同步方法异常抛出机制 - 禁止在异步状态中使用 OnEnter、OnExit 和 CanTransitionTo 同步方法 - 提供清晰的错误提示引导使用对应的异步方法 - 修复 StateMachine 中的状态转换逻辑确保线程安全 - 更新 IAsyncState 接口继承 IState 接口统一状态管理
39 lines
1.5 KiB
C#
39 lines
1.5 KiB
C#
// 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);
|
||
} |