public void DeleteTransition(HumanTransition trans) { // Check for None Transition if (trans == HumanTransition.None) { Debug.LogError("HumanFSMState Error: None transition is not allowed"); return; } // Check if the pair is inside the map before deleting if (map.ContainsKey(trans)) { map.Remove(trans); return; } Debug.LogError("HumanFSMState Error: Transition " + trans.ToString() + " passed to " + stateID.ToString() + "was not on the state's transition list"); }
public void AddTransition(HumanTransition trans, HumanFSMStateID id) { // Check if anyone of the args is invalid if (trans == HumanTransition.None) { Debug.LogError("HumanFSMState Error: None is not allowed for a real Transition"); return; } if (id == HumanFSMStateID.None) { Debug.LogError("HumanFSMState Error: None is not allowed for a real ID"); return; } // Since this is a Deterministic FSM, check fi the current transition was already inside the map if (map.ContainsKey(trans)) { Debug.LogError("HumanFSMState Error: State " + stateID.ToString() + "already has transition" + trans.ToString() + " Impossible to assign to another state"); return; } map.Add(trans, id); }
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; } } }