Beispiel #1
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);
        }