什么是iTween?
iTween是一个动画库,用它可以轻松实现各种动画、晃动、旋转、移动、褪色、上色、控制音频等
iTween的使用
从http://itween.pixelplacement.com/下载相应的插件(就一个cs文件),然后导入到unity3d工程中
可以干的事情
- 控制音频:AudioFrom、AudioTo、AudioUpdate、Stab
- 控制相机:CameraFadeAdd、CameraFadeDepth、CameraFadeDestroy、CameraFadeSwap、CameraFadeFrom、CameraFadeTo、CameraTexture
- 变色控制:ColorFrom、ColorTo、ColorUpdate
- 绘制相关:DrawLine、DrawLineGizmos、DrawLineHandles、DrawPath、DrawPathGizmos、DrawPathHandles
- 淡入淡出:FadeFrom、FadeTo、FadeUpdate
- 视角控制:LookFrom、LookTo、LookUpdate、LookType
- 移动控制:MoveAdd、MoveBy、MoveFrom、MoveTo、MoveUpdate
- 路径操作:PutOnPath、PointOnPath
- 旋转操作:RotateAdd、RotateBy、RotateFrom、RotateTo、RotateUpdate
- 缩放操作:ScaleAdd、ScaleBy、ScaleFrom、ScaleTo、ScaleUpdate
- 震动控制:ShakePosition、ShakeRotation、ShakeScale
- 其他:Count、PathLength、EaseType(衰减类型)、FloatUpdate、Hash、Init、Pause、Resume、Stop、StopByName、PunchPosition、PunchRotation、PunchScale、RectUpdate、ValueTo、Vector2Update、Vector3Update
对象的移动
函数原型:
- MoveTo(GameObject target, Vector3 position, float time)
- MoveTo(GameObject target, Hashtable args)
用法示例:
- using UnityEngine;
- using System.Collections;
-
- public class Test : MonoBehaviour
- {
-
- private bool isInAnim = false;
-
- Hashtable ht = new Hashtable();
-
-
- void Start()
- {
-
- ht.Add("time", 8.0f);
- ht.Add("delay", 1.0f);
- ht.Add("position", new Vector3(0, 4, 0));
-
-
- ht.Add("x", 1.0f);
- ht.Add("y", 2.0f);
- ht.Add("z", 1.0f);
-
-
- ht.Add("orienttopath", true);
-
-
- ht.Add("looktarget", new Vector3(0, 0, 0));
-
-
- Vector3[] path =
- {
- new Vector3(0, 0, 0),
- new Vector3(1, 1, 0),
- new Vector3(1, 3, 0),
- new Vector3(4, 4, 0)
- };
- ht.Add("path", path);
-
-
- ht.Add("onstart", "onAnimationStart");
- ht.Add("onstarttarget", this.gameObject);
- ht.Add("onstartparams", this.gameObject.name);
-
-
- ht.Add("onupdate", "onAnimationUpdate");
- ht.Add("onupdatetarget", this.gameObject);
- ht.Add("onupdateparams", this.gameObject.name);
-
-
- ht.Add("oncomplete", "onAnimationEnd");
- ht.Add("oncompletetarget", this.gameObject);
- ht.Add("oncompleteparams", this.gameObject.name);
- }
-
-
- void Update()
- {
- if (! isInAnim)
- {
- iTween.MoveTo(this.gameObject, ht);
- isInAnim = true;
- }
- }
- }