Singularity/Library/PackageCache/com.unity.visualscripting@1.../Runtime/VisualScripting.Flow/Framework/Math/Average.cs

44 lines
1.1 KiB
C#
Raw Permalink Normal View History

2024-05-06 14:45:45 -04:00
using System.Collections.Generic;
using System.Linq;
namespace Unity.VisualScripting
{
[UnitOrder(304)]
public abstract class Average<T> : MultiInputUnit<T>
{
/// <summary>
/// The average.
/// </summary>
[DoNotSerialize]
[PortLabelHidden]
public ValueOutput average { get; private set; }
protected override void Definition()
{
base.Definition();
average = ValueOutput(nameof(average), Operation).Predictable();
foreach (var multiInput in multiInputs)
{
Requirement(multiInput, average);
}
}
public abstract T Operation(T a, T b);
public abstract T Operation(IEnumerable<T> values);
public T Operation(Flow flow)
{
if (inputCount == 2)
{
return Operation(flow.GetValue<T>(multiInputs[0]), flow.GetValue<T>(multiInputs[1]));
}
else
{
return Operation(multiInputs.Select(flow.GetValue<T>));
}
}
}
}