Пример #1
0
        public void FadeInOut(GameObject parent, int duration = 1400, OnTransition onTransition = null,
                              OnFinished onFinished           = null, CenterMode centerMode = CenterMode.Min)
        {
            parent.AddChild(this);

            if (centerMode == CenterMode.Center)
            {
                SetXY(-width * 0.5f, -height * 0.5f);
            }
            else
            {
                SetXY(0, 0);
            }

            SetActive(true);

            SpriteTweener.TweenAlpha(this, 0, 1, duration / 2, o =>
            {
                onTransition?.Invoke();

                SpriteTweener.TweenAlpha(this, 1, 0, duration / 2, go =>
                {
                    onFinished?.Invoke();

                    SetActive(false);

                    this.parent.RemoveChild(this);
                });
            });

            //CoroutineManager.StartCoroutine(instance.FadeInOutRoutine(time, onFinished));
        }
Пример #2
0
        private void UpdateState(string nextState)
        {
            var oldState = State;

            State = nextState;
            OnTransition?.Invoke(this, new StateTransitionArgs(oldState, LastInput, nextState));
        }
Пример #3
0
        /// <summary>Triggers a transition to a new state via a specified link.</summary>
        /// <param name="node">The state node to transition to.</param>
        /// <param name="link">The link which triggered this new state.</param>
        public void Transition(StateMachineNode node, StateMachineLink link)
        {
            var e = new TransitionEventArgs(this.currentNode, node, link);

            nodeTime         = 0f;
            this.currentNode = node;
            OnTransition?.Invoke(this, e);
        }
Пример #4
0
        private async Task <StateTransitionResult <TState, TTrigger> > executeExitAndEntryActionsAsync(ExecutionParameters <T, TTrigger> parameters, StateTransitionResult <TState, TTrigger> currentResult)
        {
            var currentState = StateAccessor(parameters.Context);

            if (currentResult.WasTransitioned && !currentState.Equals(currentResult.StartingState))
            {
                _stateConfigurations.TryGetValue(currentResult.PreviousState, out var previousStateConfig);
                _stateConfigurations.TryGetValue(currentResult.CurrentState, out var newStateConfig);

                //OnExit? ...don't execute if moving to sub-state
                if (previousStateConfig != null && !(newStateConfig != null && newStateConfig.IsSubStateOf(currentResult.PreviousState)))
                {
                    await previousStateConfig.ExecuteExitActionAsync(parameters, currentResult)
                    .ConfigureAwait(continueOnCapturedContext: false);
                }

                //Fire the transition event before anything else.
                OnTransition?.Invoke(this, new TransitionEventArgs <T, TState, TTrigger>(parameters, currentResult));

                if (newStateConfig != null)
                {
                    //OnEntry? ...don't execute if moving to superstate
                    if (previousStateConfig != null && !previousStateConfig.IsSubStateOf(currentResult.CurrentState))
                    {
                        await newStateConfig.ExecuteEntryActionAsync(parameters, currentResult)
                        .ConfigureAwait(continueOnCapturedContext: false);
                    }

                    //Auto transition?
                    var preAutoTransitionState = currentResult.CurrentState;
                    var autoTransitionResult   = await newStateConfig.ExecuteAutoTransitionAsync(parameters, currentResult)
                                                 .ConfigureAwait(continueOnCapturedContext: false);

                    if (autoTransitionResult.WasTransitioned)
                    {
                        //Merge the results
                        currentResult.PreviousState      = currentResult.CurrentState;
                        currentResult.CurrentState       = autoTransitionResult.CurrentState;
                        currentResult.LastTransitionName = autoTransitionResult.LastTransitionName;
                        //currentResult.WasTransitioned is already true
                    }

                    //See if we have more actions from the auto transition
                    if (!preAutoTransitionState.IsEqual(currentResult.CurrentState))
                    {
                        await executeExitAndEntryActionsAsync(parameters, autoTransitionResult)
                        .ConfigureAwait(continueOnCapturedContext: false);
                    }
                }
            }
            //Reentry?
            else if (_stateConfigurations.TryGetValue(currentResult.CurrentState, out var reenteredState))
            {
                await reenteredState.ExecuteReentryActionAsync(parameters, currentResult)
                .ConfigureAwait(continueOnCapturedContext: false);
            }

            //Send non-transition events
            if (!currentResult.WasTransitioned)
            {
                var transitionEventArgs = new TransitionEventArgs <T, TState, TTrigger>(parameters, currentResult);
                if (!currentResult.TransitionDefined)
                {
                    OnTriggerNotConfigured?.Invoke(this, transitionEventArgs);
                }

                OnNoTransition?.Invoke(this, transitionEventArgs);
            }

            return(currentResult);
        }