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 withUnityEngine.SerializeField
applied. - Declare the element that you want to output data as a public or
OutputDataPort<T>
type field withUnityEngine.SerializeField
applied. - Enter data using
InputDataPort<T>.GetValue()
. - Output the data using
OutputDataPort<T>.SetValue(T value)
.
Code example
|
|
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 hasUnityEngine.SerializeField
applied to it. - Enter data using
InputField<T>.value
.
Code example
|
|
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 fromInputDataPort<T>
. - InputGameObject
This is an input field for GameObject.
In addition to fixed values andInputDataPort<GameObject>
, there is also aSelf
setting that retrieves the GameObject that is running its own graph. - InputComponent<T>
Component input field.
In addition to fixed values andInputDataPort<T>
, there is also aSelf
setting to get the component of the GameObject that is running its own graph, and aGameObject
setting to get the component from the specified GameObject. - InputQuaternion
Quaternion input field.
In addition to fixed values andInputDataPort<Quaternion>
, there is also theEuler
setting to obtain a quaternion by specifying the Euler angle. - InputSystemType
This is an input field forSystem.Type
.
It supports fixed value setting ofSystem.Type
by internally serializing the type name.