} // PerformTransition() public void PerformState(FSMState state) { currentStateID = state.ID; foreach (FSMState _state in states) { if (_state.ID == currentStateID) { // Do the post processing of the state before setting the new one currentState.DoBeforeLeaving(); //attr.StopCoroutine(currentState.DoLogic()); //currentState.RunLogic(); currentState = state; // Reset the state to its desired condition before it can reason or act currentState.DoBeforeEntering(); attr.StartCoroutine(currentState.DoLogic()); break; } } }
public void PerformTransition(Transition trans) { // Check for NullTransition before changing the current state if (trans == Transition.NullTransition) { Debug.LogError("FSM ERROR: NullTransition is not allowed for a real transition"); return; } // Check if the currentState has the transition passed as argument StateID id = currentState.GetOutputState(trans); if (id == StateID.NullStateID) { Debug.LogError("FSM ERROR: State " + currentStateID.ToString() + " does not have a target state " + " for transition " + trans.ToString()); return; } // Update the currentStateID and currentState currentStateID = id; foreach (FSMState state in states) { if (state.ID == currentStateID) { // Do the post processing of the state before setting the new one currentState.DoBeforeLeaving(); //attr.StopCoroutine(currentState.DoLogic()); //currentState.RunLogic(); currentState = state; // Reset the state to its desired condition before it can reason or act currentState.DoBeforeEntering(); attr.StartCoroutine(currentState.DoLogic()); break; } } } // PerformTransition()
/// <summary> /// 设置当前的状态 /// </summary> public void SetCurrentState(FSMState state) { currentStateID = state.ID; currentState = state; state.DoBeforeEntering();//手动触发第一个状态 attr.StartCoroutine(currentState.DoLogic()); }