AnnulusGames / LitMotion

Lightning-fast and Zero Allocation Tween Library for Unity.
https://annulusgames.github.io/LitMotion/
MIT License
841 stars 66 forks source link

Add `MotionSettings` and remove `MotionBuilder.Preserve()` #149

Closed AnnulusGames closed 3 days ago

AnnulusGames commented 3 days ago

This PR adds MotionSettings<TValue, TOptions>. This makes it possible to save settings in advance when creating motions with the same parameters multiple times. MotionSettings can be created from MotionBuilder in the same way as normal motions.

var setting = LMotion.Create(0f, 10f, 2f)
    .WithEase(Ease.OutQuad)
    .WithLoops(-1, LoopType.Yoyo)
    .WithScheduler(MotionScheduler.FixedUpdate)
    .ToMotionSettings();

LMotion.Create(setting)
    .Bind(x => {  });

Also, SerializableMotionSettings are MotionSettings that can be edited from the Inspector.

using LitMotion;
using LitMotion.Extensions;
using UnityEngine;

public class Sandbox : MonoBehaviour
{
    [SerializeField] Transform target;
    [SerializeField] SerializableMotionSettings<float, NoOptions> settings;

    void Start()
    {
        LMotion.Create(settings)
            .WithOnComplete(() => Debug.Log("Complete"))
            .BindToPositionX(target)
            .AddTo(target);
    }
}

image

AnnulusGames commented 3 days ago

I have also removed MotionBuilder.Preserve(). Similar use cases can be handled by MotionSettings. Also, MotionBuilder.Preserve() is confusing with MotionHandle.Preserve(), which was added in #146.