2013-10-15 107 views
0

是否有使用C#委託的Unity3D補間庫?我一直在使用iTween和LeanTween,但代替它們需要方法名稱以字符串形式調用,這會導致代碼非常難看。我想用苗條lambda來替換所有的自定義方法,但是這些庫不提供這樣的功能。使用C#委託的Unity3D吐溫庫

+0

我不知道。誠實補間並不難,而且很有趣。我個人實現了我自己的lib(當然使用代表)。你爲什麼不嘗試編寫自己的代碼? – Heisenbug

+0

因爲我喜歡使用現有的解決方案,而不是再發明它們;) –

+1

您是否嘗試過Prime31的GoKit? http://prime31.com/docs#goKit它似乎使用'Action onComplete'作爲Tweens的參數。 – Calvin

回答

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; 
    } 
}