public void PerformTransition(Transition trans) { if (trans == Transition.None) { Debug.LogError("FSM ERROR: Null transition is not allowed"); return; } FSMStateID id = currentState.GetOutputState(trans); if (id == FSMStateID.None) { Debug.LogError("FSM ERROR: Current State does not have a target state for this transition"); return; } currentStateID = id; foreach (FSMState state in fsmStates) { if (state.ID == currentStateID) { currentState = state; break; } } }
/// <summary> /// 状态切换 /// </summary> /// <param name="trans">条件.</param> public void PerformTransiton(Transition trans) { if (trans == Transition.NullTransiton) { Debug.LogError("无法执行空的转换条件"); } StateID id = currenState.GetOutputState(trans); if (id == StateID.NullStateId) { Debug.LogWarning("当前状态" + currentStateID + "无法根据转换条件" + trans + "发生转换"); return; } if (states.ContainsKey(id) == false) { Debug.LogError("在状态里面不存在状态" + id + ",无法进行状态转换!"); return; } FSMState state = states [id]; //因为要发生转换所以调用当前状态的离开函数 currenState.DoAfterLeaving(); currenState = state; currentStateID = id; //调用新状态的进入函数 currenState.DobeforeEntering(); }
// 该方法基于当前状态和过渡状态是否通过来尝试改变状态机的状态,当前状态没有目标状态过渡时则打印错误信息 // 切换当前状态到下一个要转换的状态 public void PerformTransition(Transition trans) { if (trans == Transition.NullTransition) { Debug.LogError("FSM error:NullTransition is not allowed"); return; } StateId id = _currentFsmState.GetOutputState(trans); if (id == StateId.NullStateId) { Debug.LogError("FSM error: State " + _currentFsmState.ID.ToString() + "does not allowed"); return; } //更新当前的状态机和状态编号 _currentStateId = id; foreach (FSMState state in states) { if (state.ID == _currentStateId) { _currentFsmState.DoBeforeLeaving(); _currentFsmState = state; _currentFsmState.DoBeforeEntering(); break; } } }
//执行状态转换 public void PerformTransition(Transition trans) { if (trans == Transition.NullTransition) { Debug.LogError("FSM ERROR: NullTransition is not allowed for a real transition"); return; } StateID id = currentState.GetOutputState(trans); if (id == StateID.NullStateID) { Debug.LogError("FSM ERROR: State " + currentStateID + " does not have a target state " + " for transition " + trans); return; } currentStateID = id; foreach (FSMState state in states) { if (state.ID != currentStateID) { continue; } currentState.DoBeforeLeaving();//转换前执行现有状态的DoBeforeLeaving方法 currentState = state; currentState.DoBeforeEntering();//转换完成,执行转换后状态的DoBeforeEntering方法 break; } }
// next method tries to chage the state the fsm is in based on the current state //and the transition passed in. If the current state doesnt have a target state for the transition passed, // prints an error message public void PerformTransition(Transition trans) { if (trans == Transition.NullTransition) { Debug.LogError("FSM error, NullTransition is not allowed for a real transition"); return; } // look at current state // see if it has the transition passed as an argument StateID id = currentState.GetOutputState(trans); // using method created above 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 the currentState currentStateID = id; foreach (FSMState state in states) { if (state.ID == currentStateID) { // post processes to do to the state before setting a new one currentState.DoBeforeLeaving(); currentState = state; // reset the state to its condition before is can be enacted (reasoning steps included) currentState.DoBeforeEntering(); break; } } // performTranition() } // class FSMSystem()
/// <summary> /// This method tries to change the state the FSM is in based on /// the current state and the transition passed. If current state /// doesn´t have a target state for the transition passed, /// an ERROR message is printed. /// </summary> public void PerformTransition(Transition trans) { // Check for NullTransition before changing the current state if (trans == Transition.None) { Debug.LogError("FSM ERROR: Null transition is not allowed"); return; } // Check if the currentState has the transition passed as argument FSMStateID id = currentState.GetOutputState(trans); if (id == FSMStateID.None) { Debug.LogError("FSM ERROR: Current State does not have a target state for this transition"); return; } // Update the currentStateID and currentState currentStateID = id; foreach (FSMState state in fsmStates) { if (state.ID == currentStateID) { currentState = state; break; } } }
//执行转换 public void PerformTransition(Transition trans) { if (trans == Transition.NullTransition) { Debug.LogError("无法执行NullTransition"); } //得到StateID StateID id = currentState.GetOutputState(trans); if (id == StateID.NullStateID) { Debug.LogWarning("当前状态" + currentState + "无法根据" + trans + "状态发生转换"); } if (states.ContainsKey(id) == false) { Debug.LogError(id + "不存在"); } //根据StateID得到state FSMState state = states[id]; currentState.DoAfterLeaving(); //将当前状态设为state currentState = state; //将当前状态ID设为id currentStateID = id; currentState.DoBeforeEntering(); }
public void PerformTransition(Transition trans) { if (trans == Transition.NullTransition) { Debug.LogError("FSM ERROR: NullTransition is not allowed for a real transition"); return; } StateID id = currentState.GetOutputState(trans); if (id == StateID.NullState) { Debug.LogError("FSM ERROR: State " + currentStateID.ToString() + " does not have a target state " + " for transition " + trans.ToString()); return; } currentStateID = id; foreach (FSMState state in states) { if (state.ID == currentStateID) { currentState.DoBeforeLeaving(); currentState = state; currentState.DoBeforeEntering(); break; } } }
/// <summary> /// 执行转换条件 /// </summary> /// <param name="trans"></param> public void PerformTransition(Transition trans) { if (trans == Transition.NullTRansition) { Debug.LogError("无法执行空的转换条件"); return; } StateID id = currentState.GetOutputState(trans); Debug.Log(id); if (id == StateID.NullStateID) { Debug.LogWarning("当前状态" + currentState + "无法发生条件转换" + trans); return; } if (states.ContainsKey(id) == false) { Debug.LogError("在状态机里不存在状态" + id); } FSMState state = states[id]; currentState.DoAfterLeaving(); currentState = state; currentStateID = state.ID; currentState.DoBeforeEntering(); }
/// <summary> /// This method tries to change the state the FSM is in based on /// the current state and the transition passed. If current state /// doesn't have a target state for the transition passed, /// an ERROR message is printed. /// </summary> 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(); currentState = state; // Reset the state to its desired condition before it can reason or act currentState.DoBeforeEntering(); break; } } }
public void PerformTransition(Transition transition) { if (transition == Transition.NullTransition) { Debug.LogError("the transition is null"); return; } StateID stateID = currentState.GetOutputState(transition); if (stateID == StateID.NullStateID) { Debug.LogError("the state of transition is null ::" + currentState.ID.ToString() + transition.ToString()); return; } currentStateID = stateID; StateID previousState = currentState.ID; foreach (FSMState state in states) { if (state.ID == currentStateID) { currentState.OnLeave(); currentState = state; currentState._PreviousState = previousState; currentState.OnEnter(); break; } } }
public void PerformTransition(int _transition) { if (_transition == FSMState.NULL_TRANSITION) { return; } int stateID = m_currentState.GetOutputState(_transition); if (stateID == FSMState.NULL_STATE_ID) { return; } if (!m_states.ContainsKey(stateID)) { return; } FSMState state = m_states[stateID]; m_currentState.DoAfterLeaving(); m_currentState = state; m_currentStateID = stateID; m_currentState.DoBeforeEntering(); }
// SM switching state public void PerformTransition(Transition trans) { if (trans == Transition.NullTransition) { Debug.LogError("Not real transition"); return; } StateID id = currentState.GetOutputState(trans); if (id == StateID.NullStateID) { Debug.LogError("Unable to switch to that state as transition doesn't exist"); return; } currentStateID = id; foreach (FSMState state in states) { if (state.ID == currentStateID) { currentState.OnExit(); currentState = state; currentState.OnEnter(); break; } } }
public void PerformTransition(Transition trans) { if (trans == Transition.NullTransition) { // Debug.LogError("trans is NullTransition"); return; } StateID id = currentState.GetOutputState(trans); if (id == StateID.NullStateID) { // Debug.LogError("id is nullStateID"); return; } currentStateID = id; foreach (FSMState state in states) { if (state.ID == currentStateID) { currentState.DoBeforeLeaving(); currentState = state; currentState.DoBeforeEntering(); break; } } }
public void PerformTransition(Transition trans) { string errorMsg = ""; if (trans == Transition.NullTransition) { errorMsg = "NullTransition is not allowed for a real transition."; FSMSystemError(errorMsg); return; } StateID id = currentState.GetOutputState(trans); if (id == StateID.NullStateID) { errorMsg = "State " + currentStateID.ToString() + " does not have a target state for transition " + trans.ToString(); FSMSystemError(errorMsg); return; } currentStateID = id; foreach (FSMState state in states) { if (state.ID == currentStateID) { currentState.DoBeforeLeaving(); currentState = state; currentState.DoBeforeEntering(); break; } } }
public void PerformTransition(TransitionID transition) //Asigna el estado al que lleva la transicion a current. { if (transition == TransitionID.NullTransition) { Debug.LogError("Transición nula."); return; } StateID state = currentState.GetOutputState(transition); //Recibe el estado al que se le asigno la transición. if (state == StateID.NullState) { Debug.LogError("La trancición no lleva a ningun estado."); return; } currentID = state; foreach (FSMState s in stateList) { if (s.getID == currentID) { currentState = s; break; //Si lo encuentra lo asigna a Current. } } }
/// <summary> /// Tries to change the state of the FSM based on the current state /// and the given transition. /// If the current state does not have a target state for the passed transition, /// no transition will be performed. /// </summary> /// <param name="transition">Transition</param> public void PerformTransition(Transition transition) { // StateID of the desired transition. StateID id = currentState.GetOutputState(transition); if (transition == Transition.NullTransition) { Debug.LogError("FSMState: NullTransition is not allowed."); } else if (id == StateID.NullStateID) { Debug.LogError("FSMState: State " + currentStateID.ToString() + " does not have a target state for transition " + transition.ToString()); } else { // Change current state currentStateID = id; foreach (FSMState state in states) { if (state.ID == currentStateID) { // Call processing before leaving. currentState.DoBeforeLeaving(); //Change current state. currentState = state; //Call proceccing after entering. currentState.DoBeforeEntering(); break; } } } }
//当前状态转换为新状态 public void PerformTransition(Transition trans) { //设置新的状态编号 currentStateID = currentState.GetOutputState(trans); foreach (FSMState state in fsmStates) { if (state.ID == currentStateID) { //设置新的状态 currentState = state; break; } } }
public void PerformTransition(Transition transition) { FSMStateID id = curState.GetOutputState(transition); curStateID = id; foreach (var state in fsmStates) { if (state.ID == curStateID) { curState = state; break; } } }
/// <summary> /// This method tries to change the state the FSM is in based on /// the current state and the transition passed. /// </summary> public void PerformTransition(Transition trans) { // Check if the currentState has the transition passed as argument FSMStateID id = currentState.GetOutputState(trans); // Update the currentStateID and currentState currentStateID = id; foreach (FSMState state in fsmStates) { if (state.ID == currentStateID) { currentState = state; break; } } }
public void PerformTransition(Transition trans) { if (isTransition) { return; } if (trans == Transition.NullTransition) { Debug.LogError("FSM ERROR: NullTransition is not allowed for a real transition"); return; } StateID id = _CurrentState.GetOutputState(trans); if (id == StateID.NullStateID) { return; } _NextStateID = id; foreach (FSMState state in States) { if (state.ID == _NextStateID) { _TransitionDuration = _CurrentState.dic[trans]; _CurrentState.DoBeforeLeaving(); _CurrentState = null; state.DoBeforeEnter(); isTransition = true; CoroutineTaskManager.Instance.WaitSecondTodo(() => { _CurrentState = state; isTransition = false; }, _TransitionDuration); break; } } }
//控制状态之间的转换 public void PreformTransition(Transition trans) { if (trans == Transition.NullTransition) { Debug.LogError("NullTransition is not allowed for real transition "); return; } StateID id = currentState.GetOutputState(trans); if (id == StateID.NullStateID) { Debug.Log("Transition is not to be happened!没有符合条件的转换"); return; } FSMState state; states.TryGetValue(id, out state); currentState.DoBeforeLeaving(); currentState = state; currentState.DoBeforeEntering(); }
/// <summary> /// This method tries to change the state the FSM is in based on /// the current state and the transition passed. If current state /// doesn't have a target state for the transition passed, /// an ERROR message is printed. /// </summary> public void PerformTransition(PersonState personState, string actionData) { // Check for NullTransition before changing the current state if (personState == PersonState.None) { Debug.Log("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(personState); if (id == StateID.NoneStateId) { Debug.Log("FSM ERROR: State " + currentStateID.ToString() + " does not have a target state " + " for transition " + personState.ToString()); return; } // Update the currentStateID and currentState currentStateID = id; foreach (FSMState state in fSMStates) { if (state.ID == currentStateID) { // Do the post processing of the state before setting the new one currentState.DoBeforeLeaving(); currentState = state; currentState.data = actionData; currentState.HandleData(); // Reset the state to its desired condition before it can reason or act currentState.DoBeforeEntering(); break; } } } // PerformTransition()
public void PerformTransition(string trans) { if (trans == nullTransition) { Debug.LogError("FSM ERROR: NullTransition is not allowed for a real transition"); return; } string id = currentState.GetOutputState(trans); Debug.Log("Got transition " + trans); Debug.Log("And output state is " + id); if (id == nullState) { Debug.LogError("FSM ERROR: State " + currentStateID.ToString() + " does not have a target state " + " for transition " + trans.ToString()); return; } currentStateID = id; bool found = false; foreach (FSMState state in states) { if (state.ID == currentStateID) { found = true; currentState.DoBeforeLeaving(); currentState = state; currentState.DoBeforeEntering(); break; } } if (!found) { Debug.LogError("FSM ERROR: state " + currentStateID + " not found. Maybe you are missing the implementation"); } }
public void PerformTransition(Transition trans) { if (trans == Transition.NullTransition) { TraceUtil.Log(SystemModel.Common, TraceLevel.Error, "FSM ERROR:NullTransition is not allowed for a real transition"); return; } StateID id = m_currentState.GetOutputState(trans); if (id == StateID.NullStateID) { TraceUtil.Log(SystemModel.Common, TraceLevel.Error, "FSM ERROR: State " + m_currentStateID.ToString() + " does not have a target state for transition " + trans.ToString()); return; } if (m_allowStateChange != null && !m_allowStateChange(trans)) { return; } m_previourStateID = m_currentStateID; m_currentStateID = id; foreach (FSMState state in m_states) { if (state.StateID == m_currentStateID) { m_currentState.DoBeforeLeaving(); m_currentState = state; if (OnPerformTransition != null) { OnPerformTransition(trans); } m_currentState.DoBeforeEntering(); break; } } }
public void PerformTransition(Transition trans)//执行状态转换 { if (trans == Transition.NullTransition) { Debug.LogError("无法执行空的转换条件"); return; } StateID id = currentState.GetOutputState(trans); if (id == StateID.NullStateID) { Debug.LogWarning("当前状态" + currentStateID + "无法根据条件转换" + trans + "发生转换"); return; } if (states.ContainsKey(id) == false) { Debug.LogError("在状态机里面不存在状态" + id + ",无法进行转换!"); return; } FSMState state = states[id]; currentState.DoAfterLeaving(); currentState = state; currentStateID = id; currentState.DoBeforeEntering(); }
/// 执行转换过渡 public void PerformTransition(Transition trans) { // 空值检验 if (trans == Transition.NullTransition) { Debug.LogError("FSM ERROR: 转换不可为空"); return; } // 获取当前状态ID StateID id = currentState.GetOutputState(trans); if (id == StateID.NullStateID) { Debug.LogError("FSM ERROR: 状态 " + currentStateID.ToString() + " 不存在目标状态 " + " - 转换: " + trans.ToString()); return; } // 更新当前状态ID 与 当前状态 currentStateID = id; foreach (FSMState state in states) { if (state.ID == currentStateID) { // 执行当前状态后处理 currentState.DoBeforeLeaving(); currentState = state; // 执行当前状态前处理 currentState.DoBeforeEntering(); break; } } }
public void PerformTransition(GlobalStateData.FSMTransistion trans) { // Check for NullTransition before changing the current state if (trans == GlobalStateData.FSMTransistion.None) { Debug.LogError(SCRIPT_NAME + ": Null transition is not allowed"); return; } // Check if the currentState has the transition passed as argument GlobalStateData.FSMStateID id = currentState.GetOutputState(trans); if (id == GlobalStateData.FSMStateID.None) { Debug.LogError(SCRIPT_NAME + ": Current State does not have a target state for this transition"); return; } // Update the currentStateID and currentState //currentStateID = id; foreach (FSMState state in fsmStates) { if (state.ID == id) { // Store previous state and call exit method. previousState = currentState; previousState.Exit(); // Update current state and call enter method. currentState = state; currentState.Enter(); break; } } }