Пример #1
0
        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);
        }
Пример #2
0
 // Add a transition to a list of transitions
 public void AddTransition(StateTransition <TEnum, TStateActor> newTranstion)
 {
     transitionList.Add(newTranstion);
 }