Ejemplo n.º 1
0
        private void StopActiveState()
        {
            _stateExecution?.Dispose();
            ActiveState?.Exit();

            ActiveState     = null;
            Context         = null;
            _stateExecution = null;
        }
Ejemplo n.º 2
0
 // Change State via State Reference
 public void ChangeState(State toState)
 {
     if (ActiveState != null)
     {
         ActiveState.Exit();
     }
     if (LastState != null && !LastState.Equals(toState))
     {
         LastState = ActiveState;
     }
     ActiveState = toState;
     ActiveState.Enter();
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Instantly changes to the target state
        /// </summary>
        /// <param name="name">The name / identifier of the active state</param>
        void ChangeState(string name)
        {
            State <T> newState = GetState(name);

            ActiveState?.Exit();
            PreviousState = ActiveState?.name ?? "";

            ActiveState = newState;
            ActiveState.Enter();

            if (fromToTransitions.TryGetValue(name, out List <FromToTransition <T> > newActiveTransitions))
            {
                activeStateTransitions = newActiveTransitions;
                foreach (FromToTransition <T> transition in activeStateTransitions)
                {
                    transition.OnEnterFromState();
                }
            }
            else
            {
                activeStateTransitions = System.Array.Empty <Transition <T> >();
            }
        }
Ejemplo n.º 4
0
        /// <inheritdoc />
        public void SwitchState(IState newState)
        {
            if (ActiveState != null)
            {
                ActiveState.SwitchState(null);
                ActiveState.Exit();
                ActiveState.OnLeafStateChanged -= InvokeLeafStateChange;
            }

            var oldState = ActiveState;

            ActiveState = newState;

            if (newState != null)
            {
                newState.Enter();
                newState.OnLeafStateChanged += InvokeLeafStateChange;
            }

            if (oldState != newState)
            {
                InvokeLeafStateChange(newState?.ActiveLeafState);
            }
        }
Ejemplo n.º 5
0
 protected override void OnExit()
 {
     ActiveState.Exit();
 }