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.

ApproximatelyEqual.cs 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System;
  2. using UnityEngine;
  3. namespace Unity.VisualScripting
  4. {
  5. /// <summary>
  6. /// Compares two numbers to determine if they are approximately equal (disregarding floating point precision errors).
  7. /// </summary>
  8. [UnitCategory("Logic")]
  9. [UnitShortTitle("Equal")]
  10. [UnitSubtitle("(Approximately)")]
  11. [UnitOrder(7)]
  12. [Obsolete("Use the Equal node with Numeric enabled instead.")]
  13. public sealed class ApproximatelyEqual : Unit
  14. {
  15. /// <summary>
  16. /// The first number.
  17. /// </summary>
  18. [DoNotSerialize]
  19. public ValueInput a { get; private set; }
  20. /// <summary>
  21. /// The second number.
  22. /// </summary>
  23. [DoNotSerialize]
  24. public ValueInput b { get; private set; }
  25. /// <summary>
  26. /// Whether A is approximately equal to B.
  27. /// </summary>
  28. [DoNotSerialize]
  29. [PortLabel("A \u2248 B")]
  30. public ValueOutput equal { get; private set; }
  31. protected override void Definition()
  32. {
  33. a = ValueInput<float>(nameof(a));
  34. b = ValueInput<float>(nameof(b), 0);
  35. equal = ValueOutput(nameof(equal), Comparison).Predictable();
  36. Requirement(a, equal);
  37. Requirement(b, equal);
  38. }
  39. public bool Comparison(Flow flow)
  40. {
  41. return Mathf.Approximately(flow.GetValue<float>(a), flow.GetValue<float>(b));
  42. }
  43. }
  44. }