Skip to content

Instantly share code, notes, and snippets.

@lycoris102
Last active July 29, 2020 15:13
Show Gist options
  • Save lycoris102/c447130ac1e02f83de8e644b2849459b to your computer and use it in GitHub Desktop.
Save lycoris102/c447130ac1e02f83de8e644b2849459b to your computer and use it in GitHub Desktop.
using DG.Tweening;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
[RequireComponent(typeof(TextMeshProUGUI))]
public class TextAnimation : MonoBehaviour, IDragHandler, IBeginDragHandler
{
private TextMeshProUGUI text;
private TextMeshProUGUI Text => text ?? (text = GetComponent<TextMeshProUGUI>());
private DOTweenTMPAnimator animator;
private DOTweenTMPAnimator Animator => animator ?? (animator = new DOTweenTMPAnimator(Text));
public void OnDrag(PointerEventData e)
{
var index = TMP_TextUtilities.FindIntersectingCharacter(Text, Input.mousePosition, Text.canvas.worldCamera, true);
if (index == -1) return;
DOTween.Sequence()
.Append(Animator.DOOffsetChar(index, new Vector3(0, 200, 0), 0.5f).SetEase(Ease.OutCubic))
.Join(Animator.DOFadeChar(index, 0, 0.5f))
.Join(Animator.DOScaleChar(index, 0, 0.5f))
.Play();
}
public void OnBeginDrag(PointerEventData eventData)
{
}
}
@lycoris102
Copy link
Author

DOTweenPro (有償版) が前提です
(TextMeshPro向けの拡張が用意されているため)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment