DOTween 사용법 (2) – Tweener
Tweener 는 DOTween 의 일개미로써, 속성 및 필드를 가져와서 주어진 값으로 애니메이션을 적용합니다. Tweener 를 사용하는데는 3가지 방법이 있는데 일반적인 방법, 간단한 방법, 추가적인 방법이 있습니다
1. 일반적인 방법
이 방법은 가장 유연한 방법이며 public or private, static or non-static 등 거의 모든 값을 tweening 할 수 있습니다.

// DOTween.To(getter, setter, to, duriation)
DOTween.To(() => Vector3.zero, x => transform.position = x, new Vector3(5, 0, 0), 1);
2. 간단한 방법
DOTween 은 몇가지 알려진 유니티 오브젝트 (예를 들면 Transform, Rigidbody 그리고 Material 등) 을 위한 간단하게 사용할 수 있는 방법이 있습니다.
DOColor(color, duration)
대상의 색을 변경합니다.

_material.DOColor(Color.red, 1)
DOFade(float, duration)
대상의 alpha 를 조절합니다. Material에서는 일부만 지원합니다.

_material.DOFade(0, 1)
DOMove(to, duration, snapping)
대상을 주어진 위치까지 주어진 시간 동안 이동합니다. snapping 을 활성화시키면 모든 값을 정수로 맞춥니다.

transform.DOMove(new Vector3(5, 0, 0), 1)
DORotate(endValue, duration)
대상을 주어진 값으로 주어진 시간 동안 회전시킵니다.

transform.DORotate(new Vector3(180, 0, 0), 1)
DOScale(to, duration)
대상을 주어진 값으로 주어진 시간 동안 변화시킵니다.

transform.DOScale(new Vector3(0.5f, 0.5f, 0.5f), 1)
DOText(to, direction, richTextEnabled, scrambleMode, scrambleChars)
대상을 주어진 값으로 tweening 합니다.

text.DOText("Hello, World!", 1);

text.DOText("Hello, World", 1, false, ScrambleMode.Uppercase);

text.DOText("<color=red> This is SECRET!</color>", 1, true, ScrambleMode.Custom, "*");
이렇게 DOTween 을 쓰지 않았다면 최소 5줄 이상의 코드를 작성해야 할 기능들을 간단하게 사용할 수 있게 만들어주는 라이브러리의 Tweener 부분을 살펴봤습니다.
포스팅을 하면서 간단한 게임을 만들어봤는데 생각보다 코드가 줄어드는 양이 많아서 놀랐습니다.
Leave a Reply
Want to join the discussion?Feel free to contribute!