是否有使用 C# 委托的 Unity3D 补间库?我一直在使用 iTween 和 LeanTween,但它们需要方法名称以字符串形式调用,而不是委托,这导致代码非常难看。我想用苗条的 lambda 替换所有自定义方法,但是这些库不提供这种功能。
问问题
2371 次
2 回答
0
不确定代表们,但这个小班从来没有让我失望
public class Tween {
public static float TweenValue (float from,float to,float time)
{
if (from != to)
{
if (Mathf.Abs(to-from) > 1.0)
{
from = Mathf.Lerp(from, to, time*Time.deltaTime);
}
else
{
from = to;
}
}
return from;
}
public static Rect TweenRect (Rect from,Rect to,float time){
if (from != to)
{
from.x = TweenValue (from.x,to.x,time*Time.deltaTime);
from.y = TweenValue (from.y,to.y,time*Time.deltaTime);
from.width = TweenValue (from.width,to.width,time*Time.deltaTime);
from.height = TweenValue (from.height,to.height,time*Time.deltaTime);
}
return from;
}
public static Vector3 TweenVector3 (Vector3 from ,Vector3 to,float time)
{
if (from != to)
{
if (Mathf.Abs((to-from).magnitude) > 0.2)
{
from = Vector3.Slerp(from, to, time);
}
else
{
from = to;
}
}
return from;
}
public static Quaternion TweenQuaternion (Quaternion from,Quaternion to,float time)
{
if (from != to)
{
if (Mathf.Abs((to.eulerAngles-from.eulerAngles).magnitude) > 0.2)
{
from = Quaternion.Slerp(from, to, time);
}
else
{
from = to;
}
}
return from;
}
}
于 2013-10-21T19:10:24.667 回答
0
新版本的 LeanTween 提供了不依赖字符串名称的 onComplete 和 onUpdate 委托。了解有关 LeanTween 2.0 中所有新功能的更多信息:http: //dentedpixel.com/developer-diary/leantween-2-0-faster-type-safe-and-c/
于 2014-01-03T18:50:35.437 回答