/// <summary> /// Add New State into the list /// </summary> public void AddFSMState(FlockFSMStateT1 fsmState) { // Check for Null reference before deleting if (fsmState == null) { Debug.LogError("FSMT1 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(fsmState); currentState = fsmState; currentStateID = fsmState.ID; return; } // Add the state to the List if it´s not inside it foreach (FlockFSMStateT1 state in fsmStates) { if (state.ID == fsmState.ID) { Debug.LogError("FSMT1 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(fsmState); }
/// <summary> /// This method tries to change the state the FSMT1 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(FlockTransitionT1 transT1) { // Check for NullTransition before changing the current state if (transT1 == FlockTransitionT1.None) { Debug.LogError("FSMT1 ERROR: Null transition is not allowed"); return; } // Check if the currentState has the transition passed as argument FlockFSMStateT1ID id = currentState.GetOutputState(transT1); if (id == FlockFSMStateT1ID.None) { Debug.LogError("FSMT1 ERROR: Current State does not have a target state for this transition"); return; } // Update the currentStateID and currentState currentStateID = id; foreach (FlockFSMStateT1 state in fsmStates) { if (state.ID == currentStateID) { currentState = state; break; } } }