mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-03-22 10:34:30 +08:00
refactor(state): 移除状态机中的同步方法实现
- 移除 IStateMachine 接口中 Unregister<T>() 方法的同步定义 - 移除 StateMachine 类中 Unregister<T>() 方法的同步实现 - 移除 IStateMachine 接口中 CanChangeTo<T>() 方法的同步定义 - 移除 StateMachine 类中 CanChangeTo<T>() 方法的同步实现 - 移除 IStateMachine 接口中 ChangeTo<T>() 方法的同步定义 - 移除 StateMachine 类中 ChangeTo<T>() 方法的同步实现 - 移除 IStateMachine 接口中 GoBack() 方法的同步定义 - 移除 StateMachine 类中 GoBack() 方法的同步实现
This commit is contained in:
parent
6c53626df8
commit
3a334e5666
@ -17,25 +17,12 @@ public interface IStateMachine
|
||||
/// <param name="state">要注册的状态实例</param>
|
||||
IStateMachine Register(IState state);
|
||||
|
||||
/// <summary>
|
||||
/// 从状态机中注销指定类型的状态
|
||||
/// </summary>
|
||||
/// <typeparam name="T">要注销的状态类型,必须实现IState接口</typeparam>
|
||||
IStateMachine Unregister<T>() where T : IState;
|
||||
|
||||
/// <summary>
|
||||
/// 异步从状态机中注销指定类型的状态
|
||||
/// </summary>
|
||||
/// <typeparam name="T">要注销的状态类型,必须实现IState接口</typeparam>
|
||||
Task<IStateMachine> UnregisterAsync<T>() where T : IState;
|
||||
|
||||
/// <summary>
|
||||
/// 检查是否可以切换到指定类型的状态
|
||||
/// </summary>
|
||||
/// <typeparam name="T">目标状态类型,必须实现IState接口</typeparam>
|
||||
/// <returns>如果可以切换则返回true,否则返回false</returns>
|
||||
bool CanChangeTo<T>() where T : IState;
|
||||
|
||||
/// <summary>
|
||||
/// 异步检查是否可以切换到指定类型的状态
|
||||
/// </summary>
|
||||
@ -43,13 +30,6 @@ public interface IStateMachine
|
||||
/// <returns>如果可以切换则返回true,否则返回false</returns>
|
||||
Task<bool> CanChangeToAsync<T>() where T : IState;
|
||||
|
||||
/// <summary>
|
||||
/// 切换到指定类型的状态
|
||||
/// </summary>
|
||||
/// <typeparam name="T">要切换到的状态类型,必须实现IState接口</typeparam>
|
||||
/// <returns>如果成功切换则返回true,否则返回false</returns>
|
||||
bool ChangeTo<T>() where T : IState;
|
||||
|
||||
/// <summary>
|
||||
/// 异步切换到指定类型的状态
|
||||
/// </summary>
|
||||
@ -89,12 +69,6 @@ public interface IStateMachine
|
||||
/// <returns>状态历史记录的只读副本</returns>
|
||||
IReadOnlyList<IState> GetStateHistory();
|
||||
|
||||
/// <summary>
|
||||
/// 回退到上一个状态
|
||||
/// </summary>
|
||||
/// <returns>如果成功回退则返回true,否则返回false</returns>
|
||||
bool GoBack();
|
||||
|
||||
/// <summary>
|
||||
/// 异步回退到上一个状态
|
||||
/// </summary>
|
||||
|
||||
@ -39,15 +39,6 @@ public class StateMachine(int maxHistorySize = 10) : IStateMachine
|
||||
return this;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从状态机中注销指定类型的状态
|
||||
/// </summary>
|
||||
/// <typeparam name="T">要注销的状态类型</typeparam>
|
||||
public IStateMachine Unregister<T>() where T : IState
|
||||
{
|
||||
return UnregisterAsync<T>().GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步注销指定类型的状态
|
||||
/// </summary>
|
||||
@ -75,17 +66,6 @@ public class StateMachine(int maxHistorySize = 10) : IStateMachine
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 检查是否可以切换到指定类型的状态
|
||||
/// </summary>
|
||||
/// <typeparam name="T">目标状态类型</typeparam>
|
||||
/// <returns>如果可以切换则返回true,否则返回false</returns>
|
||||
public bool CanChangeTo<T>() where T : IState
|
||||
{
|
||||
return CanChangeToAsync<T>().GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步检查是否可以切换到指定类型的状态
|
||||
/// </summary>
|
||||
@ -110,18 +90,6 @@ public class StateMachine(int maxHistorySize = 10) : IStateMachine
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 切换到指定类型的状态
|
||||
/// </summary>
|
||||
/// <typeparam name="T">目标状态类型</typeparam>
|
||||
/// <returns>如果成功切换则返回true,否则返回false</returns>
|
||||
/// <exception cref="InvalidOperationException">当目标状态未注册时抛出</exception>
|
||||
public bool ChangeTo<T>() where T : IState
|
||||
{
|
||||
return ChangeToAsync<T>().GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 异步切换到指定类型的状态
|
||||
/// </summary>
|
||||
@ -216,15 +184,6 @@ public class StateMachine(int maxHistorySize = 10) : IStateMachine
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 回退到上一个状态
|
||||
/// </summary>
|
||||
/// <returns>如果成功回退则返回true,否则返回false</returns>
|
||||
public bool GoBack()
|
||||
{
|
||||
return GoBackAsync().GetAwaiter().GetResult();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 异步回退到上一个状态
|
||||
/// </summary>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user