namespace Unity.VisualScripting { /// /// Caches the input so that all nodes connected to the output /// retrieve the value only once. /// [UnitCategory("Control")] [UnitOrder(15)] public sealed class Cache : Unit { /// /// The moment at which to cache the value. /// The output value will only get updated when this gets triggered. /// [DoNotSerialize] [PortLabelHidden] public ControlInput enter { get; private set; } /// /// The value to cache when the node is entered. /// [DoNotSerialize] [PortLabelHidden] public ValueInput input { get; private set; } /// /// The cached value, as it was the last time this node was entered. /// [DoNotSerialize] [PortLabel("Cached")] [PortLabelHidden] public ValueOutput output { get; private set; } /// /// The action to execute once the value has been cached. /// [DoNotSerialize] [PortLabelHidden] public ControlOutput exit { get; private set; } protected override void Definition() { enter = ControlInput(nameof(enter), Store); input = ValueInput(nameof(input)); output = ValueOutput(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; } } }