No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Cache.cs 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. namespace 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. /// <summary>
  19. /// The value to cache when the node is entered.
  20. /// </summary>
  21. [DoNotSerialize]
  22. [PortLabelHidden]
  23. public ValueInput input { get; private set; }
  24. /// <summary>
  25. /// The cached value, as it was the last time this node was entered.
  26. /// </summary>
  27. [DoNotSerialize]
  28. [PortLabel("Cached")]
  29. [PortLabelHidden]
  30. public ValueOutput output { get; private set; }
  31. /// <summary>
  32. /// The action to execute once the value has been cached.
  33. /// </summary>
  34. [DoNotSerialize]
  35. [PortLabelHidden]
  36. public ControlOutput exit { get; private set; }
  37. protected override void Definition()
  38. {
  39. enter = ControlInput(nameof(enter), Store);
  40. input = ValueInput<object>(nameof(input));
  41. output = ValueOutput<object>(nameof(output));
  42. exit = ControlOutput(nameof(exit));
  43. Requirement(input, enter);
  44. Assignment(enter, output);
  45. Succession(enter, exit);
  46. }
  47. private ControlOutput Store(Flow flow)
  48. {
  49. flow.SetValue(output, flow.GetValue(input));
  50. return exit;
  51. }
  52. }
  53. }