namespace Unity.VisualScripting { [UnitCategory("Logic")] public abstract class BinaryComparisonUnit : Unit { /// /// The first input. /// [DoNotSerialize] public ValueInput a { get; private set; } /// /// The second input. /// [DoNotSerialize] public ValueInput b { get; private set; } [DoNotSerialize] public virtual ValueOutput comparison { get; private set; } /// /// Whether the compared inputs are numbers. /// [Serialize] [Inspectable] [InspectorToggleLeft] public bool numeric { get; set; } = true; // Backwards compatibility protected virtual string outputKey => nameof(comparison); protected override void Definition() { if (numeric) { a = ValueInput(nameof(a)); b = ValueInput(nameof(b), 0); comparison = ValueOutput(outputKey, NumericComparison).Predictable(); } else { a = ValueInput(nameof(a)).AllowsNull(); b = ValueInput(nameof(b)).AllowsNull(); comparison = ValueOutput(outputKey, GenericComparison).Predictable(); } Requirement(a, comparison); Requirement(b, comparison); } private bool NumericComparison(Flow flow) { return NumericComparison(flow.GetValue(a), flow.GetValue(b)); } private bool GenericComparison(Flow flow) { return GenericComparison(flow.GetValue(a), flow.GetValue(b)); } protected abstract bool NumericComparison(float a, float b); protected abstract bool GenericComparison(object a, object b); } }