A game about forced loneliness, made by TACStudios
1using System;
2using UnityEngine;
3
4namespace Unity.VisualScripting
5{
6 /// <summary>
7 /// Compares two numeric inputs.
8 /// </summary>
9 [UnitCategory("Logic")]
10 [UnitTitle("Numeric Comparison")]
11 [UnitSurtitle("Numeric")]
12 [UnitShortTitle("Comparison")]
13 [UnitOrder(99)]
14 [Obsolete("Use the Comparison node with Numeric enabled instead.")]
15 public sealed class NumericComparison : Unit
16 {
17 /// <summary>
18 /// The first input.
19 /// </summary>
20 [DoNotSerialize]
21 public ValueInput a { get; private set; }
22
23 /// <summary>
24 /// The second input.
25 /// </summary>
26 [DoNotSerialize]
27 public ValueInput b { get; private set; }
28
29 /// <summary>
30 /// Whether A is less than B.
31 /// </summary>
32 [DoNotSerialize]
33 [PortLabel("A < B")]
34 public ValueOutput aLessThanB { get; private set; }
35
36 /// <summary>
37 /// Whether A is less than or equal to B.
38 /// </summary>
39 [DoNotSerialize]
40 [PortLabel("A \u2264 B")]
41 public ValueOutput aLessThanOrEqualToB { get; private set; }
42
43 /// <summary>
44 /// Whether A is equal to B.
45 /// </summary>
46 [DoNotSerialize]
47 [PortLabel("A = B")]
48 public ValueOutput aEqualToB { get; private set; }
49
50 /// <summary>
51 /// Whether A is greater than or equal to B.
52 /// </summary>
53 [DoNotSerialize]
54 [PortLabel("A \u2265 B")]
55 public ValueOutput aGreaterThanOrEqualToB { get; private set; }
56
57 /// <summary>
58 /// Whether A is greater than B.
59 /// </summary>
60 [DoNotSerialize]
61 [PortLabel("A > B")]
62 public ValueOutput aGreatherThanB { get; private set; }
63
64 protected override void Definition()
65 {
66 a = ValueInput<float>(nameof(a));
67 b = ValueInput<float>(nameof(b), 0);
68
69 aLessThanB = ValueOutput(nameof(aLessThanB), Less).Predictable();
70 aLessThanOrEqualToB = ValueOutput(nameof(aLessThanOrEqualToB), LessOrEqual).Predictable();
71 aEqualToB = ValueOutput(nameof(aEqualToB), Equal).Predictable();
72 aGreaterThanOrEqualToB = ValueOutput(nameof(aGreaterThanOrEqualToB), GreaterOrEqual).Predictable();
73 aGreatherThanB = ValueOutput(nameof(aGreatherThanB), Greater).Predictable();
74
75 Requirement(a, aLessThanB);
76 Requirement(b, aLessThanB);
77
78 Requirement(a, aLessThanOrEqualToB);
79 Requirement(b, aLessThanOrEqualToB);
80
81 Requirement(a, aEqualToB);
82 Requirement(b, aEqualToB);
83
84 Requirement(a, aGreaterThanOrEqualToB);
85 Requirement(b, aGreaterThanOrEqualToB);
86
87 Requirement(a, aGreatherThanB);
88 Requirement(b, aGreatherThanB);
89 }
90
91 private bool Less(Flow flow)
92 {
93 return flow.GetValue<float>(a) < flow.GetValue<float>(b);
94 }
95
96 private bool LessOrEqual(Flow flow)
97 {
98 var a = flow.GetValue<float>(this.a);
99 var b = flow.GetValue<float>(this.b);
100 return a < b || Mathf.Approximately(a, b);
101 }
102
103 private bool Equal(Flow flow)
104 {
105 return Mathf.Approximately(flow.GetValue<float>(a), flow.GetValue<float>(b));
106 }
107
108 private bool GreaterOrEqual(Flow flow)
109 {
110 var a = flow.GetValue<float>(this.a);
111 var b = flow.GetValue<float>(this.b);
112 return a > b || Mathf.Approximately(a, b);
113 }
114
115 private bool Greater(Flow flow)
116 {
117 return flow.GetValue<float>(a) < flow.GetValue<float>(b);
118 }
119 }
120}