public void ChangeState(MonoState <T> pNewState) { if (pNewState == null) { Debug.LogError("该状态不存在"); } if (currentState != pNewState) { //退出之前状态 if (currentState != null) { currentState.Exit(root); } //保存之前状态 previousState = currentState; //设置当前状态 currentState = pNewState; //进入当前状态 if (currentState != null) { currentState.Enter(root); } } }
public MonoStateMachine(T _root) { root = _root; currentState = null; previousState = null; globalStates = new List <MonoState <T> >(); }
public void RemoveGlobalState(MonoState <T> state) { if (globalStates.Contains(state)) { state.Exit(root); globalStates.Remove(state); } }
public void SetGlobalState(MonoState <T> state) { if (!globalStates.Contains(state)) { state.Enter(root); globalStates.Add(state); } }
public void SetCurrentState(MonoState <T> state) { currentState = state; currentState.Enter(root); }