using UnityEngine; namespace Unity.VisualScripting { [UnitOrder(502)] public abstract class MoveTowards : Unit { /// /// The current value. /// [DoNotSerialize] public ValueInput current { get; private set; } /// /// The target value. /// [DoNotSerialize] public ValueInput target { get; private set; } /// /// The maximum scalar increment between values. /// [DoNotSerialize] public ValueInput maxDelta { get; private set; } /// /// The incremented value. /// [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(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(current), flow.GetValue(target), flow.GetValue(maxDelta) * (perSecond ? Time.deltaTime : 1)); } public abstract T Operation(T current, T target, float maxDelta); } }