Float Value Motion

One of the most basic motions one might want to create is the Float Value. The idea behind it is that it allows creating any kind of animation you need. Now be careful when you are using this because if you have a motion that can be reused and applied to other objects you might want to create your own motion. But if you just want a quick fix for a specific animation, Float Value is the way to go. Here is a usage example for it:


new Tween(1f).Value(0f, 3f, (t) => transform.localPosition = Vector3.one * t).Start();

This simple animation will move the transform from 0,0,0 to 3,3,3. The reason you want to use the Float Value motion is that you can apply tweening settings (easings, delays, etc) to the motion.

Here is an example using the motion directly and not the extension method.

new Tween(1f).Apply(new FloatValueMotion(0f, 3f, (t) => transform.localPosition = Vector3.one * t)).Start();

Before we end, here is the source code for the motion. (Quite basic, right?)

public class FloatValueMotion : AbstractValueMotion<float>
{
    [Serializable]
    public class Builder : AbstractBuilder
    {
        public override ITweenMotion Build()
            => new FloatValueMotion(from, to, GetCallback());
    }

    public FloatValueMotion(float from, float to, Action<float> onUpdated) : base(from, to, onUpdated)
    {
    }

    protected override Func<float, float, float, float> LerpFunction => Mathf.LerpUnclamped;
}

Comments

Popular Posts