Skip to content

Commit

Permalink
Add tickable document
Browse files Browse the repository at this point in the history
  • Loading branch information
mewlist committed Feb 22, 2024
1 parent fc85045 commit 969870e
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 12 deletions.
1 change: 1 addition & 0 deletions Writerside~/di.tree
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<toc-element topic="injection.md"/>
<toc-element topic="bindings.md"/>
<toc-element topic="bindings_advanced.md"/>
<toc-element topic="tickable.md"/>
<toc-element topic="unitask-integration.md"/>
<toc-element topic="troubleshooting.md"/>
</instance-profile>
1 change: 1 addition & 0 deletions Writerside~/di_en.tree
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<toc-element topic="injection_en.md"/>
<toc-element topic="bindings_en.md"/>
<toc-element topic="bindings_advanced_en.md"/>
<toc-element topic="tickable_en.md"/>
<toc-element topic="unitask-integration_en.md"/>
<toc-element topic="troubleshooting_en.md"/>
</instance-profile>
47 changes: 47 additions & 0 deletions Writerside~/topics/tickable.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# 定期的なコールバック

Unity のプレイヤーループタイミングに従って、定期的に呼び出されるコールバックを登録できます。
DI コンテナにより管理されるインスタンスや、注入対象となるインスタンスに対して機能します。
また、対象のクラスへの注入が完了した以降に初回の呼び出しが行われることが保証されます。

## コールバックの登録

任意の public なメソッドに ```[Tickable]``` 属性をつけることで、コールバックを登録できます。
タイミングを指定しなかった場合は、```Update``` タイミングでコールバックされます。

```C#
public class SomeClass
{
// Update タイミングで呼び出される
[Tickable]
public void Tick()
{
...
}
}
```

## コールバックタイミングの指定

```Tickable``` の引数にコールバックのタイミングを指定できます。

```C#
public class SomeClass
{
// FixedUpdate タイミングで呼び出される
[Tickable(TickableTiming.FixedUpdate)]
public void Tick()
{
...
}
}
```

コールバックには以下のタイミングを指定できます。

* TickableTiming.EarlyUpdate
* TickableTiming.FixedUpdate
* TickableTiming.PreUpdate
* TickableTiming.Update
* TickableTiming.PreLateUpdate
* TickableTiming.PostLateUpdate
45 changes: 45 additions & 0 deletions Writerside~/topics/tickable_en.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Regular Callbacks

You can register callbacks that are called regularly according to the timing of Unity's player loop.
It works for instances managed by the DI container and instances to be injected. It is also guaranteed that the first call will be made after the injection to the target class has been completed.

## Registering Callbacks

By adding the ```[Tickable]``` attribute to any public method, you can register a callback. If you do not specify the timing, it will be called back at the ```Update``` timing.

```C#
public class SomeClass
{
// Called at Update timing
[Tickable]
public void Tick()
{
...
}
}
```

## Specifying Callback Timing

You can specify the timing of the callback in the arguments of ```Tickable```.

```C#
public class SomeClass
{
// Called at FixedUpdate timing
[Tickable(TickableTiming.FixedUpdate)]
public void Tick()
{
...
}
}
```

You can specify the following timings for the callback.

* TickableTiming.EarlyUpdate
* TickableTiming.FixedUpdate
* TickableTiming.PreUpdate
* TickableTiming.Update
* TickableTiming.PreLateUpdate
* TickableTiming.PostLateUpdate
22 changes: 16 additions & 6 deletions Writerside~/topics/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@ Unity Package Manager からインストールすることができます。
<step>Unity のメニューから <ui-path>Window > Package Manager</ui-path> を選択します。</step>
<step><control>+</control> ボタンをクリックし、<control>Add package from git URL...</control> を選択します。</step>
<step>以下を入力し、<control>Add</control> をクリックします。
<code-block>
git@github.com:mewlist/MewCore.git
</code-block>
<tabs>
<tab title="https">
<code-block>https://github.com/mewlist/MewCore.git</code-block>
</tab>
<tab title="ssh">
<code-block>git@github.com:mewlist/MewCore.git</code-block>
</tab>
</tabs>
</step>
</procedure>

Expand All @@ -24,9 +29,14 @@ git@github.com:mewlist/MewCore.git
<step>Unity のメニューから <ui-path>Window > Package Manager</ui-path> を選択します。</step>
<step><control>+</control> ボタンをクリックし、<control>Add package from git URL...</control> を選択します。</step>
<step>以下を入力し、<control>Add</control> をクリックします。
<code-block>
git@github.com:mewlist/Doinject.git
</code-block>
<tabs>
<tab title="https">
<code-block>https://github.com/mewlist/Doinject.git</code-block>
</tab>
<tab title="ssh">
<code-block>git@github.com:mewlist/Doinject.git</code-block>
</tab>
</tabs>
</step>
</procedure>

Expand Down
22 changes: 16 additions & 6 deletions Writerside~/topics/tutorial_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@ You can install it from the Unity Package Manager.
<step>Select <ui-path>Window > Package Manager</ui-path> from the Unity menu.</step>
<step>Click the <control>+</control> button and select <control>Add package from git URL...</control>.</step>
<step>Enter the following and click <control>Add</control>.
<code-block>
git@github.com:mewlist/MewCore.git
</code-block>
<tabs>
<tab title="https">
<code-block>https://github.com/mewlist/MewCore.git</code-block>
</tab>
<tab title="ssh">
<code-block>git@github.com:mewlist/MewCore.git</code-block>
</tab>
</tabs>
</step>
</procedure>

Expand All @@ -24,9 +29,14 @@ git@github.com:mewlist/MewCore.git
<step>Select <ui-path>Window > Package Manager</ui-path> from the Unity menu.</step>
<step>Click the <control>+</control> button and select <control>Add package from git URL...</control>.</step>
<step>Enter the following and click <control>Add</control>.
<code-block>
git@github.com:mewlist/Doinject.git
</code-block>
<tabs>
<tab title="https">
<code-block>https://github.com/mewlist/Doinject.git</code-block>
</tab>
<tab title="ssh">
<code-block>git@github.com:mewlist/Doinject.git</code-block>
</tab>
</tabs>
</step>
</procedure>

Expand Down

0 comments on commit 969870e

Please sign in to comment.