using System; using UnityEngine; namespace Unity.VisualScripting { /// /// Compares two numeric inputs. /// [UnitCategory("Logic")] [UnitTitle("Numeric Comparison")] [UnitSurtitle("Numeric")] [UnitShortTitle("Comparison")] [UnitOrder(99)] [Obsolete("Use the Comparison node with Numeric enabled instead.")] public sealed class NumericComparison : Unit { /// /// The first input. /// [DoNotSerialize] public ValueInput a { get; private set; } /// /// The second input. /// [DoNotSerialize] public ValueInput b { get; private set; } /// /// Whether A is less than B. /// [DoNotSerialize] [PortLabel("A < B")] public ValueOutput aLessThanB { get; private set; } /// /// Whether A is less than or equal to B. /// [DoNotSerialize] [PortLabel("A \u2264 B")] public ValueOutput aLessThanOrEqualToB { get; private set; } /// /// Whether A is equal to B. /// [DoNotSerialize] [PortLabel("A = B")] public ValueOutput aEqualToB { get; private set; } /// /// Whether A is greater than or equal to B. /// [DoNotSerialize] [PortLabel("A \u2265 B")] public ValueOutput aGreaterThanOrEqualToB { get; private set; } /// /// Whether A is greater than B. /// [DoNotSerialize] [PortLabel("A > B")] public ValueOutput aGreatherThanB { get; private set; } protected override void Definition() { a = ValueInput(nameof(a)); b = ValueInput(nameof(b), 0); aLessThanB = ValueOutput(nameof(aLessThanB), Less).Predictable(); aLessThanOrEqualToB = ValueOutput(nameof(aLessThanOrEqualToB), LessOrEqual).Predictable(); aEqualToB = ValueOutput(nameof(aEqualToB), Equal).Predictable(); aGreaterThanOrEqualToB = ValueOutput(nameof(aGreaterThanOrEqualToB), GreaterOrEqual).Predictable(); aGreatherThanB = ValueOutput(nameof(aGreatherThanB), Greater).Predictable(); Requirement(a, aLessThanB); Requirement(b, aLessThanB); Requirement(a, aLessThanOrEqualToB); Requirement(b, aLessThanOrEqualToB); Requirement(a, aEqualToB); Requirement(b, aEqualToB); Requirement(a, aGreaterThanOrEqualToB); Requirement(b, aGreaterThanOrEqualToB); Requirement(a, aGreatherThanB); Requirement(b, aGreatherThanB); } private bool Less(Flow flow) { return flow.GetValue(a) < flow.GetValue(b); } private bool LessOrEqual(Flow flow) { var a = flow.GetValue(this.a); var b = flow.GetValue(this.b); return a < b || Mathf.Approximately(a, b); } private bool Equal(Flow flow) { return Mathf.Approximately(flow.GetValue(a), flow.GetValue(b)); } private bool GreaterOrEqual(Flow flow) { var a = flow.GetValue(this.a); var b = flow.GetValue(this.b); return a > b || Mathf.Approximately(a, b); } private bool Greater(Flow flow) { return flow.GetValue(a) < flow.GetValue(b); } } }