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.

EqualityComparison.cs 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. using System;
  2. namespace Unity.VisualScripting
  3. {
  4. /// <summary>
  5. /// Compares two inputs to determine if they are equal or not equal.
  6. /// </summary>
  7. [UnitCategory("Logic")]
  8. [UnitTitle("Equality Comparison")]
  9. [UnitSurtitle("Equality")]
  10. [UnitShortTitle("Comparison")]
  11. [UnitOrder(4)]
  12. [Obsolete("Use the Comparison node instead.")]
  13. public sealed class EqualityComparison : Unit
  14. {
  15. /// <summary>
  16. /// The first input.
  17. /// </summary>
  18. [DoNotSerialize]
  19. public ValueInput a { get; private set; }
  20. /// <summary>
  21. /// The second input.
  22. /// </summary>
  23. [DoNotSerialize]
  24. public ValueInput b { get; private set; }
  25. /// <summary>
  26. /// Whether A is equal to B.
  27. /// </summary>
  28. [DoNotSerialize]
  29. [PortLabel("A = B")]
  30. public ValueOutput equal { get; private set; }
  31. /// <summary>
  32. /// Whether A is different than B.
  33. /// </summary>
  34. [DoNotSerialize]
  35. [PortLabel("A \u2260 B")]
  36. public ValueOutput notEqual { get; private set; }
  37. protected override void Definition()
  38. {
  39. a = ValueInput<object>(nameof(a)).AllowsNull();
  40. b = ValueInput<object>(nameof(b)).AllowsNull();
  41. equal = ValueOutput(nameof(equal), Equal).Predictable();
  42. notEqual = ValueOutput(nameof(notEqual), NotEqual).Predictable();
  43. Requirement(a, equal);
  44. Requirement(b, equal);
  45. Requirement(a, notEqual);
  46. Requirement(b, notEqual);
  47. }
  48. private bool Equal(Flow flow)
  49. {
  50. return OperatorUtility.Equal(flow.GetValue(a), flow.GetValue(b));
  51. }
  52. private bool NotEqual(Flow flow)
  53. {
  54. return OperatorUtility.NotEqual(flow.GetValue(a), flow.GetValue(b));
  55. }
  56. }
  57. }