private Sequence BounceIn(TMP_Text text, float distance = 50, int?charsAhead = null)
        {
            Sequence    textSequence = DOTween.Sequence();
            CharTweener tweener      = text.GetCharTweener();

            int count = charsAhead ?? tweener.CharacterCount;

            for (int i = 0; i < count; i++)
            {
                tweener.SetAlpha(i, 0);
                tweener.SetLocalEulerAngles(i, Vector3.forward * 45);
                tweener.SetLocalScale(i, 1);
                tweener.ResetPosition(i);
                tweener.UpdateCharProperties();
            }

            for (int i = 0; i < count; i++)
            {
                Sequence charSequence = DOTween.Sequence();
                charSequence.Insert(0, tweener.DOFade(i, 1, 1));
                charSequence.Insert(0, tweener.DOOffsetMoveY(i, distance, 0.25f).SetEase(Ease.OutCubic));
                charSequence.Insert(0.25f, tweener.DOOffsetMoveY(i, 0, 0.75f).SetEase(Ease.OutBounce));
                charSequence.Insert(0.25f, tweener.DOLocalRotate(i, Vector3.zero, 0.75f).SetEase(Ease.OutBounce));
                textSequence.Insert((float)i / count, charSequence);
            }

            textSequence.SetTarget(text);
            return(textSequence);
        }
Example #2
0
        // Sequence example, bubbly fade-in + bounce
        private void Tween3(int start, int end)
        {
            var sequence = DOTween.Sequence();

            for (var i = start; i <= end; ++i)
            {
                var timeOffset   = Mathf.Lerp(0, 1, (i - start) / (float)(end - start + 1));
                var charSequence = DOTween.Sequence();
                charSequence.Append(_tweener.DOLocalMoveY(i, height, 0.5f).SetEase(Ease.InOutCubic))
                .Join(_tweener.DOFade(i, 0, 0.5f).From())
                .Join(_tweener.DOScale(i, 0, 0.5f).From().SetEase(Ease.OutBack, 5))
                .Append(_tweener.DOLocalMoveY(i, 0, 0.5f).SetEase(Ease.OutBounce));
                sequence.Insert(timeOffset, charSequence);
            }

            sequence.SetLoops(-1, LoopType.Yoyo);
        }
Example #3
0
    // Char tween: bubbly fade-in + bounce
    private void TweenBubble(int start, int end, float duration, float scale, Action onComplete)
    {
        var sequence = DOTween.Sequence();

        for (var i = start; i < end; ++i)
        {
            var timeOffset   = Mathf.Lerp(0, duration, (i - start) / (float)(end - start + duration));
            var charSequence = DOTween.Sequence();
            charSequence.Append(_tweener.DOLocalMoveY(i, 0.5f, duration).SetEase(Ease.InOutCubic))
            .Join(_tweener.DOFade(i, 0, duration).From())
            .Join(_tweener.DOScale(i, 0, duration).From().SetEase(Ease.OutBack, scale))
            .Append(_tweener.DOLocalMoveY(i, 0, duration).SetEase(Ease.OutBounce));
            sequence.Insert(timeOffset, charSequence);
        }
        sequence.Play().AppendCallback(() => onComplete());
    }
        private Sequence ScaleOut(TMP_Text text, float distance = 100, int?charsAhead = null)
        {
            Sequence    textSequence = DOTween.Sequence();
            CharTweener tweener      = text.GetCharTweener();

            int count = charsAhead ?? tweener.CharacterCount;

            for (int i = 0; i < count; i++)
            {
                Sequence charSequence = DOTween.Sequence();
                charSequence.Insert(0, tweener.DOFade(i, 0, 0.5f).SetEase(Ease.InCubic));
                charSequence.Insert(0, tweener.DOScale(i, 0, 0.5f).SetEase(Ease.InBack));
                textSequence.Insert((float)i / count * 0.5f, charSequence);
            }

            textSequence.SetTarget(text);
            return(textSequence);
        }
Example #5
0
        private void PrepareTween(Playable playable)
        {
            var duration = (float)playable.GetDuration();
            var charAnimationDuration = duration * (1 + overlap) / charTweener.CharacterCount;
            var charStartOffset       = charAnimationDuration * (1 - overlap);

            sequence = DOTween.Sequence();
            sequence.AppendCallback(() => sequence = null);

            for (var i = 0; i < charTweener.CharacterCount; ++i)
            {
                var timeOffset = charStartOffset * i;

                var stepDuration = charAnimationDuration / 4;

                var charSequence = DOTween.Sequence();
                charSequence.Append(charTweener.DOLocalMoveY(i, 0.5f, stepDuration).SetEase(Ease.InOutCubic))
                .Join(charTweener.DOFade(i, 0, stepDuration).From())
                .Join(charTweener.DOScale(i, 0, stepDuration).From().SetEase(Ease.OutBack, 5))
                .Append(charTweener.DOLocalMoveY(i, 0, stepDuration).SetEase(Ease.OutBounce));
                sequence.Insert(timeOffset, charSequence);
            }
        }
Example #6
0
    // Animation to typewrite text
    // Returns total time it'll take for this animation to complete
    public Sequence Show(string s, float duration, float delay = 0)
    {
        text.text = s;

        if (duration > 0.011f)
        {
            text.ForceMeshUpdate();
            int count = text.textInfo.characterCount;

            // Create new animation
            showSequence = DOTween.Sequence();
            float puncDelay  = Mathf.Max(duration * 1.5f, MIN_PUNCTUATION_DELAY);
            float charDelays = 0;

            for (var i = 0; i < count; i++)
            {
                var timeOffset   = Mathf.Lerp(0, 1, (i) / (float)(count + 1));
                var charSequence = DOTween.Sequence();
                charSequence.Append(_tweener.DOFade(i, 0, duration * 2f + 0.2f).From().SetEase(Ease.InOutCubic))
                .Join(_tweener.DOScale(i, 0, duration).From().SetEase(Ease.OutBack, 5))
                .SetDelay(charDelays);

                char c = text.textInfo.characterInfo[i].character;
                if (c == '.' || c == ',' || c == ':' || c == ';' || c == '!' || c == '?')
                {
                    charDelays += puncDelay;
                }

                showSequence.Insert(timeOffset, charSequence);
            }

            showSequence.SetDelay(delay).Play();
            return(showSequence);
        }
        return(null);
    }