Ejemplo n.º 1
0
        public static IDisposable AnimationSize(this RectTransform _rectTransform, Vector2 _target, float _duration, Easing.Ease _ease = Easing.Ease.EaseInOutQuad, Action _completed = null)
        {
            var progress    = 0f;
            var rect        = _rectTransform.rect;
            var currentSize = new Vector2(rect.width, rect.height);

            int     milliseconds = Mathf.RoundToInt(_duration * 1000f);
            Vector2 valueTarget;

            return(LerpThread
                   .Execute
                   (
                       milliseconds,
                       _count =>
            {
                progress += Time.deltaTime / _duration;

                valueTarget.x = EasingFormula.EasingFloat(_ease, currentSize.x, _target.x, progress);
                valueTarget.y = EasingFormula.EasingFloat(_ease, currentSize.y, _target.y, progress);

                _rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, valueTarget.y);
                _rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, valueTarget.x);
            },
                       () =>
            {
                valueTarget = _target;
                _rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, valueTarget.y);
                _rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, valueTarget.x);

                _completed?.Invoke();
            }
                   ));
        }
Ejemplo n.º 2
0
        public static IDisposable AnimationHeight(this RectTransform _rectTransform, float _target, float _duration, Easing.Ease _ease = Easing.Ease.EaseInOutQuad, Action _completed = null)
        {
            var progress      = 0f;
            var currentHeight = _rectTransform.rect.height;

            int   milliseconds = Mathf.RoundToInt(_duration * 1000f);
            float valueTarget;


            return(LerpThread
                   .Execute
                   (
                       milliseconds,
                       _count =>
            {
                progress += Time.deltaTime / _duration;

                valueTarget = EasingFormula.EasingFloat(_ease, currentHeight, _target, progress);
                _rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, valueTarget);
            },
                       () =>
            {
                valueTarget = _target;
                _rectTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, valueTarget);

                _completed?.Invoke();
            }
                   ));
        }
Ejemplo n.º 3
0
        public static IDisposable AnimationTranslate(this RectTransform _rectTransform, Vector2 _target, float _duration, Easing.Ease _ease = Easing.Ease.EaseInOutQuad, Action _completed = null)
        {
            var progress     = 0f;
            var current      = _rectTransform.anchoredPosition;
            int milliseconds = Mathf.RoundToInt(_duration * 1000f);

            Vector2 valueTarget;

            return(LerpThread
                   .Execute
                   (
                       milliseconds,
                       _count =>
            {
                progress += Time.deltaTime / _duration;

                valueTarget.x = EasingFormula.EasingFloat(_ease, current.x, _target.x, progress);
                valueTarget.y = EasingFormula.EasingFloat(_ease, current.y, _target.y, progress);
                _rectTransform.anchoredPosition = valueTarget;
            },
                       () =>
            {
                valueTarget = _target;
                _rectTransform.anchoredPosition = valueTarget;
                _completed?.Invoke();
            }
                   ));
        }
Ejemplo n.º 4
0
        //--------------------------------------------------------------------------------------------------------------

        public static IDisposable LerpAlpha(this Text _source, int _milliseconds, float _target)
        {
            var progress  = 0f;
            var current   = _source.color.a;
            var different = _target - current;

            return(LerpThread
                   .Execute
                   (
                       _milliseconds,
                       _count =>
            {
                progress += Time.deltaTime / (_milliseconds * GlobalConstant.MILLISECONDS_TO_SECONDS);
                _source.SetAlpha(Mathf.Clamp01(current + progress * different));
            },
                       () => _source.SetAlpha(Mathf.Clamp01(_target))
                   ));
        }
Ejemplo n.º 5
0
        //--------------------------------------------------------------------------------------------------------------

        public static IDisposable LerpAlpha(this CanvasGroup _source, int _milliseconds, float _target, bool _adjustInteractAble = true, Action _onComplete = null)
        {
            var progress  = 0f;
            var current   = _source.alpha;
            var different = _target - current;

            return(LerpThread
                   .Execute
                   (
                       _milliseconds,
                       _count =>
            {
                progress += Time.deltaTime / (_milliseconds * GlobalConstant.MILLISECONDS_TO_SECONDS);
                _source.SetAlpha(Mathf.Clamp01(current + progress * different), _adjustInteractAble);
            },
                       () =>
            {
                _source.SetAlpha(Mathf.Clamp01(_target), _adjustInteractAble);
                _onComplete?.Invoke();
            }
                   ));
        }