public void PerformTransition(HumanTransition trans) { // Check for None Transition before changing the current state if (trans == HumanTransition.None) { Debug.LogError("HumanFSM Error: None Transition is not allowed for a real transition"); return; } // Check if the currentState has the transition passed as argument HumanFSMStateID id = currentState.GetOutputState(trans); if (id == HumanFSMStateID.None) { Debug.LogError("HumanFSM Error: State " + currentStateID.ToString() + " doesn't have a target state for transition " + trans.ToString()); return; } // Update the currentState and currentStateID currentStateID = id; foreach (HumanFSMState state in states) { if (state.ID == currentStateID) { // Do the post processing of the state before setting the new one currentState = state; // Reset the state to its desirec condition before it can reason or act break; } } }
public void AddState(HumanFSMState state) { // Check for Null Reference before Adding if (state == null) { Debug.LogError("HumanFSM Error: Null reference is not allowed"); } // First State inserted also the initial state, the state the machine is in when the simulation begins if (states.Count == 0) { states.Add(state); currentState = state; currentStateID = state.ID; return; } // Add the state to the List if it is not inside it foreach (HumanFSMState s in states) { if (s.ID == state.ID) { Debug.LogError("HumanFSM Error: Impossible to add state " + state.ID.ToString() + " because state has already been added"); return; } } states.Add(state); }