File size: 1,107 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
namespace Unity.VisualScripting
{
    [UnitOrder(402)]
    public abstract class Distance<T> : Unit
    {
        /// <summary>
        /// The first vector.
        /// </summary>
        [DoNotSerialize]
        public ValueInput a { get; private set; }

        /// <summary>
        /// The second vector.
        /// </summary>
        [DoNotSerialize]
        public ValueInput b { get; private set; }

        /// <summary>
        /// The distance between A and B.
        /// </summary>
        [DoNotSerialize]
        [PortLabelHidden]
        public ValueOutput distance { get; private set; }

        protected override void Definition()
        {
            a = ValueInput<T>(nameof(a));
            b = ValueInput<T>(nameof(b));
            distance = ValueOutput(nameof(distance), Operation).Predictable();

            Requirement(a, distance);
            Requirement(b, distance);
        }

        private float Operation(Flow flow)
        {
            return Operation(flow.GetValue<T>(a), flow.GetValue<T>(b));
        }

        public abstract float Operation(T a, T b);
    }
}