MeatMotion

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.

Namespace
MeatMotion
Assembly
MeatMotion

Jump to members

public static class MotionHandleExtensions
MotionHandleExtensions.cs · L69

Wait 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

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
handle
this MotionHandle Handle 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
handle
this MotionHandle Handle 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
handle
this MotionHandle Handle 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
handle
this MotionHandle Handle 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
handle
this MotionHandle Handle 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
handle
this MotionHandle Handle 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
handle
this MotionHandle Handle 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
handle
this MotionHandle Handle 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
handle
this MotionHandle Handle 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
handle
this MotionHandle Handle to control or link.
compositeMotionHandle
CompositeMotionHandle Collection used to manage the handles together.
Returns
MotionHandle
public static MotionHandle AddTo(this MotionHandle handle, GameObject target)
Parameters and return value
handle
this MotionHandle Handle to control or link.
target
GameObject Object to which the motion lifetime is linked.
Returns
MotionHandle
public static MotionHandle AddTo(this MotionHandle handle, Component target)
Parameters and return value
handle
this MotionHandle Handle to control or link.
target
Component Object to which the motion lifetime is linked.
Returns
MotionHandle
public static MotionHandle AddTo(this MotionHandle handle, Component target, LinkBehavior linkBehaviour)
Parameters and return value
handle
this MotionHandle Handle to control or link.
target
Component Object to which the motion lifetime is linked.
linkBehaviour
LinkBehavior Action taken on destruction or disable.
Returns
MotionHandle
public static MotionHandle AddTo(this MotionHandle handle, GameObject target, LinkBehavior linkBehaviour)
Parameters and return value
handle
this MotionHandle Handle to control or link.
target
GameObject Object to which the motion lifetime is linked.
linkBehaviour
LinkBehavior Action taken on destruction or disable.
Returns
MotionHandle
public static MotionHandle AddTo(this MotionHandle handle, MonoBehaviour target)
Parameters and return value
handle
this MotionHandle Handle to control or link.
target
MonoBehaviour Object 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
handle
this MotionHandle Handle to control or link.
disposeBehavior = DisposeBehavior.Cancel
DisposeBehavior Action 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
handle
this MotionHandle Handle 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
handle
this MotionHandle Handle 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
handle
this MotionHandle Handle to control or link.
cancellationToken = default
CancellationToken Token used to cancel the wait.
Returns
ValueTask
public static ValueTask ToValueTask(this MotionHandle handle, CancelBehavior cancelBehavior, CancellationToken cancellationToken = default)
Parameters and return value
handle
this MotionHandle Handle to control or link.
cancelBehavior
CancelBehavior Action applied to the tween when the wait token is canceled.
cancellationToken = default
CancellationToken Token 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
handle
this MotionHandle Handle to control or link.
cancelBehavior
CancelBehavior Action applied to the tween when the wait token is canceled.
cancelAwaitOnMotionCanceled
bool Whether canceling the motion itself also cancels the wait.
cancellationToken = default
CancellationToken Token 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
handle
this MotionHandle Handle to control or link.
cancellationToken = default
CancellationToken Token used to cancel the wait.
Returns
Awaitable
public static Awaitable ToAwaitable(this MotionHandle handle, CancelBehavior cancelBehavior, CancellationToken cancellationToken = default)
Parameters and return value
handle
this MotionHandle Handle to control or link.
cancelBehavior
CancelBehavior Action applied to the tween when the wait token is canceled.
cancellationToken = default
CancellationToken Token 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
handle
this MotionHandle Handle to control or link.
cancelBehavior
CancelBehavior Action applied to the tween when the wait token is canceled.
cancelAwaitOnMotionCanceled
bool Whether canceling the motion itself also cancels the wait.
cancellationToken = default
CancellationToken Token used to cancel the wait.
Returns
Awaitable