Exemple #1
0
 public void enterState(FSMStateType stateType) //Checks that listed state is valid, then calls previous funtion according to entry
 {
     if (fsmStates.ContainsKey(stateType))
     {
         abstractFSMState nextState = fsmStates[stateType];
         enterState(nextState);
     }
 }
Exemple #2
0
 public void enterState(abstractFSMState nextState) //Enter the next desired state
 {
     if (nextState == null)
     {
         return;
     }
     else
     {
         prevState = currentState;
         if (currentState != null)
         {
             currentState.exitState();
         }
         currentState = nextState;
         currentState.enterState();
     }
 }
Exemple #3
0
    public void Awake()
    {
        currentState = null;                                           //Set state to null

        fsmStates = new Dictionary <FSMStateType, abstractFSMState>(); //Initialize state container
        NavMeshAgent agent = this.GetComponent <NavMeshAgent>();       //Set navmesh agent
        NPC          npc   = this.GetComponent <NPC>();                //Set NPC executor

        foreach (abstractFSMState state in validStates)                //Grab each state in validStates, add it to valid states container and set control variables
        {
            state.setExecutingFSM(this);
            state.setExecutingAgent(npc);
            state.setNavMeshAgent(agent);
            state.setPlayer(player);
            fsmStates.Add(state.StateType, state);
        }
    }