Ejemplo n.º 1
0
        public void Update(float deltaTime)
        {
            // Null check the current state of the FSM
            if (m_CurrentState == null)
            {
                return;
            }

            // Check the conditions for each transition of the current state
            foreach (Transition t in m_CurrentState.TransitionList)
            {
                // If the condition has evaluated to true
                // then transition to the next state
                if (t.Condition())
                {
                    m_CurrentState.Exit(owner);
                    m_CurrentState = t.NextState;
                    m_CurrentState.Enter(owner);
                    break;
                }
            }

            // Execute the current state
            m_CurrentState.Execute(owner, deltaTime);
        }
Ejemplo n.º 2
0
 // Puts state machine in the given state
 public void Initialise(string stateName)
 {
     m_CurrentState = stateList.Find(state => state.Name.Equals(stateName));
     if (m_CurrentState != null)
     {
         m_CurrentState.Enter(owner);
     }
 }
Ejemplo n.º 3
0
 // Adds new state to list of states
 public void AddState(NPCState state)
 {
     stateList.Add(state);
 }
Ejemplo n.º 4
0
 //
 public NPCStateMachine(Enemy owner)
 {
     this.owner     = owner;
     stateList      = new List <NPCState>();
     m_CurrentState = null;
 }
Ejemplo n.º 5
0
 public Transition(NPCState nextState, Func <bool> condition)
 {
     NextState = nextState;
     Condition = condition;
 }