Пример #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);
        }
Пример #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);
     }
 }
Пример #3
0
 // Adds new state to list of states
 public void AddState(NPCState state)
 {
     stateList.Add(state);
 }
Пример #4
0
 //
 public NPCStateMachine(Enemy owner)
 {
     this.owner     = owner;
     stateList      = new List <NPCState>();
     m_CurrentState = null;
 }
Пример #5
0
 public Transition(NPCState nextState, Func <bool> condition)
 {
     NextState = nextState;
     Condition = condition;
 }