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