xNode is an open-source library to create and visualize node graphs in Unity. xNode is used in PlateUp! for defining recipes, card requirements/blockers, and restaurant layout generation.
This is an object that contains a list of nodes that are related to one another. It acts as a canvas for nodes, but does not know how nodes are connected together.
A node contains variables which can be used by methods internally to define how input data is transformed. It also has a NodePort
dictionary that contains named NodePort
objects.
Connected ports serve as a means to transmit data from one node to another. The value of the node must be Unity serializable to be used by a port. Ports can be defined as either Input or Output, where an input port can be connected to an output port that uses the same connection type.
This example creates 2 named ports called "PortA" and "PortB", where "PortA" is an input and "PortB" is an output.
[Input] public CustomPortType PortA;
[Output] public CustomPortType PortB;
Additionally, ports can have properties that affect how connections are handled
ShowBackingValue: Display value at port (visual graphing only)
ConnectionType: How to handle previous connections when a new connection is added. (Override or Multiple)
TypeConstraint: Limit which value types you can connect to this port (None, Inherited, Strict, or InheritedInverse)
DynamicPortList: Whether to display a port per list item instead of one port for the entire list
[Input(ShowBackingValue.Never, ConnectionType.Override, TypeConstraint.None, false)]
public CustomPortType PortC;
[Output(ShowBackingValue.Never, ConnectionType.Multiple, TypeConstraint.None, false)]
public CustomPortType PortD;
A connection type is defined as an empty struct. This type is used to define ports that can be linked together. The connection type does not affect the port's value type.
[StructLayout(LayoutKind.Sequential, Size = 1)]
public struct CustomPortType { }