Basic Concepts
The LitMotion API consists of several components that are crucial to understand when using LitMotion.
MotionBuilder
A structure used to construct motions. LMotion.Create()
returns a MotionBuilder
instance.
var builder = LMotion.Create(0f, 10f, 3f);
MotionBuilder provides methods to configure motions, allowing method chaining.
LMotion.Create(0f, 10f, 3f)
.WithEase(Ease.OutQuad)
.WithDelay(2f)
.WithLoops(4, LoopType.Yoyo);
LitMotion motions are typically bound to some value. Binding triggers motion creation and playback.
var value = 0f;
LMotion.Create(0f, 10f, 3f)
.WithEase(Ease.OutQuad)
.Bind(x => value = x);
For more details, refer to Binding and Motion Configuration.
MotionHandle
MotionHandle
controls created motions. Methods like Bind()
from MotionBuilder return this handle.
var handle = LMotion.Create(0f, 10f, 3f).Bind(x => value = x);
You can manage motion presence, completion, or cancellation through MotionHandle.
var handle = LMotion.Create(0f, 10f, 3f).Bind(x => value = x);
if (handle.IsActive())
{
handle.Complete();
handle.Cancel();
}
For further details, refer to Motion Control.
MotionScheduler
Motion update timing is determined by MotionScheduler. Set the Scheduler using WithScheduler()
.
LMotion.Create(0f, 10f, 2f)
.WithScheduler(MotionScheduler.FixedUpdate)
.Bind(() => Debug.Log(x));
Refer to Motion Configuration for more information.
MotionAdapter
The interpolation between two values is described by structures implementing IMotionAdapter<T, TOptions>
. Built-in adapters are defined within the LitMotion.Adapters
namespace.
To add specific options to a motion, define a structure implementing IMotionOptions
.
Refer to Custom Adapter for creating custom adapters.