A game about forced loneliness, made by TACStudios
1using System;
2using UnityEngine;
3
4namespace Unity.VisualScripting
5{
6 /// <summary>
7 /// Compares two numbers to determine if they are approximately equal (disregarding floating point precision errors).
8 /// </summary>
9 [UnitCategory("Logic")]
10 [UnitShortTitle("Equal")]
11 [UnitSubtitle("(Approximately)")]
12 [UnitOrder(7)]
13 [Obsolete("Use the Equal node with Numeric enabled instead.")]
14 public sealed class ApproximatelyEqual : Unit
15 {
16 /// <summary>
17 /// The first number.
18 /// </summary>
19 [DoNotSerialize]
20 public ValueInput a { get; private set; }
21
22 /// <summary>
23 /// The second number.
24 /// </summary>
25 [DoNotSerialize]
26 public ValueInput b { get; private set; }
27
28 /// <summary>
29 /// Whether A is approximately equal to B.
30 /// </summary>
31 [DoNotSerialize]
32 [PortLabel("A \u2248 B")]
33 public ValueOutput equal { get; private set; }
34
35 protected override void Definition()
36 {
37 a = ValueInput<float>(nameof(a));
38 b = ValueInput<float>(nameof(b), 0);
39 equal = ValueOutput(nameof(equal), Comparison).Predictable();
40
41 Requirement(a, equal);
42 Requirement(b, equal);
43 }
44
45 public bool Comparison(Flow flow)
46 {
47 return Mathf.Approximately(flow.GetValue<float>(a), flow.GetValue<float>(b));
48 }
49 }
50}