MeatMotion

MotionBuilder<TValue, TOptions, TAdapter>

Configure easing, loops, callbacks and scheduling for a value, options type and adapter. Bind schedules the configured motion.

Namespace
MeatMotion
Assembly
MeatMotion

Jump to members

public struct MotionBuilder<TValue, TOptions, TAdapter> : IDisposable
    where TValue : unmanaged
    where TOptions : unmanaged, IMotionOptions
    where TAdapter : unmanaged, IMotionAdapter<TValue, TOptions>
MotionBuilder.cs · L11

Reuse the same settings

Add using MeatMotion;. Capture settings before binding to create multiple independently controlled motions.

using var world = new MotionWorld();
using var builder = MMotion.Create(0f, 10f, 1f).WithScheduler(world).AsMotionBuilder();
var settings = builder.ToMotionSettings();
float a = 0f, b = 0f;
var first = MMotion.Create(settings).Bind(v => a = v);
MMotion.Create(settings).Bind(v => b = v);
first.Cancel();
world.Tick(0.5);

Members

ToMotionSettings

Capture the configuration before binding and pass it to MMotion.Create to reuse it.

public MotionSettings<TValue, TOptions> ToMotionSettings()
Return value
Returns
MotionSettings<TValue, TOptions>

Dispose

Return the shared builder buffer. Struct copies are invalidated too. Obtain a new builder before configuring or binding again.

public void Dispose()

WithScheduler

Choose the automatic update phase or manual world before binding.

public MotionBuilder<TValue, TOptions, TAdapter> WithScheduler(MotionWorld world)
Parameters and return value
world
MotionWorld MotionWorld in which to schedule the tween.
Returns
MotionBuilder<TValue, TOptions, TAdapter>
public MotionBuilder<TValue, TOptions, TAdapter> WithScheduler(IMotionScheduler scheduler)
Parameters and return value
scheduler
IMotionScheduler Scheduler that determines where the motion is registered and updated.
Returns
MotionBuilder<TValue, TOptions, TAdapter>

WithEase

Choose the curve that maps normalized time to progress. When used with Bind, an AnimationCurve is sampled from a snapshot taken at bind time.

public MotionBuilder<TValue, TOptions, TAdapter> WithEase(Easing easing)
Parameters and return value
easing
Easing Easing function mapping normalized time to progress.
Returns
MotionBuilder<TValue, TOptions, TAdapter>
public MotionBuilder<TValue, TOptions, TAdapter> WithEase(Ease ease)
Parameters and return value
ease
Ease Easing function mapping normalized time to progress.
Returns
MotionBuilder<TValue, TOptions, TAdapter>
public MotionBuilder<TValue, TOptions, TAdapter> WithEase(AnimationCurve animationCurve)
Parameters and return value
animationCurve
AnimationCurve Unity AnimationCurve with its keys and pre/post wrap modes.
Returns
MotionBuilder<TValue, TOptions, TAdapter>

WithLoops

Set the loop count and LoopType. Stop an infinite loop by canceling it.

public MotionBuilder<TValue, TOptions, TAdapter> WithLoops(int loops, LoopType loopType = LoopType.Restart)
Parameters and return value
loops
int Loop count. Use -1 for an infinite loop.
loopType = LoopType.Restart
LoopType How progress is evaluated on successive passes.
Returns
MotionBuilder<TValue, TOptions, TAdapter>

WithDelay

Set a delay in seconds and choose which loops receive it. skipValuesDuringDelay controls writes while waiting.

public MotionBuilder<TValue, TOptions, TAdapter> WithDelay(float delay, DelayType delayType = DelayType.FirstLoop, bool skipValuesDuringDelay = true)
Parameters and return value
delay
float Delay before interpolation, in seconds.
delayType = DelayType.FirstLoop
DelayType Apply the delay once or before every loop.
skipValuesDuringDelay = true
bool Whether to skip setter writes during a delay.
Returns
MotionBuilder<TValue, TOptions, TAdapter>

WithImmediateBind

Pass false to suppress the initial write at bind time, for example on a later sequence child targeting the same property.

public MotionBuilder<TValue, TOptions, TAdapter> WithImmediateBind(bool immediateBind = true)
Parameters and return value
immediateBind = true
bool Whether to write the start value immediately upon binding.
Returns
MotionBuilder<TValue, TOptions, TAdapter>

WithOnCancel

Register work to run when the motion is canceled.

public MotionBuilder<TValue, TOptions, TAdapter> WithOnCancel(Action callback)
Parameters and return value
callback
Action Register work to run when the motion is canceled.
Returns
MotionBuilder<TValue, TOptions, TAdapter>

WithDebugName

Set a name for identifying the tween in the Editor or a Development Build.

public MotionBuilder<TValue, TOptions, TAdapter> WithDebugName(string debugName)
Parameters and return value
debugName
string Name used to identify the tween while debugging.
Returns
MotionBuilder<TValue, TOptions, TAdapter>

WithOnComplete

Register work to run on completion, including explicit completion.

public MotionBuilder<TValue, TOptions, TAdapter> WithOnComplete(Action callback)
Parameters and return value
callback
Action Register work to run on completion, including explicit completion.
Returns
MotionBuilder<TValue, TOptions, TAdapter>

WithOnLoopComplete

Register a callback that receives the completed loop count at a loop boundary.

public MotionBuilder<TValue, TOptions, TAdapter> WithOnLoopComplete(Action<int> callback)
Parameters and return value
callback
Action<int> Register a callback that receives the completed loop count at a loop boundary.
Returns
MotionBuilder<TValue, TOptions, TAdapter>

WithOptions

Assign the options struct passed to the value adapter.

public MotionBuilder<TValue, TOptions, TAdapter> WithOptions(TOptions options)
Parameters and return value
options
TOptions Options passed to this value adapter.
Returns
MotionBuilder<TValue, TOptions, TAdapter>

WithCancelOnError

Choose whether an exception from the bound setter cancels this tween.

public MotionBuilder<TValue, TOptions, TAdapter> WithCancelOnError(bool cancelOnError = true)
Parameters and return value
cancelOnError = true
bool Whether an exception from the setter cancels the motion.
Returns
MotionBuilder<TValue, TOptions, TAdapter>

Bind

Schedule the tween with a value setter. Stateful overloads pass the bound state after the interpolated value.

public MotionHandle Bind(Action<TValue> action)
Parameters and return value
action
Action<TValue> Callback receiving the sampled value.
Returns
MotionHandle
public MotionHandle Bind<T1>(T1 state, Action<TValue, T1> action)
    where T1 : class
Parameters and return value
state
T1 State passed to the setter after the interpolated value.
action
Action<TValue, T1> Callback receiving the sampled value.
Returns
MotionHandle
public MotionHandle Bind<T1, T2>(T1 state0, T2 state1, Action<TValue, T1, T2> action)
    where T1 : class
    where T2 : class
Parameters and return value
state0
T1 State passed to the setter after the interpolated value.
state1
T2 State passed to the setter after the interpolated value.
action
Action<TValue, T1, T2> Callback receiving the sampled value.
Returns
MotionHandle
public MotionHandle Bind<T1, T2, T3>(T1 state0, T2 state1, T3 state2, Action<TValue, T1, T2, T3> action)
    where T1 : class
    where T2 : class
    where T3 : class
Parameters and return value
state0
T1 State passed to the setter after the interpolated value.
state1
T2 State passed to the setter after the interpolated value.
state2
T3 State passed to the setter after the interpolated value.
action
Action<TValue, T1, T2, T3> Callback receiving the sampled value.
Returns
MotionHandle

RunWithoutBinding

Schedule without a value setter and return a handle for timing and callbacks.

public MotionHandle RunWithoutBinding()
Return value
Returns
MotionHandle

Related types