File size: 3,706 Bytes
18a519f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
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);
        }
    }
}