1

Is there a Unity3D tween library that uses C# delegates? I've been using iTween and LeanTween, but instead of delegates they require method names to call in form of strings, which results in quite ugly code. I'd like to replace all the custom methods with slim lambdas, but these libraries don't provide such capability.

Max Yankov
  • 12,551
  • 12
  • 67
  • 135
  • I don't know. Honestly tweening isn't that hard, and it's quite funny. Personally I implemented my own lib (of course using delegates). Why don't you try to write your own code? – Heisenbug Oct 15 '13 at 15:57
  • 1
    Because I like to use existing solutions rather then invent them again ;) – Max Yankov Oct 15 '13 at 17:18
  • 1
    Have you tried Prime31's GoKit? http://prime31.com/docs#goKit It seems to use `Action onComplete` as an argument for Tweens. – Calvin Oct 16 '13 at 00:38

2 Answers2

0

Not sure about the delegates but this small class has never let me down

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;
    }   
}
MichaelTaylor3D
  • 1,615
  • 3
  • 18
  • 32
0

The new version of LeanTween offers onComplete and onUpdate delegates that do not rely on string names. Find out more about all the new features in LeanTween 2.0: http://dentedpixel.com/developer-diary/leantween-2-0-faster-type-safe-and-c/

marfastic
  • 405
  • 3
  • 7