[英]Unity3D Tween library that uses C# delegates
是否存在使用C#委托的Unity3D補間庫? 我一直在使用iTween和LeanTween,但是它們不是委托,而是需要方法名稱以字符串形式調用,這導致代碼很丑陋。 我想用苗條的lambda替換所有自定義方法,但是這些庫不提供這種功能。
不確定代表們,但這個小班從來沒有讓我失望
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;
}
}
新版本的LeanTween提供了不依賴字符串名稱的onComplete和onUpdate委托。 了解有關LeanTween 2.0中所有新功能的更多信息: http ://dentedpixel.com/developer-diary/leantween-2-0-faster-type-safe-and-c/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.