什么是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



对象的移动函数原型:
[csharp]

  • MoveTo(GameObject target, Vector3 position, float time)
  • MoveTo(GameObject target, Hashtable args)


MoveTo(GameObject target, Vector3 position, float time)
MoveTo(GameObject target, Hashtable args)
用法示例:
[csharp]

using UnityEngine;

  • using System.Collections;
  • public class Test : MonoBehaviour
  • {
  •     // 是否正在播放动画
  •     private bool isInAnim = false;
  •     Hashtable ht = new Hashtable();
  •     // Use this for initialization
  •     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);
  •     }
  •     // Update is called once per frame
  •     void Update()
  •     {
  •         if (! isInAnim)
  •         {
  •             iTween.MoveTo(this.gameObject, ht);
  •             isInAnim = true;
  •         }
  •     }
  • }