MotionBuilder<TValue, TOptions, TAdapter>
Configure easing, loops, callbacks and scheduling for a value, options type and adapter. Bind schedules the configured motion.
public struct MotionBuilder<TValue, TOptions, TAdapter> : IDisposable
where TValue : unmanaged
where TOptions : unmanaged, IMotionOptions
where TAdapter : unmanaged, IMotionAdapter<TValue, TOptions>MotionBuilder.cs · L11Reuse 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
- Dispose
- WithScheduler
- WithEase
- WithLoops
- WithDelay
- WithImmediateBind
- WithOnCancel
- WithDebugName
- WithOnComplete
- WithOnLoopComplete
- WithOptions
- WithCancelOnError
- Bind
- RunWithoutBinding
ToMotionSettings
Capture the configuration before binding and pass it to MMotion.Create to reuse it.
public MotionSettings<TValue, TOptions> ToMotionSettings()Return value
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
worldMotionWorldMotionWorld in which to schedule the tween.- Returns
MotionBuilder<TValue, TOptions, TAdapter>
public MotionBuilder<TValue, TOptions, TAdapter> WithScheduler(IMotionScheduler scheduler)Parameters and return value
schedulerIMotionSchedulerScheduler 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
easingEasingEasing function mapping normalized time to progress.- Returns
MotionBuilder<TValue, TOptions, TAdapter>
public MotionBuilder<TValue, TOptions, TAdapter> WithEase(Ease ease)Parameters and return value
easeEaseEasing function mapping normalized time to progress.- Returns
MotionBuilder<TValue, TOptions, TAdapter>
public MotionBuilder<TValue, TOptions, TAdapter> WithEase(AnimationCurve animationCurve)Parameters and return value
animationCurveAnimationCurveUnity 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
loopsintLoop count. Use -1 for an infinite loop.loopType = LoopType.RestartLoopTypeHow 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
delayfloatDelay before interpolation, in seconds.delayType = DelayType.FirstLoopDelayTypeApply the delay once or before every loop.skipValuesDuringDelay = trueboolWhether 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 = trueboolWhether 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
callbackActionRegister 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
debugNamestringName 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
callbackActionRegister 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
callbackAction<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
optionsTOptionsOptions 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 = trueboolWhether 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
actionAction<TValue>Callback receiving the sampled value.- Returns
MotionHandle
public MotionHandle Bind<T1>(T1 state, Action<TValue, T1> action)
where T1 : classParameters and return value
stateT1State passed to the setter after the interpolated value.actionAction<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 : classParameters and return value
state0T1State passed to the setter after the interpolated value.state1T2State passed to the setter after the interpolated value.actionAction<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 : classParameters and return value
state0T1State passed to the setter after the interpolated value.state1T2State passed to the setter after the interpolated value.state2T3State passed to the setter after the interpolated value.actionAction<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
- MMotion
- MotionBuilderExtensions
- MotionHandle
- AudioMotionExtensions
- CameraMotionExtensions
- LoggerMotionExtensions
- MaterialMotionExtensions
- ProgressMotionExtensions
- RectTransformMotionExtensions
- Rigidbody2DMotionExtensions
- RigidbodyMotionExtensions
- SpriteRendererMotionExtensions
- TextMeshProMotionExtensions
- TransformMotionExtensions
- UGUIMotionExtensions
- UIToolkitMotionExtensions
- VisualEffectMotionExtensions
- VolumeMotionExtensions
- R3MotionExtensions
- UniRxMotionExtensions
- UniTaskMotionExtensions
MeatMotion