Ei kuvausta
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.

ExclusiveOr.cs 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. namespace Unity.VisualScripting
  2. {
  3. /// <summary>
  4. /// Returns true if one input is true and the other is false.
  5. /// </summary>
  6. [UnitCategory("Logic")]
  7. [UnitOrder(2)]
  8. public sealed class ExclusiveOr : Unit
  9. {
  10. /// <summary>
  11. /// The first boolean.
  12. /// </summary>
  13. [DoNotSerialize]
  14. public ValueInput a { get; private set; }
  15. /// <summary>
  16. /// The second boolean.
  17. /// </summary>
  18. [DoNotSerialize]
  19. public ValueInput b { get; private set; }
  20. /// <summary>
  21. /// True if either A or B is true but not the other; false otherwise.
  22. /// </summary>
  23. [DoNotSerialize]
  24. [PortLabel("A \u2295 B")]
  25. public ValueOutput result { get; private set; }
  26. protected override void Definition()
  27. {
  28. a = ValueInput<bool>(nameof(a));
  29. b = ValueInput<bool>(nameof(b));
  30. result = ValueOutput(nameof(result), Operation).Predictable();
  31. Requirement(a, result);
  32. Requirement(b, result);
  33. }
  34. public bool Operation(Flow flow)
  35. {
  36. return flow.GetValue<bool>(a) ^ flow.GetValue<bool>(b);
  37. }
  38. }
  39. }