我有这两个主要课程.首先是FSMSystem类:
public class FSMSystem<T> : MonoBehavIoUr where T : FSMSystem<T> { private T m_Owner = default(T); protected FSMState<T> currentState; private Dictionary<int,FSMState<T>> m_states; public FSMSystem(T owner) { m_Owner = GameObject.FindObjectOfType(typeof(T)) as T; //owner; m_states = new Dictionary<int,FSMState<T>>(); } protected void AddState( FSMState<T> state ) { m_states.Add( state.GetStateID(),state ); } }
第二节,FSMState:
public abstract class FSMState<T> { public abstract int GetStateID(); public abstract void OnEnter (FSMSystem<T> fsm,FSMState<T> prevState); public abstract void OnUpdate (FSMSystem<T> fsm); public abstract void OnExit (FSMSystem<T> fsm,FSMState<T> nextState); }
它会导致以下错误:
error CS0309: The type ‘
T
‘ must be convertible to ‘FSMSystem<T>
‘ in
order to use it as parameter ‘T
‘ in the generic type or method
‘FSMSystem<T>
‘
有人能告诉我如何解决这个问题吗?我看到很多其他类似的帖子,但我没有看到这种关系.