Пример #1
0
    // Exit this state
    private void ExitState()
    {
        Debug.Log("Exit Explosion State");
        // Set which state to go.
        States stateToGo;

        if (isAnyExploded)
        {
            stateToGo = States.Reposition;
        }
        else
        {
            if (RotationManager.Instance.isOver)
            {
                stateToGo = States.Input;
            }
            else
            {
                stateToGo = States.Rotation;
            }
        }
        // Publish state exit
        OnStateExit?.Invoke(this, new OnStateExitEventArgs {
            stateToGo = stateToGo
        });
    }
Пример #2
0
        public void ChangeState(T nextState)
        {
            if (Equals(nextState, CurrentState))
            {
                return;
            }
            HashSet <OnExit> exitCallbacks;

            if (OnStateExit.TryGetValue(CurrentState, out exitCallbacks))
            {
                foreach (var callback in exitCallbacks)
                {
                    callback(nextState);
                }
            }
            PreviousState = CurrentState;
            CurrentState  = nextState;
            HashSet <OnEnter> enterCallbacks;

            if (OnStateEnter.TryGetValue(CurrentState, out enterCallbacks))
            {
                foreach (var callback in enterCallbacks)
                {
                    callback(PreviousState);
                }
            }
            StateEnterTime = TimeSlice.Create();
            StateChanged.Publish(PreviousState, CurrentState);
        }
Пример #3
0
 // Exit this state
 private void ExitState(bool isClockwise)
 {
     Debug.Log("Exit Input State");
     isStateActive = false;
     OnStateExit?.Invoke(this, new OnStateExitEventArgs {
         isClockwise = isClockwise
     });
 }
Пример #4
0
 public void ChangeState(TEnum next)
 {
     if (isCalledEnter)
     {
         isCalledEnter = false;
         OnStateExit?.Invoke(CurrentState);
         previousState = CurrentState;
     }
     currentState = next;
 }
Пример #5
0
 // Exit this state
 private void ExitState()
 {
     Debug.Log("Exit Reposition State");
     // Set checkers to false
     isStateOver = true;
     // Clear target positions
     targetPositions.Clear();
     // Publish exit event
     OnStateExit?.Invoke(this, EventArgs.Empty);
 }
Пример #6
0
        protected virtual void ExitCurrentState()
        {
            if (_currentState == null)
            {
                return;
            }

            _currentState.OnExitInvoke();
            _currentState.Exit();
            OnStateExit?.Invoke(_currentState);
            _currentState = null;
        }
Пример #7
0
 // Exit this state
 private void ExitState()
 {
     Debug.Log("Exit Rotation State");
     isStepOver = true;
     counter++;
     if (counter == 3)
     {
         isOver = true;
     }
     OnStateExit?.Invoke(this, new OnStateExitEventArgs {
         isOver = isOver
     });
 }
Пример #8
0
        public void ChangeState(TKey key)
        {
            if (CurrentState != null)
            {
                OnStateExit?.Invoke(CurrentStateKey);
            }

            LogExtensions.Log($"State changed to <color=orange>{key}</color>");

            CurrentState    = states[key];
            CurrentStateKey = key;

            OnStateEnter?.Invoke(key);
        }
Пример #9
0
        /// <summary>
        /// Delete the current state, and activate the one bellow that.
        /// </summary>
        internal void PopState()
        {
            if (_states.Count < 2)
            {
                throw new StackOverflowException();
            }

            _states.Peek().OnExit();
            OnStateExit?.Invoke(_states.Peek());
            _states.Pop();

            var currentState = _states.Peek();

            State.InitStateManager(this);
            currentState.OnEnter();
            OnStateChanged?.Invoke(currentState);
        }
Пример #10
0
        /// <summary>
        /// Calls OnExit on the current state (without Popping it), then Add a new one.
        /// </summary>
        internal void PushState(State state)
        {
            if (state == null)
            {
                Debug.LogWarning("[StateManager] Trying to Push a null state");
                return;
            }

            if (_states.Count > 0)
            {
                _states.Peek().OnExit();
                OnStateExit?.Invoke(_states.Peek());
            }

            _states.Push(state);
            State.InitStateManager(this);
            _states.Peek().OnEnter();
            OnStateChanged?.Invoke(state);
        }
Пример #11
0
        public bool IssueCommand(IComparable command)
        {
            if (IsTransitioning)
            {
                return(false);
            }
            if (CurrentState == null)
            {
                return(false);
            }
            else
            {
                if (!_transitions.ContainsKey(CurrentState))
                {
                    return(false);
                }
                if (!_transitions[CurrentState].ContainsKey(command))
                {
                    return(false);
                }

                if (isInitialisingState)
                {
                    Debug.LogWarning("Do not call IssueCommand from OnStateChange and OnStateEnter handlers");
                    return(false);
                }

                var transition = _transitions[CurrentState][command];
                var ret1       = transition.TestCondition();
                var ret2       = OnStateTransition == null || OnStateTransition.Invoke(transition);
                if (ret1 && ret2)
                {
                    CurrentTransition      = transition;
                    transition.OnComplete += HandleTransitionComplete;

                    OnStateExit?.Invoke(CurrentState);
                    transition.Begin();
                }
                return(true);
            }
        }
 public virtual void Exit()
 {
     OnStateExit?.Invoke();
 }
Пример #13
0
 // Exit this state
 private void ExitState()
 {
     Debug.Log("Exit Game Over State");
     OnStateExit?.Invoke(this, EventArgs.Empty);
 }
Пример #14
0
 protected virtual void OnExit()
 {
     _active = false;
     OnStateExit?.Invoke();
 }
Пример #15
0
 protected void StateExit()
 {
     OnStateExit?.Invoke(Cell);
 }
Пример #16
0
 public Machine(SimpleState initial) : base()
 {
     _activeState = initial;
     OnStateEnter.Add(StateEntered);
     OnStateExit.Add(StateExited);
 }
Пример #17
0
 public virtual void ExitState(T owner)
 {
     OnStateExit?.Invoke(owner);
     OnStateExit = null;
 }
Пример #18
0
 public void Exit(object data, CancellationToken ct)
 {
     OnStateExit?.Invoke(data, ct);
 }