ServiceComponent

ServiceComponent can be written in a C# script.

How to create

  1. Click the “+” button in the Project window.
  2. Select Logic Toolkit > Scripts > Service Component C# Script from the menu.
  3. Enter the script name and confirm with Enter.

How to write a script

  • Create a class that inherits from LogicToolkit.ServiceComponent.
  • Apply System.SerializableAttribute to the type.
  • protected override void OnActivated() is called when activated.
  • protected override void OnDeactivated() is called when it becomes inactive.
  • Implement LogicToolkit.IUpdateReceiver as necessary, and perform update processing for each frame with void OnUpdate().

Code example

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using LogicToolkit;

[System.Serializable]
public class ServiceExample : ServiceComponent
{
    private float tempTimeScale;

    // OnActivated is called when activated.
    protected override void OnActivated()
    {
        tempTimeScale = Time.timeScale;
        Time.timeScale = 0f;
    }
    
    // OnDeactivated is called when it is deactivated.
    protected override void OnDeactivated()
    {
        Time.timeScale = tempTimeScale;
    }
}

In this example, using this script on a State or BehaviorTreeNode will stop the game's time progression while the node is active.