Data flow

This section explains how to write code related to data flow.

Data input/output

To input data values, use InputDataPort<T>. To output data values, use OutputDataPort<T>.

How to write a script

  • Declare the element where you want to input data as a public or InputDataPort<T> type field with UnityEngine.SerializeField applied.
  • Declare the element that you want to output data as a public or OutputDataPort<T> type field with UnityEngine.SerializeField applied.
  • Enter data using InputDataPort<T>.GetValue().
  • Output the data using OutputDataPort<T>.SetValue(T value).

Code example

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

[System.Serializable]
public class DataFlowExample : ActionComponent
{
    public InputDataPort<int> min;
    public InputDataPort<int> max;
    public OutputDataPort<int> output;

    // OnAction is called when the node is executed.
    protected override void OnAction()
    {
        var minValue = min.GetValue();
        var maxValue = max.GetValue();
        var result = Random.Range(minValue, maxValue);
        output.SetValue(result);
    }
}

This example prints a random integer value between the value received on the min port and the value received on the max port minus 1 each time the action is executed.

A similar script can be created by selecting Random.Range(int, int) when generating the script.

InputField

For data input, InputField also allows you to set fixed values directly in fields within nodes.

How to write a script

  • Declare a field of type InputField<T> that is either public or has UnityEngine.SerializeField applied to it.
  • Enter data using InputField<T>.value.

Code example

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

[System.Serializable]
public class InputFieldExample : ActionComponent
{
    public InputField<int> min;
    public InputField<int> max;
    public OutputDataPort<int> output;

    // OnAction is called when the node is executed.
    protected override void OnAction()
    {
        var minValue = min.value;
        var maxValue = max.value;
        var result = Random.Range(minValue, maxValue);
        output.SetValue(result);
    }
}

This is an example of replacing the previous example with InputField.
For the min and max fields, you can choose to set them to fixed values or receive them from the input port.

InputField types

  • InputField<T>
    This is a normal input field.
    You can choose to set a fixed value or receive it from InputDataPort<T>.
  • InputGameObject
    This is an input field for GameObject.
    In addition to fixed values and InputDataPort<GameObject>, there is also a Self setting that retrieves the GameObject that is running its own graph.
  • InputComponent<T>
    Component input field.
    In addition to fixed values and InputDataPort<T>, there is also a Self setting to get the component of the GameObject that is running its own graph, and a GameObject setting to get the component from the specified GameObject.
  • InputQuaternion
    Quaternion input field.
    In addition to fixed values and InputDataPort<Quaternion>, there is also the Euler setting to obtain a quaternion by specifying the Euler angle.
  • InputSystemType
    This is an input field for System.Type.
    It supports fixed value setting of System.Type by internally serializing the type name.