Exemple #1
0
        /************************************************************************************************************************/

        /// <summary>
        /// Calls <see cref="IState.OnExitState"/> on the current state then changes to the specified key and
        /// state and calls <see cref="IState.OnEnterState"/> on it.
        /// <para></para>
        /// Note that this method does not check <see cref="IState.CanExitState"/> or
        /// <see cref="IState.CanEnterState"/>. To do that, you should use
        /// <see cref="TrySetState(TKey, TState)"/> instead.
        /// </summary>
        public void ForceSetState(TKey key, TState state)
        {
            KeyChange <TKey> .Begin(CurrentKey, key, out var previouslyActiveChange);

            try
            {
                CurrentKey = key;
                ForceSetState(state);
            }
            finally
            {
                KeyChange <TKey> .End(previouslyActiveChange);
            }
        }
Exemple #2
0
        /************************************************************************************************************************/

        /// <summary>
        /// Attempts to enter the specified `state` and returns true if successful.
        /// <para></para>
        /// This method does not check if the `state` is already the <see cref="StateMachine{TState}.CurrentState"/>.
        /// To do so, use <see cref="TrySetState(TKey, TState)"/> instead.
        /// </summary>
        public bool TryResetState(TKey key, TState state)
        {
            KeyChange <TKey> .Begin(CurrentKey, key, out var previouslyActiveChange);

            try
            {
                if (!CanSetState(state))
                {
                    return(false);
                }

                ForceSetState(key, state);
                return(true);
            }
            finally
            {
                KeyChange <TKey> .End(previouslyActiveChange);
            }
        }