Exemplo n.º 1
0
        public string CurrentStateName()
        {
            if (m_currentState == null)
            {
                return(null);
            }

            return(m_currentState.GetType().FullName);
        }
Exemplo n.º 2
0
        /// <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);
        }
Exemplo n.º 3
0
        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();
            }
        }
Exemplo n.º 4
0
 /// <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);
 }
Exemplo n.º 5
0
 /// <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;
 }
Exemplo n.º 6
0
 /// <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;
 }