예제 #1
0
        public string CurrentStateName()
        {
            if (m_currentState == null)
            {
                return(null);
            }

            return(m_currentState.GetType().FullName);
        }
예제 #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);
        }
예제 #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();
            }
        }
예제 #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);
 }
예제 #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;
 }
예제 #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;
 }