Move Motion

For the first motion I will talk about the simplest and most common motion used in both script and key-based animations: Move

FlowEnt comes by default with a considerable set of Move motions that can be used to move a transform(RectTransforms too!)

The animation can consist of a Vector3d or just one axis that one might want to animate, and they can be applied in both global and local space.

Here are some examples:

transform.Tween(1f).Move(Vector3.right);
transform.Tween(1f).MoveX(1f);
transform.Tween(1f).MoveLocal(Vector3.left);
transform.Tween(1f).MoveLocalX(-1f);

Here we move the transform left or right, in global or local spaces.

Here is the code for an actual motion:

public class MoveVectorMotion : AbstractVector3Motion<Transform>
{
    [Serializable]
    public class ValueBuilder : AbstractValueBuilder
    {
        public override ITweenMotion Build()
            => new MoveVectorMotion(item, value);
    }

    [Serializable]
    public class FromToBuilder : AbstractFromToBuilder
    {
        public override ITweenMotion Build()
            => new MoveVectorMotion(item, from, to);
    }

    public MoveVectorMotion(Transform item, Vector3 value) : base(item, value)
    {
    }

    public MoveVectorMotion(Transform item, Vector3? from, Vector3 to) : base(item, from, to)
    {
    }

    protected override Vector3 GetFrom() => item.position;
    protected override void SetValue(Vector3 value) => item.position = value;
}

Comments

Popular Posts