Notice
Recent Posts
Recent Comments
Link
«   2024/09   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
Archives
Today
Total
관리 메뉴

폐관수련

DOTween 본문

Programming/unity

DOTween

믜믜 2021. 10. 26. 15:06

DOTween

C#에 최적화된 빠르고 효율적인 객체 지향 애니메이션 엔진.

빠르고 간편하다는데......

 

http://dotween.demigiant.com/index.php

 

DOTween (HOTween v2)

DOTween is a fast, efficient, fully type-safe object-oriented animation engine for Unity, optimized for C# users, free and open-source, with tons of advanced features It is also the evolution of HOTween, my previous Unity tween engine. Compared to it, DOTw

dotween.demigiant.com

공식 홈페이지에 (영어지만) 사용법과 예제가 아주 친절하게 나와있다.

예제는 별로 없다..

 

사용 준비

https://assetstore.unity.com/packages/tools/animation/dotween-hotween-v2-27676

 

DOTween (HOTween v2) | 애니메이션 도구 | Unity Asset Store

Use the DOTween (HOTween v2) tool from Demigiant on your next project. Find this & more animation tools on the Unity Asset Store.

assetstore.unity.com

에셋 스토어에서 무료 버전을 내 에셋으로 추가한다.

유료 버전도 있는데 여기서는 무료 버전만 사용한다.

 

Window-Package Manager에서 선택한 후 우측 하단 Import

 

using DG.Tweening;

 

클래스나 스크립트에 네임스페이스를 추가한 뒤 사용한다.

 

용어 정리

  • tweener : 값을 제어하고 애니메이션을 적용하는 tween
  • sequence : 값을 제어하는 대신 다른 tween을 제어하고 그룹으로 애니메이션하는 특수 tween
  • tween : tweener와 sequence를 모두 나타내는 일반적인 단어

 

 

초기화

사용하기 전, 초기화 메서드를 이용하여 사용자가 직접 초기화 하는 것을 추천한다고 한다.

직접 초기화 하지 않아도 상관은 없다.

DOTween.Init();		// DOTween 패널에 설정한 값으로 초기화

// static DOTween.Init(bool recycleAllByDefault = false, bool useSafeMode = true, LogBehaviour logBehaviour = LogBehaviour.ErrorsOnly)
DOTween.Init(true, true, LogBehaviour.Verbose).SetCapacity(200, 10);	// 사용자 초기화

// SetCapacity를 사용할 경우 트윈과 시퀀스의 초기 용량을 설정할 수 있다

 

recycleAllByDefault

true일 경우 모든 새 tween이 재활용되어 풀에 넣어지고 재사용된다. GC 할당을 피할 수 있지만 tween이 제거되어도 참조가 살아있을 수 있으므로 참조 처리를 잘 해주어야 한다. (무슨 소린지..)

.OnKill(()=> myTweenReference = null)	// 트윈 삭제시 자동으로 트윈 참조를 null로 만들어준다​

언제든지 DOTween.defaultRecyclable 프로퍼티로 설정을 변경할 수 있다.

또한 SetRecyclable로 재사용 여부를 각각 tween에 적용할 수 있다.

 

UseSafeMode

true일 경우 약간 느려지지만 안전해진다. 자동으로 처리해주는 것들이 있나보다.

 

logBehaviour

로그를 무엇을 남길지 선택한다.

 

 

Tweeners

DOTween의 작업 단위같은 개념. 속성/필드 값을 가져와서 주어진 값으로 애니메이션한다.

Tweener를 만드는 방법은 세 가지가 있다. (마지막 방법은 매뉴얼을 참고하자)

 

The generic way

// DOTween.To(getter, setter, to, float duration)
// getter : 속성 값을 tween에 반환하는 대리자. 초기값. 람다로 작성 가능.
// setter : 속성 값을 tween으로 설정하는 대리자. 변화되는 값을 매개변수로 하는 함수 정의. 람다로 작성 가능.
// to : 최종 목표값.
// duration : 지속 시간.

DOTween.To(() => myColor.color, x => myColor.color = x, Color.magenta, 5.0f);
DOTween.To(() => txt.text, x => txt.text = x, "Hello world!", 1.0f);

DOTween.To(() => myColor.color, x => myColor.color = x, Color.magenta, 5.0f).From();
DOTween.To(() => txt.text, x => txt.text = x, "Hello world!", 1.0f).From();

Tweening 방법 중에 제일 유연한 방법이며 사용자가 거의 대부분의 값들을 tween 할 수 있다.

From() chain을 지원한다.

 

The Shortcuts way

myColor.DOColor(Color.magenta, 5.0f);
txt.DOText("Hello world!", 1.0f);

myColor.DOColor(Color.magenta, 5.0f).From();
txt.DOText("Hello world!", 1.0f).From();

유니티 오브젝트에 미리 만들어져 있어 간단하게 사용할 수 있다.

From() chain을 지원한다.

 

 

Sequence

sequence는 tweener와 비슷하지만 프로퍼티나 값을 애니메이팅 하는 대신, 다른 tweener들이나 sequence들을 그룹으로서 애니메이트한다.

계층의 깊이 제한 없이 다른 sequence 안에 포함될 수 있다.

동일한 tween을 여러 sequence에서 재사용할 수 없다.

빈 sequence를 사용할 수 없다.

'Programming > unity' 카테고리의 다른 글

이벤트 함수  (0) 2021.11.02
코루틴 (Coroutine)  (0) 2021.10.29
스프라이트 (Sprite)  (0) 2021.10.22
Comments