LoopCheckDecoratorをC#スクリプトで記述できます。
作成方法
- Projectウィンドウの「+」ボタンをクリック。
- メニューからLogic Toolkit > Scripts > Decorator > Loop Check Decorator C# Scriptを選択。
- スクリプト名を入力し、Enterで決定。
スクリプトの書き方
- LogicToolkit.BehaviorTree.LoopCheckDecoratorを継承したクラスを作成します。
- 型にSystem.SerializableAttributeを適用します。
- protected override bool OnNext()を実装し、実行時の処理を記述します。
- アクティブになった際にprotected override void OnActivated()が呼ばれます。
- 非アクティブになった際にprotected override void OnDeactivated()が呼ばれます。
コード例
|  1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
 | using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using LogicToolkit;
using LogicToolkit.BehaviorTrees;
[System.Serializable]
public class LoopCheckDecoratorExample : LoopCheckDecorator
{
    private int count;
    // OnActivated is called when activated.
    protected override void OnActivated()
    {
        count = 0;
    }
    
    // Called when the node finishes executing
    protected override bool OnNext()
    {
        count++;
        // Returns true if the node is executed repeatedly
        return count < 10;
    }
    // OnDeactivated is called when it is deactivated.
    protected override void OnDeactivated()
    {
    }
}
 | 
 
この例では、ノードを10回まで繰り返します。
なお、同様の機能としてLoopCountというスクリプトが予め同梱されています。