我有一个简单FiniteStateMachine,并为FSM的状态是从继承的类FSMState抽象类,至极的力量实现的某些方法和字段,该ownerClass字段是一个泛型类型,所以每个国家持有到拥有该实例的类的引用密克罗尼西亚联邦
public abstract class FSMState<T>
{
/// <summary>
/// Reference to the owner class of this State.
/// </summary>
protected abstract T ownerClass { get; set; }
/// <summary>
/// The ID name of this State.
/// </summary>
public abstract string Name { get; set; }
//Constructor
public FSMState(T owner, string name)
{
ownerClass = owner;
Name = name;
}
}
Run Code Online (Sandbox Code Playgroud)
所以州级会看起来像这样
public class MovingState : FSMState<AI>
{
protected override AI ownerClass { get; set; } …Run Code Online (Sandbox Code Playgroud)