목차

<note tip>DoTween 이나 LeanTwean 씁시다. 이게 더 나아요.</note>

DoTween

LeanTween

iTweenPath

iTweenPath로 iTween 움직임을 적용할 패스를 만들 수 있다.

어느 오브젝트든 상관없이,

패스를 적용하고 싶은 오브젝트에 아래 같은 스크립트를 추가

using UnityEngine;
using System.Collections;
 
public class MovingCube : MonoBehaviour {
void Start () {
  iTween.MoveTo( gameObject, 
		iTween.Hash(
			"time", 5,
			"path", iTweenPath.GetPath("cubepath1"),			
			"easetype", iTween.EaseType.easeInOutQuad,
			"looptype", iTween.LoopType.pingPong
		) );
}
}

iTween : Path를 사용한 이동 기능

임의의 오브젝트를 Path를 따라 움직이게 만든다. 움직이는 방향은 궤도 회전 방식.

  1. 패쓰로 사용할 빈 오브젝트를 , 생각한 경로 대로 만든다.
  2. 패스가 눈에 보이도록 OnDrawGizmos()에서 그려지는 스크립트를 추가한다.
    // 이런 식으로..
    void OnDrawGizmos() {
      Gizmos.DrawWireSphere(transform.position,.25f);	
    }
  3. 움직이려는 오브젝트에 아래와 같은 스크립트를 추가해서, 패쓰를 따라 오브젝트가 움직이게 한다. _path에 미리 만들어 놓은 빈 오브젝트를 차례대로 추가해서 경로를 완성한다.
    public Transform[] _path;
    void OnDrawGizmos() { 
      iTween.DrawPath( iTweenPath.GetPath("<PathName>") ); 
    }
    // iTween의 Path 파라미터에 _path를 추가해서 이 경로 만큼 이동하게 한다.
    void Start() {
      iTween.MoveTo( gameObject,
        iTween.Hash(
          "path",iTweenPath.GetPath("<PathName>"),
          "time",1,
          "easetype",iTween.EaseType.linear,
          "looptype",iTween.LoopType.loop,
          "movetopath",false)
      );
    }

iTween : 회전 샘플

랜덤한 회전과, 각 tween 방식을 확인하기 위한 샘플 코드

public class cubeTexture : MonoBehaviour
{
public float tweenTime = 3f;
// 인스펙터에서 직접 정하고 싶으면 코멘트 삭제
//public iTween.EaseType easeType = iTween.EaseType.easeOutExpo;
 
void Start ()
{
// tween 움직임을 랜덤하게 선택
iTween.EaseType _easytype = (iTween.EaseType)Random.Range( 0, 31 );
// 랜덤 로테이션으로 무작위 회전값을 얻고,
// "oncomplete" 옵션을 추가해서, 움직임이 끝나면 새로운 움직임을 새로 추가
iTween.RotateTo( gameObject, 
  iTween.Hash(
    "rotation", Random.rotation.eulerAngles,
    "time", tweenTime,
    "oncomplete","rotateTest",
    "easeType",_easytype ));
}
 
public void rotateTest()
{
iTween.EaseType _easytype = (iTween.EaseType)Random.Range( 0, 31 );
  iTween.RotateTo( gameObject, 
    iTween.Hash(
      "rotation", Random.rotation.eulerAngles,
      "time", tweenTime,
      "oncomplete","rotateTest",
      "easeType",_easytype ));
}
}

애니메이션 이징 (Tween or Easing)

이징 공식

공식의 적용 모드

각 움직임에 대한 라이브 데모

easing_demo.swf