From 49420c17210bf80b6d1f474790bbe5825b41e56c Mon Sep 17 00:00:00 2001 From: AnnulusGames Date: Mon, 29 Jan 2024 15:06:27 +0900 Subject: [PATCH] Update: docs --- docs/articles/en/controlling-motion.md | 14 ++++++++- docs/articles/en/toc.yml | 2 ++ .../en/waiting-for-motion-in-async-await.md | 29 +++++++++++++++++++ docs/articles/ja/controlling-motion.md | 14 ++++++++- docs/articles/ja/toc.yml | 2 ++ .../ja/waiting-for-motion-in-async-await.md | 29 +++++++++++++++++++ 6 files changed, 88 insertions(+), 2 deletions(-) create mode 100644 docs/articles/en/waiting-for-motion-in-async-await.md create mode 100644 docs/articles/ja/waiting-for-motion-in-async-await.md diff --git a/docs/articles/en/controlling-motion.md b/docs/articles/en/controlling-motion.md index a455fce..07ec315 100644 --- a/docs/articles/en/controlling-motion.md +++ b/docs/articles/en/controlling-motion.md @@ -24,9 +24,21 @@ var handle = LMotion.Create(0f, 10f, 2f).RunWithoutBinding(); handle.Cancel(); ``` +### Motion Playback Speed + +You can change the playback speed of a motion using the `MotionHandle.PlaybackSpeed` property. This allows you to perform actions such as slow-motion or pause during the motion playback. + +```cs +var handle = LMotion.Create(0f, 10f, 2f).RunWithoutBinding(); +handle.PlaybackSpeed = 2f; +``` + +> [!WARNING] +> PlaybackSpeed does not support values less than 0. Trying to set a negative value to `MotionHandle.PlaybackSpeed` will throw an exception. + ### Motion Existence Check -The mentioned methods throw exceptions if the motion has already ended or if the `MotionHandle` hasn’t been initialized. Use `IsActive()` to check if the motion referenced by `MotionHandle` exists. +The methods and properties mentioned above will throw exceptions if the motion has already ended or if the `MotionHandle` has not been initialized. To check whether the motion pointed to by the `MotionHandle` exists, use `IsActive()`. ```cs var handle = LMotion.Create(0f, 10f, 2f).RunWithoutBinding(); diff --git a/docs/articles/en/toc.yml b/docs/articles/en/toc.yml index 05f0916..d49f8ea 100644 --- a/docs/articles/en/toc.yml +++ b/docs/articles/en/toc.yml @@ -21,6 +21,8 @@ href: motion-configuration.md - name: Waiting for Motion in Coroutine href: waiting-for-motion-in-coroutine.md +- name: Waiting for Motion in async/await + href: waiting-for-motion-in-async-await.md - name: Vibration Motion with Punch/Shake href: punch-and-shake.md - name: Text Animation diff --git a/docs/articles/en/waiting-for-motion-in-async-await.md b/docs/articles/en/waiting-for-motion-in-async-await.md new file mode 100644 index 0000000..a2aaff9 --- /dev/null +++ b/docs/articles/en/waiting-for-motion-in-async-await.md @@ -0,0 +1,29 @@ +# Waiting for Motion in async/await + +`MotionHandle.ToValueTask()` allows you to convert a motion to a `ValueTask`. This enables you to await the completion of the motion using async/await. + +```cs +async ValueTask ExampleAsync(CancellationToken cancellationToken) +{ + await LMotion.Create(0f, 10f, 1f) + .RunWithoutBinding() + .ToValueTask(cancellationToken); +} +``` + +However, using `ValueTask` in Unity may have performance implications. For optimal performance, it is recommended to use UniTask. Refer to [UniTask](integration-unitask.md) for information on integrating UniTask with LitMotion. + +### Awaitable + +Unity 2023.1 and later versions provide the [Awaitable](https://docs.unity3d.com/2023.1/Documentation/ScriptReference/Awaitable.html) class, which allows for efficient async/await in Unity. + +If you're using Unity 2023.1 or a later version, LitMotion provides an extension method `ToAwaitable()` to convert a `MotionHandle` into an `Awaitable`. This allows you to await the motion using async/await. + +```cs +async Awaitable ExampleAsync(CancellationToken cancellationToken) +{ + await LMotion.Create(0f, 10f, 1f) + .RunWithoutBinding() + .ToAwaitable(cancellationToken); +} +``` \ No newline at end of file diff --git a/docs/articles/ja/controlling-motion.md b/docs/articles/ja/controlling-motion.md index 191599b..ab30440 100644 --- a/docs/articles/ja/controlling-motion.md +++ b/docs/articles/ja/controlling-motion.md @@ -24,9 +24,21 @@ var handle = LMotion.Create(0f, 10f, 2f).RunWithoutBinding(); handle.Cancel(); ``` +### モーションの再生速度 + +`MotionHandle.PlaybackSpeed`プロパティを操作することで、モーションの再生速度を変更することができます。これを使用してモーションのスロー再生や一時停止などを行うことができます。 + +```cs +var handle = LMotion.Create(0f, 10f, 2f).RunWithoutBinding(); +handle.PlaybackSpeed = 2f; +``` + +> [!WARNING] +> PlaybackSpeedは0未満の値をサポートしていません。`MotionHandle.PlaybackSpeed`に負の値を設定しようとすると例外をスローします。 + ### モーションの存在チェック -上記のメソッドはモーションが既に終了している、または`MotionHandle`が初期化されていない場合に例外をスローします。`MotionHandle`の指すモーションが存在しているかをチェックするには`IsActive()`を使用します。 +上記のメソッド/プロパティはモーションが既に終了している、または`MotionHandle`が初期化されていない場合に例外をスローします。`MotionHandle`の指すモーションが存在しているかをチェックするには`IsActive()`を使用します。 ```cs var handle = LMotion.Create(0f, 10f, 2f).RunWithoutBinding(); diff --git a/docs/articles/ja/toc.yml b/docs/articles/ja/toc.yml index 30d7aae..c97dc9b 100644 --- a/docs/articles/ja/toc.yml +++ b/docs/articles/ja/toc.yml @@ -21,6 +21,8 @@ href: motion-configuration.md - name: コルーチンでモーションを待機する href: waiting-for-motion-in-coroutine.md +- name: async/awaitでモーションを待機する + href: waiting-for-motion-in-async-await.md - name: Punch/Shakeによる振動のモーション href: punch-and-shake.md - name: テキストアニメーション diff --git a/docs/articles/ja/waiting-for-motion-in-async-await.md b/docs/articles/ja/waiting-for-motion-in-async-await.md new file mode 100644 index 0000000..9b47fd3 --- /dev/null +++ b/docs/articles/ja/waiting-for-motion-in-async-await.md @@ -0,0 +1,29 @@ +# async/awaitでモーションを待機する + +`MotionHandle.ToValueTask()`を使用してモーションを`ValueTask`に変換することができます。これを使用することで、async/awaitでモーションの完了を待機することが可能になります。 + +```cs +async ValueTask ExampleAsync(CancellationToken cancellationToken) +{ + await LMotion.Create(0f, 10f, 1f) + .RunWithoutBinding() + .ToValueTask(cancellationToken); +} +``` + +ただし、Unityにおいて`ValueTask`の使用はパフォーマンス上の問題を抱えています。最良のパフォーマンスを得るためにはUniTaskの使用を推奨します。UniTaskとの統合については[UniTask](integration-unitask.md)を参照してください。 + +### Awaitable + +Unity 2023.1以降では、Unityで効率的なasync/awaitを実現するためのクラスである[Awaitable](https://docs.unity3d.com/2023.1/Documentation/ScriptReference/Awaitable.html)が提供されています。 + +Unity 2023.1以降のバージョンを使用している場合、LitMotionでは`MotionHandle`を`Awaitable`に変換する拡張メソッドとして`ToAwaitable()`が提供されます。これを使用することで、async/awaitを利用してモーションを待機することができます。 + +```cs +async Awaitable ExampleAsync(CancellationToken cancellationToken) +{ + await LMotion.Create(0f, 10f, 1f) + .RunWithoutBinding() + .ToAwaitable(cancellationToken); +} +```