MotionHandleExtensions
Link a handle to an object's lifetime, yield it in a coroutine or wait asynchronously. Direct await and ToValueTask have different cancellation semantics.
public static class MotionHandleExtensionsMotionHandleExtensions.cs · L69Wait for completion via ValueTask
Add using MeatMotion;. In this example completion resolves the ValueTask before its result is read. In an async method you can await the task.
using var world = new MotionWorld();
var handle = MMotion.Create(0f, 1f, 1f).WithScheduler(world).RunWithoutBinding();
var wait = handle.ToValueTask();
handle.Complete();
wait.GetAwaiter().GetResult();
Members
- IsValid
- IsActive
- IsPlaying
- Preserve
- Complete
- TryComplete
- Cancel
- TryCancel
- GetDebugName
- AddTo
- ToDisposable
- ToYieldInstruction
- GetAwaiter
- ToValueTask
- ToAwaitable
IsValid
Check whether the handle still resolves to its original slot. This can differ from IsActive immediately after completion.
public static bool IsValid(this MotionHandle handle)Parameters and return value
handlethis MotionHandleHandle to control or link.- Returns
bool
IsActive
Check whether the motion is active. A preserved motion can remain active at its endpoint.
public static bool IsActive(this MotionHandle handle)Parameters and return value
handlethis MotionHandleHandle to control or link.- Returns
bool
IsPlaying
Return true for an active motion that has not ended. A playback speed of zero alone does not make this false.
public static bool IsPlaying(this MotionHandle handle)Parameters and return value
handlethis MotionHandleHandle to control or link.- Returns
bool
Preserve
Retain a root motion so the handle can seek it again after it completes.
public static MotionHandle Preserve(this MotionHandle handle)Parameters and return value
handlethis MotionHandleHandle to control or link.- Returns
MotionHandle
Complete
Seek a finite root motion to its end and complete it. Infinite motions and sequence-owned children cannot be completed directly.
public static void Complete(this MotionHandle handle)Parameters
handlethis MotionHandleHandle to control or link.
TryComplete
Complete a playing, finite root and report whether the request succeeded.
public static bool TryComplete(this MotionHandle handle)Parameters and return value
handlethis MotionHandleHandle to control or link.- Returns
bool
Cancel
Stop a root motion at its current value and notify cancellation.
public static void Cancel(this MotionHandle handle)Parameters
handlethis MotionHandleHandle to control or link.
TryCancel
Cancel an active root and return true. Invalid handles and sequence-owned children return false.
public static bool TryCancel(this MotionHandle handle)Parameters and return value
handlethis MotionHandleHandle to control or link.- Returns
bool
GetDebugName
In the Editor and Development Builds, return the recorded name or handle string. Invalid handles throw there. Release Builds always return the handle string.
public static string GetDebugName(this MotionHandle handle)Parameters and return value
handlethis MotionHandleHandle to control or link.- Returns
string
AddTo
Link the motion to a GameObject or component, or add it to a collection. The MonoBehaviour overload uses that component's own destruction token.
public static MotionHandle AddTo(this MotionHandle handle, CompositeMotionHandle compositeMotionHandle)Parameters and return value
handlethis MotionHandleHandle to control or link.compositeMotionHandleCompositeMotionHandleCollection used to manage the handles together.- Returns
MotionHandle
public static MotionHandle AddTo(this MotionHandle handle, GameObject target)Parameters and return value
handlethis MotionHandleHandle to control or link.targetGameObjectObject to which the motion lifetime is linked.- Returns
MotionHandle
public static MotionHandle AddTo(this MotionHandle handle, Component target)Parameters and return value
handlethis MotionHandleHandle to control or link.targetComponentObject to which the motion lifetime is linked.- Returns
MotionHandle
public static MotionHandle AddTo(this MotionHandle handle, Component target, LinkBehavior linkBehaviour)Parameters and return value
handlethis MotionHandleHandle to control or link.targetComponentObject to which the motion lifetime is linked.linkBehaviourLinkBehaviorAction taken on destruction or disable.- Returns
MotionHandle
public static MotionHandle AddTo(this MotionHandle handle, GameObject target, LinkBehavior linkBehaviour)Parameters and return value
handlethis MotionHandleHandle to control or link.targetGameObjectObject to which the motion lifetime is linked.linkBehaviourLinkBehaviorAction taken on destruction or disable.- Returns
MotionHandle
public static MotionHandle AddTo(this MotionHandle handle, MonoBehaviour target)Parameters and return value
handlethis MotionHandleHandle to control or link.targetMonoBehaviourObject to which the motion lifetime is linked.- Returns
MotionHandle
ToDisposable
Return an IDisposable that applies the selected action to the handle when disposed.
public static IDisposable ToDisposable(this MotionHandle handle, DisposeBehavior disposeBehavior = DisposeBehavior.Cancel)Parameters and return value
handlethis MotionHandleHandle to control or link.disposeBehavior = DisposeBehavior.CancelDisposeBehaviorAction to apply when the registered IDisposable is disposed.- Returns
IDisposable
ToYieldInstruction
Return an IEnumerator for waiting on the motion from a Unity coroutine.
public static IEnumerator ToYieldInstruction(this MotionHandle handle)Parameters and return value
handlethis MotionHandleHandle to control or link.- Returns
IEnumerator
GetAwaiter
Return the awaiter used by await handle to wait for completion or cancellation.
public static MotionAwaiter GetAwaiter(this MotionHandle handle)Parameters and return value
handlethis MotionHandleHandle to control or link.- Returns
MotionAwaiter
ToValueTask
Wait via ValueTask. By default canceling the motion also cancels the wait.
public static ValueTask ToValueTask(this MotionHandle handle, CancellationToken cancellationToken = default)Parameters and return value
handlethis MotionHandleHandle to control or link.cancellationToken = defaultCancellationTokenToken used to cancel the wait.- Returns
ValueTask
public static ValueTask ToValueTask(this MotionHandle handle, CancelBehavior cancelBehavior, CancellationToken cancellationToken = default)Parameters and return value
handlethis MotionHandleHandle to control or link.cancelBehaviorCancelBehaviorAction applied to the tween when the wait token is canceled.cancellationToken = defaultCancellationTokenToken used to cancel the wait.- Returns
ValueTask
public static ValueTask ToValueTask(this MotionHandle handle, CancelBehavior cancelBehavior, bool cancelAwaitOnMotionCanceled, CancellationToken cancellationToken = default)Parameters and return value
handlethis MotionHandleHandle to control or link.cancelBehaviorCancelBehaviorAction applied to the tween when the wait token is canceled.cancelAwaitOnMotionCanceledboolWhether canceling the motion itself also cancels the wait.cancellationToken = defaultCancellationTokenToken used to cancel the wait.- Returns
ValueTask
ToAwaitable
Wait via Unity Awaitable. Select how token cancellation affects the underlying tween.
public static Awaitable ToAwaitable(this MotionHandle handle, CancellationToken cancellationToken = default)Parameters and return value
handlethis MotionHandleHandle to control or link.cancellationToken = defaultCancellationTokenToken used to cancel the wait.- Returns
Awaitable
public static Awaitable ToAwaitable(this MotionHandle handle, CancelBehavior cancelBehavior, CancellationToken cancellationToken = default)Parameters and return value
handlethis MotionHandleHandle to control or link.cancelBehaviorCancelBehaviorAction applied to the tween when the wait token is canceled.cancellationToken = defaultCancellationTokenToken used to cancel the wait.- Returns
Awaitable
public static Awaitable ToAwaitable(this MotionHandle handle, CancelBehavior cancelBehavior, bool cancelAwaitOnMotionCanceled, CancellationToken cancellationToken = default)Parameters and return value
handlethis MotionHandleHandle to control or link.cancelBehaviorCancelBehaviorAction applied to the tween when the wait token is canceled.cancelAwaitOnMotionCanceledboolWhether canceling the motion itself also cancels the wait.cancellationToken = defaultCancellationTokenToken used to cancel the wait.- Returns
Awaitable
MeatMotion