示例#1
0
        private async void OnCameraActivated(ICinemachineCamera newCam, ICinemachineCamera oldCam)
        {
            if (_inTransition)
            {
                _cts?.Cancel();
                _inTransition = false;
            }

            if (_toCam != null && !ReferenceEquals(newCam, _toCam))
            {
                return;
            }
            if (_fromCam != null && !ReferenceEquals(oldCam, _fromCam))
            {
                return;
            }

            _inTransition = true;
            _cts          = new CancellationTokenSource();

            OnTransitionStarted?.Invoke();


            var transitionDuration = _brain.ActiveBlend.Duration;

            var token = _cts.Token;
            await Task.Run(() => Task.Delay(TimeSpan.FromSeconds(transitionDuration)));

            if (token.IsCancellationRequested)
            {
                return;
            }

            OnTransitionEnded?.Invoke();
        }
示例#2
0
        // TODO: add other operations like replace, pop-replace, reset etc...

        private void PerformTransition(ViewTransition transition, Action manipulateState, Action onComplete = null)
        {
            transition = transition ?? DefaultTransition ?? Transitions.Instant;

            var oldTopViewEntry = TopViewEntry;

            manipulateState();

            if (OnTransitionStarted != null)
            {
                OnTransitionStarted.Invoke(
                    oldTopViewEntry != null ? oldTopViewEntry.ViewID : null,
                    TopViewEntry != null ? TopViewEntry.ViewID : null
                    );
            }

            if (oldTopViewEntry != null)
            {
                // notify old view that transition has started
                oldTopViewEntry.NotifyView <ITransitionStartedHandler>(
                    t => t.HandleTransitionStarted());
            }

            var oldView = oldTopViewEntry != null ? oldTopViewEntry.View : null;

            transitionIsInProgress = true;
            transition(oldView, TopViewEntry != null ? TopViewEntry.View : null, () =>
            {
                // notify the new view that transition has completed
                if (TopViewEntry != null)
                {
                    TopViewEntry.NotifyView <ITransitionCompleteHandler>(
                        t => t.HandleTransitionComplete());
                }

                if (OnTransitionComplete != null)
                {
                    OnTransitionComplete(oldTopViewEntry == null ? null : oldTopViewEntry.ViewID, TopViewEntry.ViewID);
                }

                if (OnViewHidden != null && oldTopViewEntry != null)
                {
                    OnViewHidden(oldTopViewEntry.ViewID, oldTopViewEntry.View);
                }

                if (OnViewShown != null)
                {
                    OnViewShown(TopViewEntry.ViewID, TopViewEntry.View);
                }

                transitionIsInProgress = false;

                if (onComplete != null)
                {
                    onComplete();
                }
            });
        }
示例#3
0
    public void StartTransition(ISceneTransition transition, int dstScene)
    {
        this.transition = transition;

        m_dst = dstScene;

        Material.shader            = this.transition.GetShader();
        m_transitionCamera.enabled = true;

        OnTransitionStarted?.Invoke();

        StartCoroutine(this.transition.OnScreenObscured(Instance));
    }
        public override bool Transition(SceneManagerController sceneManager,
                                        SceneModel current, SceneModel desired)
        {
            if (swapperCoroutine != null)
            {
                return(false);
            }

            OnTransitionStarted.SafeInvoke(new SceneTransitionEventArgs(sceneManager, current, desired));

            swapperCoroutine = StartCoroutine(SwapScenes(sceneManager, current, desired));

            return(true);
        }
        /// <inheritdoc />
        public async Task DoSceneTransition(IEnumerable <Func <Task> > sceneOperations, IProgressIndicator progressIndicator = null)
        {
            if (TransitionInProgress)
            {
                throw new Exception("Attempting to do a transition while one is already in progress.");
            }

            #region Transition begin

            TransitionInProgress = true;
            OnTransitionStarted?.Invoke();

            if (progressIndicator == null && sceneTransitionServiceProfile.UseDefaultProgressIndicator)
            {   // If we haven't been given a progress indicator, and we're supposed to use a default
                // find / create the default progress indicator
                CreateDefaultProgressIndicator();
                progressIndicator = defaultProgressIndicator;
            }

            if (UseFadeColor)
            {
                await FadeOut();
            }

            if (progressIndicator != null)
            {
                await progressIndicator.OpenAsync();
            }

            #endregion

            #region Task execution

            // Make sure we're on the main thread

            foreach (Func <Task> sceneOperation in sceneOperations)
            {
                await sceneOperation();
            }

            #endregion

            #region Transition end

            // If we used a progress indicator, close it
            if (progressIndicator != null)
            {
                await progressIndicator.CloseAsync();
            }


            if (UseFadeColor)
            {
                await FadeIn();
            }

            TransitionInProgress = false;
            OnTransitionCompleted?.Invoke();

            #endregion
        }