投稿日:2011-07-13 Wed
Pです。Unityの便利ライブラリ「iTween」について備忘録です(C#用)
本当はもっと複雑な動きや色変化なども実装できるみたいなのですが
最もよく使うと思われるTransform系のみです。
●アニメーションの開始
【移動】
iTween.MoveTo(GameObject型, Hashtable型);
【拡大・縮小】
iTween.ScaleTo(GameObject型, Hashtable型);
【回転】
iTween.RotateTo(GameObject型, Hashtable型);
●アニメーションの強制終了
iTween.Stop(GameObject型);
●第二引数「Hashtable型」に指定する主なパラメータ
time アニメにかける時間[秒]。speedと重複指定できない
デフォルト:1f
delay アニメ開始までの待機時間[秒]
デフォルト:0f
speed スピード。timeと重複指定できない
※speedの単位が不明。数値が大きいほどアニメーションも速くなるようだが
looptype ループするかしないか
デフォルト:iTween.LoopType.none
easetype イージング関数
デフォルト:iTween.EaseType.easeOutExpo
※イージング有りがデフォルトなので注意!
onupdate アニメーション中毎フレーム呼ばれる
onupdatetarget onupdateが呼び出されるtarget
onupdateparams onupdateにパラメータを送ることができる
oncomplete アニメーション完了時に呼ばれる
oncompletetarget oncompleteが呼び出されるtarget
oncompleteparams oncompleteにパラメータを送ることができる
●使用例
・自身を0.5秒間でx=2.5fまで移動
Hashtable hash = iTween.Hash("x",2.5f,"time",0.5f);
iTween.MoveTo(gameObject, hash);
・GameObject「ball」を2秒間でy=5f, z=5fに拡大
Hashtable hash = iTween.Hash("y",5f,"z",5f,"time",2f);
iTween.ScaleTo(ball, hash);
・GameObject「ship」をyの角度120度に回転
Hashtable hash = iTween.Hash("y",120f,"speed",60f,"easetype",iTween.EaseType.linear);
iTween.RotateTo(ship, hash);
・oncompleteparamsを使用
「MySphere.cs」
using UnityEngine;
using System.Collections;
public class MySphere : MonoBehaviour {
public GameObject targetObject;
void Start () {
MyObject mo;
mo.hoge = 3;
mo.huga = "abcde";
Hashtable hash = iTween.Hash(
"y",10f,
"time",2.5f,
"oncomplete","onComplete",
"oncompleteparams",mo);
iTween.MoveTo(targetObject, hash);
}
public struct MyObject {
public int hoge;
public string huga;
}
}
「MyCube.cs」
using UnityEngine;
using System.Collections;
public class MyCube : MonoBehaviour {
void onComplete(MySphere.MyObject mo) {
Debug.Log("MyCube.onComplete, " + mo.hoge + ", " + mo.huga);
//出力:MyCube.onComplete, 3, abcde
}
}
△ PAGE UP