public virtual void Update() { // Don't execute if halted or never started if (!active) { #if DD_DEBUG LogHalt("Tried to update while the machine was inactive!"); #endif return; } // FSM should never have bad refs if (activeState == null) { #if DD_DEBUG LogHalt("Tried to run an update with no active state to run!"); #endif Halt(); return; } // Check a state's list of transitions and grab the first one that returns true StateTransition <TEnum, TStateActor> newStateTran = activeState.CheckTransitions(ownerActor); // Transition to a new state if (newStateTran != null) { #if DD_DEBUG LogStateChange(activeState, newStateTran.getTargetState); #endif // Notify the old state of the transition TEnum oldState = activeState.getID; activeState.Exit(newStateTran.getTargetState.getID, ownerActor); // Notify the new state of the transition activeState = newStateTran.getTargetState; activeState.Enter(oldState, ownerActor); } // Handle state manipulation of the FSM's owning object activeState.Update(ownerActor); }
// Add a transition to a list of transitions public void AddTransition(StateTransition <TEnum, TStateActor> newTranstion) { transitionList.Add(newTranstion); }