public void DeleteTransition(EnemyTransition transition) { if (!m_Map.ContainsKey(transition)) { Debug.LogError("删除转换条件失败,不存在该条件 : " + transition.ToString()); return; } m_Map.Remove(transition); }
/// <summary> /// 根据指定的转换条件获取状态ID /// </summary> /// <param name="transition"></param> /// <returns></returns> public EnemyStateID GetOutPutState(EnemyTransition transition) { if (!m_Map.ContainsKey(transition)) { Debug.LogError("获取转换条件失败,不存在该条件 : " + transition.ToString()); return(EnemyStateID.NullState); } return(m_Map[transition]); }
public void DeleteTransition(EnemyTransition trans) { // Check for NullTransition if (trans == EnemyTransition.NullTransition) { Debug.LogError("EnemyFSMState ERROR: NullTransition is not allowed"); return; } // Check if the pair is inside the map before deleting if (map.ContainsKey(trans)) { map.Remove(trans); return; } Debug.LogError("EnemyFSMState ERROR: Transition " + trans.ToString() + " passed to " + stateID.ToString() + " was not on the state's transition list"); }
/// <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(EnemyTransition trans) { // Check for NullTransition before changing the current state if (trans == EnemyTransition.NullTransition) { Debug.LogError("EnemyFSM ERROR: NullTransition is not allowed for a real transition"); return; } // Check if the currentState has the transition passed as argument EnemyStateID id = currentState.GetOutputState(trans); if (id == EnemyStateID.NullStateID) { Debug.LogError("EnemyFSM ERROR: State " + currentStateID.ToString() + " does not have a target state " + " for transition " + trans.ToString()); return; } // Update the currentStateID and currentState currentStateID = id; foreach (EnemyFSMState 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; } } } // PerformTransition()
public void AddTransition(EnemyTransition trans, EnemyStateID id) { // Check if anyone of the args is invalid if (trans == EnemyTransition.NullTransition) { Debug.LogError("EnemyFSMState ERROR: NullTransition is not allowed for a real transition"); return; } if (id == EnemyStateID.NullStateID) { Debug.LogError("EnemyFSMState ERROR: NullStateID is not allowed for a real ID"); return; } // Since this is a Deterministic FSM, // check if the current transition was already inside the map if (map.ContainsKey(trans)) { Debug.LogError("EnemyFSMState ERROR: State " + stateID.ToString() + " already has transition " + trans.ToString() + "Impossible to assign to another state"); return; } map.Add(trans, id); }