/// <summary> /// Add New State into the list /// </summary> public void AddFSMStateTeamRed(FSMStateTeamRed fsmStateTeamRed) { // Check for Null reference before deleting if (fsmStateTeamRed == null) { Debug.LogError("FSM ERROR: Null reference is not allowed"); } // First State inserted is also the Initial state // the state the machine is in when the simulation begins if (fsmStates.Count == 0) { fsmStates.Add(fsmStateTeamRed); currentStateTeamRed = fsmStateTeamRed; currentStateIdTeamRed = fsmStateTeamRed.IdTeamRed; return; } // Add the state to the List if it�s not inside it foreach (FSMStateTeamRed state in fsmStates) { if (state.IdTeamRed == fsmStateTeamRed.IdTeamRed) { Debug.LogError("FSM ERROR: Trying to add a state that was already inside the list"); return; } } //If no state in the current then add the state to the list fsmStates.Add(fsmStateTeamRed); }
/// <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 PerformTransitionTeamRed(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 FSMStateIDTeamRed idTeamRed = currentStateTeamRed.GetOutputStateTeamRed(trans); if (idTeamRed == FSMStateIDTeamRed.None) { Debug.LogError("FSM ERROR: Current State does not have a target state for this transition"); return; } // Update the currentStateID and currentState currentStateIdTeamRed = idTeamRed; foreach (FSMStateTeamRed state in fsmStates) { if (state.IdTeamRed == currentStateIdTeamRed) { currentStateTeamRed = state; break; } } }