Пример #1
0
        public static void PreviewViewAnimation(UIView view, UIAnimation animation)
        {
            if (s_previewIsPlaying)
            {
                return;
            }
            if (s_delayedCall != null)
            {
                s_delayedCall.Cancel();
            }
            view.UpdateStartValues();
            StopViewPreview(view);
            StopAllAnimations(view.RectTransform);

            Vector3 moveFrom = UIAnimator.GetAnimationMoveFrom(view.RectTransform, animation, view.CurrentStartPosition);
            Vector3 moveTo   = UIAnimator.GetAnimationMoveTo(view.RectTransform, animation, view.CurrentStartPosition);

            if (!animation.Move.Enabled)
            {
                view.ResetPosition();
            }
            else
            {
                PreviewMove(view.RectTransform, moveFrom, moveTo, animation, view.CurrentStartPosition);
            }

            Vector3 rotateFrom = UIAnimator.GetAnimationRotateFrom(animation, view.StartRotation);
            Vector3 rotateTo   = UIAnimator.GetAnimationRotateTo(animation, view.StartRotation);

            if (!animation.Rotate.Enabled)
            {
                view.ResetRotation();
            }
            else
            {
                PreviewRotate(view.RectTransform, rotateFrom, rotateTo, animation, view.StartRotation);
            }

            Vector3 scaleFrom = UIAnimator.GetAnimationScaleFrom(animation, view.StartScale);
            Vector3 scaleTo   = UIAnimator.GetAnimationScaleTo(animation, view.StartScale);

            if (!animation.Scale.Enabled)
            {
                view.ResetScale();
            }
            else
            {
                PreviewScale(view.RectTransform, scaleFrom, scaleTo, animation, view.StartScale);
            }

            float fadeFrom = UIAnimator.GetAnimationFadeFrom(animation, view.StartAlpha);
            float fadeTo   = UIAnimator.GetAnimationFadeTo(animation, view.StartAlpha);

            if (!animation.Fade.Enabled)
            {
                view.ResetAlpha();
            }
            else
            {
                PreviewFade(view.RectTransform, fadeFrom, fadeTo, animation, view.StartAlpha);
            }

            DOTweenEditorPreview.Start();
            s_previewIsPlaying = true;

            s_delayedCall = new DelayedCall((animation.AnimationType == AnimationType.Loop ? 5f : animation.TotalDuration + (animation.AnimationType == AnimationType.Hide ? 0.5f : 0f)), () =>
            {
                StopViewPreview(view);
                s_delayedCall = null;
            });
        }
Пример #2
0
        public static void PreviewButtonAnimation(UIAnimation animation, RectTransform rectTransform, CanvasGroup canvasGroup)
        {
            if (s_previewIsPlaying)
            {
                return;
            }
            if (s_delayedCall != null)
            {
                s_delayedCall.Cancel();
            }
            StopButtonPreview(rectTransform, canvasGroup);

            RectTransform target = rectTransform;

            s_startPosition = target.anchoredPosition3D;
            s_startRotation = target.localRotation.eulerAngles;
            s_startScale    = target.localScale;
            s_startAlpha    = canvasGroup.alpha;

            StopAllAnimations(target);

            Vector3 moveFrom = UIAnimator.GetAnimationMoveFrom(rectTransform, animation, s_startPosition);
            Vector3 moveTo   = UIAnimator.GetAnimationMoveTo(rectTransform, animation, s_startPosition);

            if (!animation.Move.Enabled)
            {
                target.anchoredPosition3D = s_startPosition;
            }
            else
            {
                PreviewMove(rectTransform, moveFrom, moveTo, animation, s_startPosition);
            }

            Vector3 rotateFrom = UIAnimator.GetAnimationRotateFrom(animation, s_startRotation);
            Vector3 rotateTo   = UIAnimator.GetAnimationRotateTo(animation, s_startRotation);

            if (!animation.Rotate.Enabled)
            {
                target.localRotation = Quaternion.Euler(s_startRotation);
            }
            else
            {
                PreviewRotate(rectTransform, rotateFrom, rotateTo, animation, s_startRotation);
            }

            Vector3 scaleFrom = UIAnimator.GetAnimationScaleFrom(animation, s_startScale);
            Vector3 scaleTo   = UIAnimator.GetAnimationScaleTo(animation, s_startScale);

            if (!animation.Scale.Enabled)
            {
                target.localScale = s_startScale;
            }
            else
            {
                PreviewScale(rectTransform, scaleFrom, scaleTo, animation, s_startScale);
            }

            float fadeFrom = UIAnimator.GetAnimationFadeFrom(animation, s_startAlpha);
            float fadeTo   = UIAnimator.GetAnimationFadeTo(animation, s_startAlpha);

            if (!animation.Fade.Enabled)
            {
                canvasGroup.alpha = s_startAlpha;
            }
            else
            {
                PreviewFade(rectTransform, fadeFrom, fadeTo, animation, s_startAlpha);
            }

            DOTweenEditorPreview.Start();
            s_previewIsPlaying = true;

            s_delayedCall = new DelayedCall((animation.AnimationType == AnimationType.Loop ? 5f : animation.TotalDuration + (animation.AnimationType == AnimationType.Hide || animation.AnimationType == AnimationType.State ? 0.5f : 0f)), () =>
            {
                StopButtonPreview(rectTransform, canvasGroup);
                s_delayedCall = null;
            });
        }
Пример #3
0
        public static void PreviewPopupAnimation(UIPopup popup, UIAnimation animation)
        {
            if (s_previewIsPlaying)
            {
                return;
            }
            if (s_delayedCall != null)
            {
                s_delayedCall.Cancel();
            }
            popup.UpdateStartValues();
            StopPopupPreview(popup);
            StopAllAnimations(popup.RectTransform);
            if (popup.HasContainer)
            {
                popup.Container.UpdateStartValues();
                StopAllAnimations(popup.Container.RectTransform);
            }

            if (popup.HasOverlay)
            {
                popup.Overlay.UpdateStartValues();
                StopAllAnimations(popup.RectTransform);
            }

            Vector3 moveFrom = UIAnimator.GetAnimationMoveFrom(popup.Container.RectTransform, animation, popup.Container.StartPosition);
            Vector3 moveTo   = UIAnimator.GetAnimationMoveTo(popup.Container.RectTransform, animation, popup.Container.StartPosition);

            if (!animation.Move.Enabled)
            {
                popup.Container.ResetPosition();
            }
            else
            {
                PreviewMove(popup.Container.RectTransform, moveFrom, moveTo, animation, popup.Container.StartPosition);
            }

            Vector3 rotateFrom = UIAnimator.GetAnimationRotateFrom(animation, popup.Container.StartRotation);
            Vector3 rotateTo   = UIAnimator.GetAnimationRotateTo(animation, popup.Container.StartRotation);

            if (!animation.Rotate.Enabled)
            {
                popup.Container.ResetRotation();
            }
            else
            {
                PreviewRotate(popup.Container.RectTransform, rotateFrom, rotateTo, animation, popup.Container.StartRotation);
            }

            Vector3 scaleFrom = UIAnimator.GetAnimationScaleFrom(animation, popup.Container.StartScale);
            Vector3 scaleTo   = UIAnimator.GetAnimationScaleTo(animation, popup.Container.StartScale);

            if (!animation.Scale.Enabled)
            {
                popup.Container.ResetScale();
            }
            else
            {
                PreviewScale(popup.Container.RectTransform, scaleFrom, scaleTo, animation, popup.Container.StartScale);
            }

            float fadeFrom = UIAnimator.GetAnimationFadeFrom(animation, popup.Container.StartAlpha);
            float fadeTo   = UIAnimator.GetAnimationFadeTo(animation, popup.Container.StartAlpha);

            if (!animation.Fade.Enabled)
            {
                popup.Container.ResetAlpha();
            }
            else
            {
                PreviewFade(popup.Container.RectTransform, fadeFrom, fadeTo, animation, popup.Container.StartAlpha);
            }

            if (animation.Enabled && popup.HasOverlay && popup.Overlay.Enabled)
            {
                float overlayFadeFrom = animation.AnimationType == AnimationType.Show ? 0 : 1;
                float overlayFadeTo   = animation.AnimationType == AnimationType.Show ? 1 : 0;
                popup.Overlay.CanvasGroup.alpha = overlayFadeFrom;
                DOTweenEditorPreview.PrepareTweenForPreview(popup.Overlay.CanvasGroup.DOFade(overlayFadeTo, animation.TotalDuration), true, true, false);
            }

            DOTweenEditorPreview.Start();
            s_previewIsPlaying = true;

            s_delayedCall = new DelayedCall(animation.TotalDuration + (animation.AnimationType == AnimationType.Hide ? 0.5f : 0f), () =>
            {
                StopPopupPreview(popup);
                s_delayedCall = null;
            });
        }
Пример #4
0
    private IEnumerator ShowEnumerator()
    {
        UIAnimator.StopAnimations(RectTransform, ShowBehavior.Animation.AnimationType); //stop any SHOW animations


        //MOVE
        Vector3 moveFrom = UIAnimator.GetAnimationMoveFrom(RectTransform, ShowBehavior.Animation, StartPosition);
        Vector3 moveTo   = UIAnimator.GetAnimationMoveTo(RectTransform, ShowBehavior.Animation, StartPosition);

        if (!ShowBehavior.Animation.Move.Enabled)
        {
            ResetPosition();
        }
        UIAnimator.Move(RectTransform, ShowBehavior.Animation, moveFrom, moveTo); //initialize and play the SHOW Move tween

        //ROTATE
        Vector3 rotateFrom = UIAnimator.GetAnimationRotateFrom(ShowBehavior.Animation, StartRotation);
        Vector3 rotateTo   = UIAnimator.GetAnimationRotateTo(ShowBehavior.Animation, StartRotation);

        if (!ShowBehavior.Animation.Rotate.Enabled)
        {
            ResetRotation();
        }
        UIAnimator.Rotate(RectTransform, ShowBehavior.Animation, rotateFrom, rotateTo); //initialize and play the SHOW Rotate tween

        //SCALE
        Vector3 scaleFrom = UIAnimator.GetAnimationScaleFrom(ShowBehavior.Animation, StartScale);
        Vector3 scaleTo   = UIAnimator.GetAnimationScaleTo(ShowBehavior.Animation, StartScale);

        if (!ShowBehavior.Animation.Scale.Enabled)
        {
            ResetScale();
        }
        UIAnimator.Scale(RectTransform, ShowBehavior.Animation, scaleFrom, scaleTo); //initialize and play the SHOW Scale tween

        //FADE
        float fadeFrom = UIAnimator.GetAnimationFadeFrom(ShowBehavior.Animation, StartAlpha);
        float fadeTo   = UIAnimator.GetAnimationFadeTo(ShowBehavior.Animation, StartAlpha);

        if (!ShowBehavior.Animation.Fade.Enabled)
        {
            ResetAlpha();
        }
        UIAnimator.Fade(RectTransform, ShowBehavior.Animation, fadeFrom, fadeTo); //initialize and play the SHOW Fade tween

        Visibility = VisibilityState.Showing;                                     //update the visibility state


        float startTime      = Time.realtimeSinceStartup;
        float totalDuration  = ShowBehavior.Animation.TotalDuration;
        float elapsedTime    = startTime - Time.realtimeSinceStartup;
        float startDelay     = ShowBehavior.Animation.StartDelay;
        bool  invokedOnStart = false;

        while (elapsedTime <= totalDuration + 0.1f) //wait for seconds realtime (ignore Unity's Time.Timescale)
        {
            elapsedTime = Time.realtimeSinceStartup - startTime;

            if (!invokedOnStart && elapsedTime > startDelay)
            {
                ShowBehavior.onCallback_Start.Invoke();
                invokedOnStart = true;
            }
            yield return(null);
        }

        ShowBehavior.onCallback_Completed.Invoke();
        Visibility      = VisibilityState.Visible; //update the visibility state
        m_showCoroutine = null;                    //clear the coroutine reference
    }
Пример #5
0
        private IEnumerator HideEnumerator(bool instantAction)
        {
            RectTransform.FullScreen(true);
            Overlay.FullScreen(true);

            yield return(null); //skip a frame

            DisableUIInteractions();

            UIAnimator.StopAnimations(Container.RectTransform, HideBehavior.Animation.AnimationType); //stop any HIDE animations

            //MOVE
            Vector3 moveFrom = UIAnimator.GetAnimationMoveFrom(Container.RectTransform, HideBehavior.Animation, Container.StartPosition);
            Vector3 moveTo   = UIAnimator.GetAnimationMoveTo(Container.RectTransform, HideBehavior.Animation, Container.StartPosition);

            if (!HideBehavior.Animation.Move.Enabled)
            {
                Container.ResetPosition();
            }
            UIAnimator.Move(Container.RectTransform, HideBehavior.Animation, moveFrom, moveTo, instantAction); //initialize and play the HIDE Move tween

            //ROTATE
            Vector3 rotateFrom = UIAnimator.GetAnimationRotateFrom(HideBehavior.Animation, Container.StartRotation);
            Vector3 rotateTo   = UIAnimator.GetAnimationRotateTo(HideBehavior.Animation, Container.StartRotation);

            if (!HideBehavior.Animation.Rotate.Enabled)
            {
                Container.ResetRotation();
            }
            UIAnimator.Rotate(Container.RectTransform, HideBehavior.Animation, rotateFrom, rotateTo, instantAction); //initialize and play the HIDE Rotate tween

            //SCALE
            Vector3 scaleFrom = UIAnimator.GetAnimationScaleFrom(HideBehavior.Animation, Container.StartScale);
            Vector3 scaleTo   = UIAnimator.GetAnimationScaleTo(HideBehavior.Animation, Container.StartScale);

            if (!HideBehavior.Animation.Scale.Enabled)
            {
                Container.ResetScale();
            }
            UIAnimator.Scale(Container.RectTransform, HideBehavior.Animation, scaleFrom, scaleTo, instantAction); //initialize and play the HIDE Scale tween

            //FADE
            float fadeFrom = UIAnimator.GetAnimationFadeFrom(HideBehavior.Animation, Container.StartAlpha);
            float fadeTo   = UIAnimator.GetAnimationFadeTo(HideBehavior.Animation, Container.StartAlpha);

            if (!HideBehavior.Animation.Fade.Enabled)
            {
                Container.ResetAlpha();
            }
            UIAnimator.Fade(Container.RectTransform, HideBehavior.Animation, fadeFrom, fadeTo, instantAction); //initialize and play the HIDE Fade tween

            StartCoroutine(ExecuteHideDeselectButtonEnumerator());
            Visibility = VisibilityState.Hiding;                 //update the visibility state
            HideBehavior.OnStart.Invoke(gameObject, !instantAction, !instantAction);
            NotifySystemOfTriggeredBehavior(AnimationType.Hide); //send the global events

            float startTime = Time.realtimeSinceStartup;

            if (!instantAction) //wait for the animation to finish
            {
//                    yield return new WaitForSecondsRealtime(HideBehavior.Animation.TotalDuration + UIViewSettings.DISABLE_WHEN_HIDDEN_TIME_BUFFER); //wait for seconds realtime (ignore Unity's Time.Timescale)

                float totalDuration = HideBehavior.Animation.TotalDuration;
                float elapsedTime   = startTime - Time.realtimeSinceStartup;
                while (elapsedTime <= totalDuration) //wait for seconds realtime (ignore Unity's Time.Timescale)
                {
                    elapsedTime        = Time.realtimeSinceStartup - startTime;
                    VisibilityProgress = 1 - elapsedTime / totalDuration; //operation is reversed in hide than in show
                    yield return(null);
                }

                yield return(new WaitForSecondsRealtime(UIPopupSettings.DISABLE_WHEN_HIDDEN_TIME_BUFFER)); //wait for seconds realtime (ignore Unity's Time.Timescale)
            }

            HideBehavior.OnFinished.Invoke(gameObject, !instantAction, !instantAction);
            Visibility = VisibilityState.NotVisible; //update the visibility state
            if (VisiblePopups.Contains(this))
            {
                VisiblePopups.Remove(this);
            }

            Container.Disable(); //disable the gameobject, canvas and graphic raycaster - if their disable options are set to true
            Overlay.Disable();

            m_hideCoroutine = null; //clear the coroutine reference
            EnableUIInteractions();

            RemoveHiddenFromVisiblePopups();

            if (!m_initialized)
            {
                m_initialized = true;
                yield break;
            }

            UIPopupManager.RemoveFromQueue(this);
            if (!DestroyAfterHide)
            {
                yield break;
            }
            Destroy(gameObject);
        }
Пример #6
0
        private IEnumerator ShowEnumerator(bool instantAction)
        {
            RectTransform.FullScreen(true);
            Overlay.FullScreen(true);

            yield return(null); //skip a frame

            DisableUIInteractions();

            UIAnimator.StopAnimations(Container.RectTransform, ShowBehavior.Animation.AnimationType); //stop any SHOW animations
            Container.Enable();                                                                       //enable the gameobject, canvas and graphic raycaster
            Overlay.Enable();

            //MOVE
            Vector3 moveFrom = UIAnimator.GetAnimationMoveFrom(Container.RectTransform, ShowBehavior.Animation, Container.StartPosition);
            Vector3 moveTo   = UIAnimator.GetAnimationMoveTo(Container.RectTransform, ShowBehavior.Animation, Container.StartPosition);

            if (!ShowBehavior.Animation.Move.Enabled)
            {
                Container.ResetPosition();
            }
            UIAnimator.Move(Container.RectTransform, ShowBehavior.Animation, moveFrom, moveTo, instantAction); //initialize and play the SHOW Move tween

            //ROTATE
            Vector3 rotateFrom = UIAnimator.GetAnimationRotateFrom(ShowBehavior.Animation, Container.StartRotation);
            Vector3 rotateTo   = UIAnimator.GetAnimationRotateTo(ShowBehavior.Animation, Container.StartRotation);

            if (!ShowBehavior.Animation.Rotate.Enabled)
            {
                Container.ResetRotation();
            }
            UIAnimator.Rotate(Container.RectTransform, ShowBehavior.Animation, rotateFrom, rotateTo, instantAction); //initialize and play the SHOW Rotate tween

            //SCALE
            Vector3 scaleFrom = UIAnimator.GetAnimationScaleFrom(ShowBehavior.Animation, Container.StartScale);
            Vector3 scaleTo   = UIAnimator.GetAnimationScaleTo(ShowBehavior.Animation, Container.StartScale);

            if (!ShowBehavior.Animation.Scale.Enabled)
            {
                Container.ResetScale();
            }
            UIAnimator.Scale(Container.RectTransform, ShowBehavior.Animation, scaleFrom, scaleTo, instantAction); //initialize and play the SHOW Scale tween

            //FADE
            float fadeFrom = UIAnimator.GetAnimationFadeFrom(ShowBehavior.Animation, Container.StartAlpha);
            float fadeTo   = UIAnimator.GetAnimationFadeTo(ShowBehavior.Animation, Container.StartAlpha);

            if (!ShowBehavior.Animation.Fade.Enabled)
            {
                Container.ResetAlpha();
            }
            UIAnimator.Fade(Container.RectTransform, ShowBehavior.Animation, fadeFrom, fadeTo, instantAction); //initialize and play the SHOW Fade tween

            Visibility = VisibilityState.Showing;                                                              //update the visibility state
            if (!VisiblePopups.Contains(this))
            {
                VisiblePopups.Add(this);
            }
            ShowBehavior.OnStart.Invoke(gameObject, !instantAction, !instantAction);
            NotifySystemOfTriggeredBehavior(AnimationType.Show); //send the global events
            if (HideProgressor != null)
            {
                HideProgressor.SetValue(0f);
            }

            float startTime = Time.realtimeSinceStartup;

            if (!instantAction) //wait for the animation to finish
            {
//                yield return new WaitForSecondsRealtime(ShowBehavior.Animation.TotalDuration);

                float totalDuration = ShowBehavior.Animation.TotalDuration;
                float elapsedTime   = startTime - Time.realtimeSinceStartup;
                while (elapsedTime <= totalDuration) //wait for seconds realtime (ignore Unity's Time.Timescale)
                {
                    elapsedTime        = Time.realtimeSinceStartup - startTime;
                    VisibilityProgress = elapsedTime / totalDuration;
                    yield return(null);
                }
            }

            ShowBehavior.OnFinished.Invoke(gameObject, !instantAction, !instantAction);

            Visibility = VisibilityState.Visible; //update the visibility state
            if (!VisiblePopups.Contains(this))
            {
                VisiblePopups.Add(this);
            }

            if (AutoHideAfterShow)
            {
                Hide(AutoHideAfterShowDelay);
            }
            StartCoroutine(ExecuteShowSelectDeselectButtonEnumerator()); //select the selectedButton
            m_showCoroutine = null;                                      //clear the coroutine reference
            EnableUIInteractions();

            RemoveHiddenFromVisiblePopups();
        }