Exemplo n.º 1
0
        public void UpdateMachine(GameTime gameTime)
        {
            //don't do anything if you have no states
            if (states.Count == 0)
                return;

            //don't do anything if there's no current
            //state, and no default state
            if (currentState == null)
                currentState = defaultState;
            if (currentState == null)
                return;

            //check for transitions, and then update
            FSMStateEnum oldStateID = currentState.GetID();
            goalStateID = currentState.CheckTransitions();

            //switch if there was a transition
            if (goalStateID != oldStateID)
            {
                if (TransitionState(goalStateID))
                {
                    currentState.Exit();
                    currentState = goalState;
                    currentState.Enter();
                }
            }
            currentState.Update(gameTime);
        }
Exemplo n.º 2
0
    public void pushState(FSMStateEnum fsmStateEnum)
    {
        FSMStateBase fsmStateBase = null;

        if (FSMStateDic.TryGetValue(fsmStateEnum, out fsmStateBase))
        {
            stateBaseStack.Push(fsmStateBase);
        }
    }
Exemplo n.º 3
0
        bool TransitionState(FSMStateEnum goal)
        {
            //don't do anything if you have no states
            if (states.Count == 0)
            {
                return(false);
            }

            //determine if we have state of type 'goal'
            //in the list, and switch to it, otherwise, quit out
            for (int i = 0; i < states.Count; i++)
            {
                if (states[i].GetID() == goal)
                {
                    goalState = states[i];
                    return(true);
                }
            }
            return(false);
        }
Exemplo n.º 4
0
        public void UpdateMachine(GameTime gameTime)
        {
            //don't do anything if you have no states
            if (states.Count == 0)
            {
                return;
            }

            //don't do anything if there's no current
            //state, and no default state
            if (currentState == null)
            {
                currentState = defaultState;
            }
            if (currentState == null)
            {
                return;
            }

            //check for transitions, and then update
            FSMStateEnum oldStateID = currentState.GetID();

            goalStateID = currentState.CheckTransitions();

            //switch if there was a transition
            if (goalStateID != oldStateID)
            {
                if (TransitionState(goalStateID))
                {
                    currentState.Exit();
                    currentState = goalState;
                    currentState.Enter();
                }
            }
            currentState.Update(gameTime);
        }
Exemplo n.º 5
0
        bool TransitionState(FSMStateEnum goal)
        {
            //don't do anything if you have no states
            if (states.Count == 0)
                return false;

            //determine if we have state of type 'goal'
            //in the list, and switch to it, otherwise, quit out
            for (int i = 0; i < states.Count; i++)
            {
                if (states[i].GetID() == goal)
                {
                    goalState = states[i];
                    return true;
                }
            }
            return false;
        }
Exemplo n.º 6
0
 void SetGoalID(FSMStateEnum goal)
 {
     goalStateID = goal;
 }
Exemplo n.º 7
0
 public FSMStateBase(FSMStateEnum fsmStateEnum, GoapAgent goapAgent)
 {
     this.fsmStateEnum = fsmStateEnum;
     this.goapAgent    = goapAgent;
 }
Exemplo n.º 8
0
 void SetGoalID(FSMStateEnum goal)
 {
     goalStateID = goal;
 }
Exemplo n.º 9
0
 public static int ToInt(this FSMStateEnum e)
 {
     return((int)e);
 }