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.

Modulo.cs 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. namespace Unity.VisualScripting
  2. {
  3. [UnitOrder(105)]
  4. public abstract class Modulo<T> : Unit
  5. {
  6. /// <summary>
  7. /// The dividend (or numerator).
  8. /// </summary>
  9. [DoNotSerialize]
  10. [PortLabel("A")]
  11. public ValueInput dividend { get; private set; }
  12. /// <summary>
  13. /// The divisor (or denominator).
  14. /// </summary>
  15. [DoNotSerialize]
  16. [PortLabel("B")]
  17. public ValueInput divisor { get; private set; }
  18. /// <summary>
  19. /// The remainder of the division of dividend and divison (numerator / denominator).
  20. /// </summary>
  21. [DoNotSerialize]
  22. [PortLabel("A % B")]
  23. public ValueOutput remainder { get; private set; }
  24. [DoNotSerialize]
  25. protected virtual T defaultDivisor => default(T);
  26. [DoNotSerialize]
  27. protected virtual T defaultDividend => default(T);
  28. protected override void Definition()
  29. {
  30. dividend = ValueInput(nameof(dividend), defaultDividend);
  31. divisor = ValueInput(nameof(divisor), defaultDivisor);
  32. remainder = ValueOutput(nameof(remainder), Operation).Predictable();
  33. Requirement(dividend, remainder);
  34. Requirement(divisor, remainder);
  35. }
  36. public abstract T Operation(T divident, T divisor);
  37. public T Operation(Flow flow)
  38. {
  39. return Operation(flow.GetValue<T>(dividend), flow.GetValue<T>(divisor));
  40. }
  41. }
  42. }