TaskComponentをC#スクリプトで記述できます。
作成方法
- Projectウィンドウの「+」ボタンをクリック。
- メニューからLogic Toolkit > Scripts > Task Component C# Scriptを選択。
- スクリプト名を入力し、Enterで決定。
スクリプトの書き方
- LogicToolkit.TaskComponentを継承したクラスを作成します。
- 型にSystem.SerializableAttributeを適用します。
- アクティブになった際にprotected override void OnActivated()が呼ばれます。
- 非アクティブになった際にprotected override void OnDeactivated()が呼ばれます。
- protected override TaskStatus OnExecute()を実装し、実行時の処理を記述します。
コード例
|  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
 | using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using LogicToolkit;
[System.Serializable]
public class TaskExample : TaskComponent
{
    private float startTime;
    // OnActivated is called when activated.
    protected override void OnActivated()
    {
        startTime = Time.time;
    }
    // OnExecute is called when it is executed.
    protected override TaskStatus OnExecute()
    {
        // Return Running, Success, or Failure depending on the task execution status.
        return Time.time - startTime > 1f? TaskStatus.Success : TaskStatus.Running;
    }
    // OnDeactivated is called when it is deactivated.
    protected override void OnDeactivated()
    {
        
    }
}
 | 
 
この例では、実行されると1秒後に成功を返して終了します。
なお、同様の機能としてWait For Secondsというスクリプトが予め同梱されています。