iTween 官方链接:
http://www.pixelplacement.com/itween/index.php
通用的函数说明文档:
http://www.pixelplacement.com/itween/documentation.php
iTween 是一个动画库,作者创建它的目的就是最小的投入实现最大的产出,让你做开发更轻松,用它可以轻松实现各种动画,晃动,旋转,移动,褪色,上色,控制音频等等。其实 iTween的核心重点是数值插值,简单说就是给 iTween 两个数值(开始值,结束值),它会自动生成一些中间值,大概像这样子, 开始值->中间值 -> 中间值 …. -> 结束值。这里的数值可以理解为: 数字,坐标点,角度,物体大小,物体颜色,音量大小。整体的使用是蛮灵活和简单的。
下面小编这边直接进行关键函数功能的学习和分享哈。 1、Move:移动位置。 代码示例:
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
)
;
}
后面小编继续和大家分享更多的功能函数,例如音频方法Audio、Stab,颜色变化方法Color,iTweenPath类等。
iTween是一个强大的Unity动画库,可轻松实现移动、旋转、褪色等效果。本文详细介绍了iTween的Move函数,包括参数设置如速度、时间、路径等,以及如何使用事件处理动画的开始、更新和结束。

被折叠的 条评论
为什么被折叠?



