public void DeleteTransition(ZombieTransition trans) { // Check for None Transition if (trans == ZombieTransition.None) { Debug.LogError("ZombieFSMState 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("ZombieFSMState Error: Transition " + trans.ToString() + " passed to " + stateID.ToString() + "was not on the state's transition list"); }
// protected float curRotSpeed; // protected float curSpeed; // protected Vector3 desPos; public void AddTransition(ZombieTransition trans, ZombieFSMStateID id) { // Check if anyone of the args is invalid if (trans == ZombieTransition.None) { Debug.LogError("ZombieFSMState Error: None is not allowed for a real Transition"); return; } if (id == ZombieFSMStateID.None) { Debug.LogError("ZombieFSMState 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("ZombieFSMState Error: State " + stateID.ToString() + "already has transition" + trans.ToString() + " Impossible to assign to another state"); return; } map.Add(trans, id); }
public void PerformTransition(ZombieTransition trans) { // Check for None Transition before changing the current state if (trans == ZombieTransition.None) { Debug.LogError("ZombieFSM Error: None Transition is not allowed for a real transition"); return; } // Check if the currentState has the transition passed as argument ZombieFSMStateID id = currentState.GetOutputState(trans); if (id == ZombieFSMStateID.None) { Debug.LogError("ZombieFSM Error: State " + currentStateID.ToString() + " doesn't have a target state for transition " + trans.ToString()); return; } // Update the currentState and currentStateID currentStateID = id; foreach (ZombieFSMState 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; } } }