File size: 1,795 Bytes
18a519f | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | namespace Unity.VisualScripting
{
/// <summary>
/// Caches the input so that all nodes connected to the output
/// retrieve the value only once.
/// </summary>
[UnitCategory("Control")]
[UnitOrder(15)]
public sealed class Cache : Unit
{
/// <summary>
/// The moment at which to cache the value.
/// The output value will only get updated when this gets triggered.
/// </summary>
[DoNotSerialize]
[PortLabelHidden]
public ControlInput enter { get; private set; }
/// <summary>
/// The value to cache when the node is entered.
/// </summary>
[DoNotSerialize]
[PortLabelHidden]
public ValueInput input { get; private set; }
/// <summary>
/// The cached value, as it was the last time this node was entered.
/// </summary>
[DoNotSerialize]
[PortLabel("Cached")]
[PortLabelHidden]
public ValueOutput output { get; private set; }
/// <summary>
/// The action to execute once the value has been cached.
/// </summary>
[DoNotSerialize]
[PortLabelHidden]
public ControlOutput exit { get; private set; }
protected override void Definition()
{
enter = ControlInput(nameof(enter), Store);
input = ValueInput<object>(nameof(input));
output = ValueOutput<object>(nameof(output));
exit = ControlOutput(nameof(exit));
Requirement(input, enter);
Assignment(enter, output);
Succession(enter, exit);
}
private ControlOutput Store(Flow flow)
{
flow.SetValue(output, flow.GetValue(input));
return exit;
}
}
}
|