public string CurrentStateName() { if (m_currentState == null) { return(null); } return(m_currentState.GetType().FullName); }
/// <summary> /// Creates a new Finite State Machine and changes the state to startState. /// </summary> /// <param name="context">Type</param> /// <param name="startState">Start State</param> public FiniteStateMachine(T context, IFsmState <T> startState) { this.Context = context; this.CurrentState = startState; startState.Machine = this; startState.Context = context; this.CurrentState.Begin(); stateDictionary.Add(startState.GetType(), startState); }
public void UpdateTick() { if (_currentState != null) { var next = _currentState.ShoudExit(); if (next != null && next != _currentState.GetType()) { _currentState.OnExit(); _currentState = _fsmStates[next]; _currentState.OnEnter(); } _currentState.OnUpdate(); } }
/// <summary> /// Preemptively add a state instance. Useful if the state doesn't have an empty /// constructor and therefore cannot be used with ChangeStateAuto. /// </summary> /// <param name="state">The state to register.</param> public void AddState(IFsmState <T> state) { state.Machine = this; state.Context = Context; stateDictionary.Add(state.GetType(), state); }
/// <summary> /// Preemptively add a state instance. /// Useful if the state doesn't have an empty constructor and therefore cannot be used with ChangeStateAuto. /// </summary> /// <param name="state">The state to register.</param> public void RegisterState(IFsmState <T> state) { _states[state.GetType()] = state; }
/// <summary> /// Preemptively add a state instance. /// Useful if the state doesn't have an empty constructor and therefore cannot be used with ChangeStateAuto. /// </summary> /// <param name="state">The state to register.</param> public void RegisterState(IFsmState <T> state) { _states[state.GetType()] = state; CurrentState.Machine = this; CurrentState.Context = Context; }