Maze / Library /PackageCache /com.unity.visualscripting@1.8.0 /Runtime /VisualScripting.Flow /Framework /Control /Cache.cs
| namespace Unity.VisualScripting | |
| { | |
| /// <summary> | |
| /// Caches the input so that all nodes connected to the output | |
| /// retrieve the value only once. | |
| /// </summary> | |
| [] | |
| [] | |
| 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> | |
| [] | |
| [] | |
| public ControlInput enter { get; private set; } | |
| /// <summary> | |
| /// The value to cache when the node is entered. | |
| /// </summary> | |
| [] | |
| [] | |
| public ValueInput input { get; private set; } | |
| /// <summary> | |
| /// The cached value, as it was the last time this node was entered. | |
| /// </summary> | |
| [] | |
| [] | |
| [] | |
| public ValueOutput output { get; private set; } | |
| /// <summary> | |
| /// The action to execute once the value has been cached. | |
| /// </summary> | |
| [] | |
| [] | |
| 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; | |
| } | |
| } | |
| } | |