Esempio n. 1
0
        public void StartDemoTween()
        {
            if (this.imageComponent == null)
            {
                return;
            }

            float targetAmount = (this.imageComponent.fillAmount > 0.5f) ? 0f : 1f;

            FloatTween floatTween = new FloatTween {
                duration = this.Duration, startFloat = this.imageComponent.fillAmount, targetFloat = targetAmount
            };

            floatTween.AddOnChangedCallback(SetFillAmount);
            floatTween.AddOnFinishCallback(OnTweenFinished);
            floatTween.ignoreTimeScale = true;
            this.m_FloatTweenRunner.StartTween(floatTween);
        }
        public void StartDemoTween()
        {
            if ((this.m_Type == Type.Normal && this.m_TargetImage == null) || (this.m_Type == Type.Masked && this.m_TargetTransform == null))
            {
                return;
            }

            float targetAmount = (this.m_FillAmount > 0.5f) ? 0f : 1f;

            FloatTween floatTween = new FloatTween {
                duration = this.m_Duration, startFloat = this.m_FillAmount, targetFloat = targetAmount
            };

            floatTween.AddOnChangedCallback(SetFillAmount);
            floatTween.AddOnFinishCallback(OnTweenFinished);
            floatTween.ignoreTimeScale = true;
            this.m_FloatTweenRunner.StartTween(floatTween);
        }
Esempio n. 3
0
        public void StartDemoTween()
        {
            if (this.bar == null)
            {
                return;
            }

            float pct          = (float)this.bar.value / (float)this.bar.maxValue;
            float targetAmount = (pct > 0.5f) ? 0f : 1f;

            FloatTween floatTween = new FloatTween {
                duration = this.duration, startFloat = pct, targetFloat = targetAmount
            };

            floatTween.AddOnChangedCallback(SetFillAmount);
            floatTween.AddOnFinishCallback(OnTweenFinished);
            floatTween.ignoreTimeScale = true;
            this.m_FloatTweenRunner.StartTween(floatTween);
        }
Esempio n. 4
0
        protected void Start()
        {
            if (this.imageComponent != null)
            {
                this.imageComponent.fillAmount = 0f;
            }

            if (this.textComponent != null)
            {
                this.textComponent.text = "0%";
            }

            var floatTween = new FloatTween {
                duration = this.Duration, startFloat = 0f, targetFloat = 1f
            };

            floatTween.AddOnChangedCallback(SetFillAmount);
            floatTween.AddOnFinishCallback(OnTweenFinished);
            floatTween.ignoreTimeScale = true;
            this.m_FloatTweenRunner.StartTween(floatTween);
        }
Esempio n. 5
0
        /// <summary>
        /// Tweens the delete button alpha.
        /// </summary>
        /// <param name="targetAlpha">Target alpha.</param>
        /// <param name="duration">Duration.</param>
        /// <param name="ignoreTimeScale">If set to <c>true</c> ignore time scale.</param>
        public void TweenDeleteButtonAlpha(float targetAlpha, float duration, bool ignoreTimeScale)
        {
            if (this.GetDeleteButtonCavnasGroup() == null)
            {
                return;
            }

            float currentAlpha = this.GetDeleteButtonCavnasGroup().alpha;

            if (currentAlpha.Equals(targetAlpha))
            {
                return;
            }

            var floatTween = new FloatTween {
                duration = duration, startFloat = currentAlpha, targetFloat = targetAlpha
            };

            floatTween.AddOnChangedCallback(SetDeleteButtonAlpha);
            floatTween.ignoreTimeScale = ignoreTimeScale;
            this.m_FloatTweenRunner.StartTween(floatTween);
        }
Esempio n. 6
0
        /// <summary>
        /// Tweens the list alpha.
        /// </summary>
        /// <param name="targetAlpha">Target alpha.</param>
        /// <param name="duration">Duration.</param>
        /// <param name="ignoreTimeScale">If set to <c>true</c> ignore time scale.</param>
        private void TweenListAlpha(float targetAlpha, float duration, bool ignoreTimeScale)
        {
            if (this.m_ListCanvasGroup == null)
            {
                return;
            }

            float currentAlpha = this.m_ListCanvasGroup.alpha;

            if (currentAlpha.Equals(targetAlpha))
            {
                return;
            }

            var floatTween = new FloatTween {
                duration = duration, startFloat = currentAlpha, targetFloat = targetAlpha
            };

            floatTween.AddOnChangedCallback(SetListAlpha);
            floatTween.AddOnFinishCallback(OnListTweenFinished);
            floatTween.ignoreTimeScale = ignoreTimeScale;
            this.m_FloatTweenRunner.StartTween(floatTween);
        }
Esempio n. 7
0
        /// <summary>
        /// Transition the scene out.
        /// </summary>
        /// <param name="transition">The transition.</param>
        /// <param name="duration">The transition duration.</param>
        /// <param name="easing">The transition easing.</param>
        public void TransitionOut(Transition transition, float duration, TweenEasing easing)
        {
            // Make sure the scene is active and enabled
            if (!this.isActiveAndEnabled || !this.gameObject.activeInHierarchy)
            {
                return;
            }

            if (this.m_CanvasGroup == null)
            {
                return;
            }

            // If no transition is used
            if (transition == Transition.None)
            {
                this.Deactivate();
                return;
            }

            // If the transition is animation
            if (transition == Transition.Animation)
            {
                this.TriggerAnimation(this.m_AnimateOutTrigger);
                return;
            }

            // Make the scene non interactable
            //this.m_CanvasGroup.interactable = false;
            //this.m_CanvasGroup.blocksRaycasts = false;

            // Prepare some variable
            Vector2 rectSize = this.rectTransform.rect.size;

            // Prepare the rect transform
            if (transition == Transition.SlideFromLeft || transition == Transition.SlideFromRight || transition == Transition.SlideFromTop || transition == Transition.SlideFromBottom)
            {
                // Anchor and pivot top left
                this.rectTransform.pivot            = new Vector2(0f, 1f);
                this.rectTransform.anchorMin        = new Vector2(0f, 1f);
                this.rectTransform.anchorMax        = new Vector2(0f, 1f);
                this.rectTransform.sizeDelta        = rectSize;
                this.rectTransform.anchoredPosition = new Vector2(0f, 0f);
            }

            // Prepare the tween
            FloatTween floatTween = new FloatTween();

            floatTween.duration = duration;

            switch (transition)
            {
            case Transition.CrossFade:
                this.m_CanvasGroup.alpha = 1f;
                // Start the tween
                floatTween.startFloat  = this.m_CanvasGroup.alpha;
                floatTween.targetFloat = 0f;
                floatTween.AddOnChangedCallback(SetCanvasAlpha);
                break;

            case Transition.SlideFromRight:
                // Start the tween
                floatTween.startFloat  = 0f;
                floatTween.targetFloat = (rectSize.x * -1f);
                floatTween.AddOnChangedCallback(SetPositionX);
                break;

            case Transition.SlideFromLeft:
                // Start the tween
                floatTween.startFloat  = 0f;
                floatTween.targetFloat = rectSize.x;
                floatTween.AddOnChangedCallback(SetPositionX);
                break;

            case Transition.SlideFromBottom:
                // Start the tween
                floatTween.startFloat  = 0f;
                floatTween.targetFloat = rectSize.y;
                floatTween.AddOnChangedCallback(SetPositionY);
                break;

            case Transition.SlideFromTop:
                // Start the tween
                floatTween.startFloat  = 0f;
                floatTween.targetFloat = (rectSize.y * -1f);
                floatTween.AddOnChangedCallback(SetPositionY);
                break;
            }

            // Start the transition
            floatTween.AddOnFinishCallback(OnTransitionOut);
            floatTween.ignoreTimeScale = true;
            floatTween.easing          = easing;
            this.m_FloatTweenRunner.StartTween(floatTween);
        }
        /// <summary>
        /// Raises the bar fill change event.
        /// </summary>
        /// <param name="amount">Amount.</param>
        public void OnBarFillChange(float amount)
        {
            // Calculate the bar fill based on it's width and value
            float fillWidth = ((float)this.bar.imageComponent.rectTransform.rect.width * this.bar.imageComponent.fillAmount);

            // Check if the fill width is too small to bother with the ending
            if (fillWidth <= (1f + (float)this.offset))
            {
                this.targetImage.gameObject.SetActive(false);
                return;
            }
            else if (!this.targetImage.gameObject.activeSelf)
            {
                // Re-enable
                this.targetImage.gameObject.SetActive(true);
            }

            // Position the ending at the end of the fill
            this.targetImage.rectTransform.anchoredPosition = new Vector2(
                (this.offset + fillWidth),
                this.targetImage.rectTransform.anchoredPosition.y
                );

            // Check if the fill width is too great to handle the ending width
            if (fillWidth < this.defaultFinishWidth)
            {
                // Change the width to the fill width
                this.targetImage.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, Mathf.Round(fillWidth));
            }
            else if (this.targetImage.rectTransform.rect.width != this.defaultFinishWidth)
            {
                // Restore default width
                this.targetImage.rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, this.defaultFinishWidth);
            }

            // Show / Hide the finish
            if (this.autoVisibility)
            {
                // Check if the finish needs the be shown
                if (this.bar.imageComponent.fillAmount >= this.showAfterPct && this.bar.imageComponent.fillAmount < this.hideAfterPct)
                {
                    // Fade in if not 100%
                    if (this.fading)
                    {
                        FloatTween floatTween = new FloatTween {
                            duration = this.fadeDuration, startFloat = this.canvasGroup.alpha, targetFloat = this.defaultFinishAlpha
                        };
                        floatTween.AddOnChangedCallback(SetFinishAlpha);
                        floatTween.ignoreTimeScale = true;
                        this.m_FloatTweenRunner.StartTween(floatTween);
                    }
                    else
                    {
                        this.SetFinishAlpha(this.defaultFinishAlpha);
                    }
                }
                else if (this.bar.imageComponent.fillAmount >= this.hideAfterPct || this.bar.imageComponent.fillAmount < this.showAfterPct)
                {
                    // Fade out at 100%
                    if (this.fading)
                    {
                        FloatTween floatTween = new FloatTween {
                            duration = this.fadeDuration, startFloat = this.canvasGroup.alpha, targetFloat = 0f
                        };
                        floatTween.AddOnChangedCallback(SetFinishAlpha);
                        floatTween.ignoreTimeScale = true;
                        this.m_FloatTweenRunner.StartTween(floatTween);
                    }
                    else
                    {
                        this.SetFinishAlpha(0f);
                    }
                }
            }
        }