A game about forced loneliness, made by TACStudios
1namespace Unity.VisualScripting
2{
3 [UnitOrder(501)]
4 public abstract class Lerp<T> : Unit
5 {
6 /// <summary>
7 /// The first value.
8 /// </summary>
9 [DoNotSerialize]
10 public ValueInput a { get; private set; }
11
12 /// <summary>
13 /// The second value.
14 /// </summary>
15 [DoNotSerialize]
16 public ValueInput b { get; private set; }
17
18 /// <summary>
19 /// The interpolation value.
20 /// </summary>
21 [DoNotSerialize]
22 public ValueInput t { get; private set; }
23
24 /// <summary>
25 /// The linear interpolation between A and B at T.
26 /// </summary>
27 [DoNotSerialize]
28 [PortLabelHidden]
29 public ValueOutput interpolation { get; private set; }
30
31 [DoNotSerialize]
32 protected virtual T defaultA => default(T);
33
34 [DoNotSerialize]
35 protected virtual T defaultB => default(T);
36
37 protected override void Definition()
38 {
39 a = ValueInput(nameof(a), defaultA);
40 b = ValueInput(nameof(b), defaultB);
41 t = ValueInput<float>(nameof(t), 0);
42 interpolation = ValueOutput(nameof(interpolation), Operation).Predictable();
43
44 Requirement(a, interpolation);
45 Requirement(b, interpolation);
46 Requirement(t, interpolation);
47 }
48
49 private T Operation(Flow flow)
50 {
51 return Operation(flow.GetValue<T>(a), flow.GetValue<T>(b), flow.GetValue<float>(t));
52 }
53
54 public abstract T Operation(T a, T b, float t);
55 }
56}