Maze / Library /PackageCache /com.unity.visualscripting@1.8.0 /Runtime /VisualScripting.Flow /Framework /Logic /NumericComparison.cs
| using System; | |
| using UnityEngine; | |
| namespace Unity.VisualScripting | |
| { | |
| /// <summary> | |
| /// Compares two numeric inputs. | |
| /// </summary> | |
| [] | |
| [] | |
| [] | |
| [] | |
| [] | |
| [] | |
| public sealed class NumericComparison : Unit | |
| { | |
| /// <summary> | |
| /// The first input. | |
| /// </summary> | |
| [] | |
| public ValueInput a { get; private set; } | |
| /// <summary> | |
| /// The second input. | |
| /// </summary> | |
| [] | |
| public ValueInput b { get; private set; } | |
| /// <summary> | |
| /// Whether A is less than B. | |
| /// </summary> | |
| [] | |
| [] | |
| public ValueOutput aLessThanB { get; private set; } | |
| /// <summary> | |
| /// Whether A is less than or equal to B. | |
| /// </summary> | |
| [] | |
| [] | |
| public ValueOutput aLessThanOrEqualToB { get; private set; } | |
| /// <summary> | |
| /// Whether A is equal to B. | |
| /// </summary> | |
| [] | |
| [] | |
| public ValueOutput aEqualToB { get; private set; } | |
| /// <summary> | |
| /// Whether A is greater than or equal to B. | |
| /// </summary> | |
| [] | |
| [] | |
| public ValueOutput aGreaterThanOrEqualToB { get; private set; } | |
| /// <summary> | |
| /// Whether A is greater than B. | |
| /// </summary> | |
| [] | |
| [] | |
| 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); | |
| } | |
| } | |
| } | |