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.

Add.cs 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. namespace Unity.VisualScripting
  2. {
  3. [UnitOrder(101)]
  4. public abstract class Add<T> : Unit
  5. {
  6. /// <summary>
  7. /// The first value.
  8. /// </summary>
  9. [DoNotSerialize]
  10. public ValueInput a { get; private set; }
  11. /// <summary>
  12. /// The second value.
  13. /// </summary>
  14. [DoNotSerialize]
  15. public ValueInput b { get; private set; }
  16. /// <summary>
  17. /// The sum of A and B.
  18. /// </summary>
  19. [DoNotSerialize]
  20. [PortLabel("A + B")]
  21. public ValueOutput sum { get; private set; }
  22. [DoNotSerialize]
  23. protected virtual T defaultB => default(T);
  24. protected override void Definition()
  25. {
  26. a = ValueInput<T>(nameof(a));
  27. b = ValueInput(nameof(b), defaultB);
  28. sum = ValueOutput(nameof(sum), Operation).Predictable();
  29. Requirement(a, sum);
  30. Requirement(b, sum);
  31. }
  32. private T Operation(Flow flow)
  33. {
  34. return Operation(flow.GetValue<T>(a), flow.GetValue<T>(b));
  35. }
  36. public abstract T Operation(T a, T b);
  37. }
  38. }