File size: 1,859 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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | using UnityEngine;
namespace Unity.VisualScripting
{
[UnitOrder(502)]
public abstract class MoveTowards<T> : Unit
{
/// <summary>
/// The current value.
/// </summary>
[DoNotSerialize]
public ValueInput current { get; private set; }
/// <summary>
/// The target value.
/// </summary>
[DoNotSerialize]
public ValueInput target { get; private set; }
/// <summary>
/// The maximum scalar increment between values.
/// </summary>
[DoNotSerialize]
public ValueInput maxDelta { get; private set; }
/// <summary>
/// The incremented value.
/// </summary>
[DoNotSerialize]
[PortLabelHidden]
public ValueOutput result { get; private set; }
[Serialize, Inspectable, UnitHeaderInspectable("Per Second"), InspectorToggleLeft]
public bool perSecond { get; set; }
[DoNotSerialize]
protected virtual T defaultCurrent => default(T);
[DoNotSerialize]
protected virtual T defaultTarget => default(T);
protected override void Definition()
{
current = ValueInput(nameof(current), defaultCurrent);
target = ValueInput(nameof(target), defaultTarget);
maxDelta = ValueInput<float>(nameof(maxDelta), 0);
result = ValueOutput(nameof(result), Operation);
Requirement(current, result);
Requirement(target, result);
Requirement(maxDelta, result);
}
private T Operation(Flow flow)
{
return Operation(flow.GetValue<T>(current), flow.GetValue<T>(target), flow.GetValue<float>(maxDelta) * (perSecond ? Time.deltaTime : 1));
}
public abstract T Operation(T current, T target, float maxDelta);
}
}
|