123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- using System;
- using UnityEngine;
-
- namespace Unity.VisualScripting
- {
- /// <summary>
- /// Compares two numeric inputs.
- /// </summary>
- [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
- {
- /// <summary>
- /// The first input.
- /// </summary>
- [DoNotSerialize]
- public ValueInput a { get; private set; }
-
- /// <summary>
- /// The second input.
- /// </summary>
- [DoNotSerialize]
- public ValueInput b { get; private set; }
-
- /// <summary>
- /// Whether A is less than B.
- /// </summary>
- [DoNotSerialize]
- [PortLabel("A < B")]
- public ValueOutput aLessThanB { get; private set; }
-
- /// <summary>
- /// Whether A is less than or equal to B.
- /// </summary>
- [DoNotSerialize]
- [PortLabel("A \u2264 B")]
- public ValueOutput aLessThanOrEqualToB { get; private set; }
-
- /// <summary>
- /// Whether A is equal to B.
- /// </summary>
- [DoNotSerialize]
- [PortLabel("A = B")]
- public ValueOutput aEqualToB { get; private set; }
-
- /// <summary>
- /// Whether A is greater than or equal to B.
- /// </summary>
- [DoNotSerialize]
- [PortLabel("A \u2265 B")]
- public ValueOutput aGreaterThanOrEqualToB { get; private set; }
-
- /// <summary>
- /// Whether A is greater than B.
- /// </summary>
- [DoNotSerialize]
- [PortLabel("A > B")]
- public ValueOutput aGreatherThanB { get; private set; }
-
- protected override void Definition()
- {
- a = ValueInput<float>(nameof(a));
- b = ValueInput<float>(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<float>(a) < flow.GetValue<float>(b);
- }
-
- private bool LessOrEqual(Flow flow)
- {
- var a = flow.GetValue<float>(this.a);
- var b = flow.GetValue<float>(this.b);
- return a < b || Mathf.Approximately(a, b);
- }
-
- private bool Equal(Flow flow)
- {
- return Mathf.Approximately(flow.GetValue<float>(a), flow.GetValue<float>(b));
- }
-
- private bool GreaterOrEqual(Flow flow)
- {
- var a = flow.GetValue<float>(this.a);
- var b = flow.GetValue<float>(this.b);
- return a > b || Mathf.Approximately(a, b);
- }
-
- private bool Greater(Flow flow)
- {
- return flow.GetValue<float>(a) < flow.GetValue<float>(b);
- }
- }
- }
|