A game about forced loneliness, made by TACStudios
1namespace Unity.VisualScripting
2{
3 [UnitCategory("Logic")]
4 public abstract class BinaryComparisonUnit : Unit
5 {
6 /// <summary>
7 /// The first input.
8 /// </summary>
9 [DoNotSerialize]
10 public ValueInput a { get; private set; }
11
12 /// <summary>
13 /// The second input.
14 /// </summary>
15 [DoNotSerialize]
16 public ValueInput b { get; private set; }
17
18 [DoNotSerialize]
19 public virtual ValueOutput comparison { get; private set; }
20
21 /// <summary>
22 /// Whether the compared inputs are numbers.
23 /// </summary>
24 [Serialize]
25 [Inspectable]
26 [InspectorToggleLeft]
27 public bool numeric { get; set; } = true;
28
29 // Backwards compatibility
30 protected virtual string outputKey => nameof(comparison);
31
32 protected override void Definition()
33 {
34 if (numeric)
35 {
36 a = ValueInput<float>(nameof(a));
37 b = ValueInput<float>(nameof(b), 0);
38 comparison = ValueOutput(outputKey, NumericComparison).Predictable();
39 }
40 else
41 {
42 a = ValueInput<object>(nameof(a)).AllowsNull();
43 b = ValueInput<object>(nameof(b)).AllowsNull();
44 comparison = ValueOutput(outputKey, GenericComparison).Predictable();
45 }
46
47 Requirement(a, comparison);
48 Requirement(b, comparison);
49 }
50
51 private bool NumericComparison(Flow flow)
52 {
53 return NumericComparison(flow.GetValue<float>(a), flow.GetValue<float>(b));
54 }
55
56 private bool GenericComparison(Flow flow)
57 {
58 return GenericComparison(flow.GetValue(a), flow.GetValue(b));
59 }
60
61 protected abstract bool NumericComparison(float a, float b);
62
63 protected abstract bool GenericComparison(object a, object b);
64 }
65}