Skip to content

Commit

Permalink
Merge pull request #90 from AnnulusGames/update-docs
Browse files Browse the repository at this point in the history
Update: docs
  • Loading branch information
AnnulusGames authored Jan 29, 2024
2 parents 2fa6c94 + 49420c1 commit 100f3c8
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 2 deletions.
14 changes: 13 additions & 1 deletion docs/articles/en/controlling-motion.md
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions docs/articles/en/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 29 additions & 0 deletions docs/articles/en/waiting-for-motion-in-async-await.md
Original file line number Diff line number Diff line change
@@ -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);
}
```
14 changes: 13 additions & 1 deletion docs/articles/ja/controlling-motion.md
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions docs/articles/ja/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: テキストアニメーション
Expand Down
29 changes: 29 additions & 0 deletions docs/articles/ja/waiting-for-motion-in-async-await.md
Original file line number Diff line number Diff line change
@@ -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);
}
```

0 comments on commit 100f3c8

Please sign in to comment.