public bool TransitionTo(AState p_to) { if (!m_transitions.ContainsKey(m_currentState)) { Debug.Log("Current state has no transitions"); return(false); } if (!m_transitions[m_currentState].ContainsKey(p_to)) { return(false); } var condition = m_transitions[m_currentState][p_to]; if (condition != null && !condition.Invoke()) { return(false); } m_currentState.OnExit(); m_currentState = p_to; m_currentState.OnEnter(); return(true); }
public StateMachine SetCurrentState(AState p_state) { if (!m_states.Contains(p_state)) { return(null); } m_currentState = p_state; return(this); }
public StateMachine AddTransition(AState p_from, AState p_to, Func <bool> p_condition = null) { // Initialization if (m_transitions == null) { m_transitions = new Dictionary <AState, Dictionary <AState, Func <bool> > >(); } if (!m_transitions.ContainsKey(p_from)) { m_transitions.Add(p_from, new Dictionary <AState, Func <bool> >()); } // Add state m_transitions[p_from].Add(p_to, p_condition); return(this); }