-
Notifications
You must be signed in to change notification settings - Fork 2
Writing a CustomAgent class
An Agent is what handles the logic of a node. This class will handle the inputs and set the outputs and will have methods called when command ports are activated:
To begin, create a class that extends PlasmaModding.CustomAgent
public class ExampleNode: PlasmaModding.CustomAgent
{
}
If you have code that you want to run when the node is first created, override the OnSetupFinished()
method with what you want to happen:
protected override void OnSetupFinished()
{
// code for when node is created
}
To define a function that will be called when a command port is activated, create a function with the attribute [SketchNodePortOperation(α)]
where α
is the int you passed into the operation
parameter when creating the port using PlasmaModding.CustomNodeManager.CreateCommandPort
:
[SketchNodePortOperation(α)]
public void AppropriateFunctionName(Behavior.SketchNode node){
// code for when command port α is activated
}
You will often find yourself wanting to read from property nodes and write to output nodes.
To get a property, use GetProperty(string)
to get a property and WriteOutput(string, Behavior.Data)
to write data to an output port.
Note that GetProperty
returns an AgentProperty
, to get the Data
from the property, do AgentProperty.GetValue()
public class ExampleNode: PlasmaModding.CustomAgent
{
protected override void OnSetupFinished()
{
// This function doesn't have to be here but if you want to do something when the node loads it goes here
}
[SketchNodePortOperation(1)]
public void Called(Behavior.SketchNode node)
{
WriteOutput("Output Text", GetProperty("Text").GetValue());
}
}