Exemplo n.º 1
0
        public void UpdateMachine(float delta)
        {
            //If the machine has no states then return;
            if (states.Count == 0)
                return;

            //If state is null set the default state.
            if (currentState == null)
                currentState = defaultState;
            if (currentState == null)
                return;

            FSMEnum oldType = currentState.GetStateType();
            FSMEnum newType = currentState.CheckTransitions();

            //Check if current state wants to change state.
            if(oldType != newType)
            {
                //Checks if the state exists in this machine.
                if (TransitionState(newType))
                {
                    //Enter the new state
                    currentState = (FSMState)states[newType];
                    currentState.Enter();
                }
            }
            //Update the current state.
            currentState.Update(delta);
        }
Exemplo n.º 2
0
 public void AddState(FSMState state){
     states[state.GetStateType()] = state;
 }
Exemplo n.º 3
0
 public void SetDefaultState(FSMState state){
     defaultState = state;
 }