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