Last active
July 29, 2020 15:13
-
-
Save lycoris102/c447130ac1e02f83de8e644b2849459b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
{ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
DOTweenPro (有償版) が前提です
(TextMeshPro向けの拡張が用意されているため)