1,五種移動方法;2, 函數的基礎屬性及用法php
原文地址:http://blog.csdn.net/dingkun520wy/article/details/50476864數組
iTween官網:http://itween.pixelplacement.com/index.php函數
1,五種移動方法oop
MoveTo:從原始位置移動到目標位置。動畫
MoveFrom:從目標位置移動到原始位置。spa
MoveAdd:隨時間移動遊戲對象的位置,根據提供的量。.net
MoveBy:增長提供的座標到遊戲對象的位置。(與MoveAdd同樣)code
MoveUpdate:相似於MoveTo,在Update()或FixedUpdate()方法或循環環境中調用。提供每幀改變屬性值的環境。不依賴於EasrType.orm
動畫的方法通常有兩種重載,對象
a,最小定製選項,只須要提供最少必需參數
//target:要移動的物體;position:要移動的位置;time:動畫的運行的時間
public static void MoveUpdate(GameObject target, Vector3 position, float time);
b,徹底定製選項,可定製全部的參數
//target:要移動的物體;args:定製的數組
public static void MoveUpdate(GameObject target, Hashtable args);
定製移動路徑iTweenPath 詳細講解: http://blog.csdn.net/dingkun520wy/article/details/51075774
2, 函數的基礎屬性及用法
基礎屬性比較簡單直接上代碼
[csharp] view plain copy
void Start () {
//鍵值對兒的形式保存iTween所用到的參數
Hashtable args = new Hashtable();
//這裏是設置類型,iTween的類型又不少種,在源碼中的枚舉EaseType中
//例如移動的特效,先震動在移動、前後退在移動、先加速在變速、等等
args.Add("easeType", iTween.EaseType.easeInOutExpo);
//移動的速度,
//args.Add("speed",10f);
//移動的總體時間。若是與speed共存那麼優先speed
args.Add("time",10f);
//這個是處理顏色的。能夠看源碼的那個枚舉。
args.Add("NamedValueColor","_SpecColor");
//延遲執行時間
args.Add("delay", 0.1f);
//是否讓遊戲對象始終面朝路徑行進的方向,拐彎的地方會自動旋轉。
args.Add("orienttopath", true);
//移動的過程當中面朝一個點,當「orienttopath」爲true時該參數失效
args.Add("looktarget",Vector3.zero);
//遊戲對象看向「looktarget」的秒數。
args.Add("looktime",1.1);
//遊戲對象移動的路徑能夠爲Vector3[]或Transform[] 類型。可經過iTweenPath編輯獲取路徑
Vector3[] testPath = { new Vector3(0, 0, 0), new Vector3(0, 1, 0), new Vector3(0, 1, 1), new Vector3(1, 1, 1), new Vector3(1, 5, 1) };
args.Add("path", testPath);
//是否移動到路徑的起始位置(false:遊戲對象當即處於路徑的起始點,true:遊戲對象將從原是位置移動到路徑的起始點)
args.Add("movetopath", false);
//當包含「path」參數且「orienttopath」爲true時,該值用於計算「looktarget」的值,表示遊戲物體看着前方點的位置,(百分比,默認0.05)
args.Add("lookahead",0.01);
//限制僅在指定的軸上旋轉
args.Add("axis", "x");
//是否使用局部座標(默認爲false)
args.Add("islocal", false);
//三個循環類型 none loop pingPong (通常 循環 來回)
//args.Add("loopType", "none");
//args.Add("loopType", "loop");
args.Add("loopType", iTween.LoopType.pingPong);
//處理移動過程當中的事件。
//開始發生移動時調用AnimationStart方法,5.0表示它的參數
args.Add("onstart", "AnimationStart");
args.Add("onstartparams", 5.0f);
//設置接受方法的對象,默認是自身接受,這裏也能夠改爲別的對象接受,
//那麼就得在接收對象的腳本中實現AnimationStart方法。
args.Add("onstarttarget", gameObject);
//移動結束時調用,參數和上面相似
args.Add("oncomplete", "AnimationEnd");
args.Add("oncompleteparams", "end");
args.Add("oncompletetarget", gameObject);
//移動中調用,參數和上面相似
args.Add("onupdate", "AnimationUpdate");
args.Add("onupdatetarget", gameObject);
args.Add("onupdateparams", true);
// x y z 標示移動的位置。
args.Add("x",-5);
args.Add("y",1);
args.Add("z",1);
//固然也能夠寫Vector3
//args.Add("position",Vectoe3.zero);
//最終讓改對象開始移動
iTween.MoveTo(btnBegin, args);
}
//對象移動中調用
void AnimationUpdate(bool f)
{
Debug.Log("update :" + f);
}
//對象開始移動時調用
void AnimationStart(float f)
{
Debug.Log("start :" + f);
}
//對象移動時調用
void AnimationEnd(string f)
{
Debug.Log("end : " + f);
}