RPGCore
RPGCore copied to clipboard
Input<T>.HasChanged
Currently, to detect changes to an individual input, you have to subscribe to a delegate. You can also receive a callback whenever any of the inputted values change.
This API proposal adds a Boolean property to the inputs to a node that can be acted on in the OnInputChanged() callback.
Example
public class DemoNode : Node
{
public InputSocket Target;
public InputSocket StatIncrease;
public INodeInstance Create()
{
return new DemoNodeInstance();
}
public class DemoNodeInstance : Instance
{
public Input<Character> Target;
public Input<int> StatIncrease;
public override InputMap[] Inputs(GraphConnector connections) = new[]
{
connections.Create(ref Node.Target, ref Target)
}
public override void Setup()
{
// Subscribe to events, setup variables...
}
public override void OnInputChanged()
{
if (StatIncrease.HasChanged)
{
Console.WriteLine($"New Stat Value: {StatIncrease.Value}.");
}
if (Target.HasChanged)
{
Console.WriteLine($"New Target Value: {Target.Value}.");
}
}
public override void Remove()
{
// Unsubscribe from events, dispose members...
}
}
}
Implementation
This Boolean flag indicating whether the value of the connection has changed should live on the connection itself.
Buffering events will allow this API to be much more useful.