Minimum#
Collections / Minimum
Can Read
Cannot Write
Description#
The smallest value found in a collection read as numbers
Parameters#
| Name | Description |
|---|---|
| Collection | The collection whose smallest item is returned |
Code#
using System;
using UnityEngine;
using VisualScript.Icons;
namespace VisualScript.Runtime
{
[Get]
[Title("Minimum")]
[Category("Collections/Minimum")]
[Description("The smallest value found in a collection read as numbers")]
[Image(typeof(IconStack), ColorTheme.Type.Teal, typeof(BadgeArrowDown))]
[Parameter("Collection", "The collection whose smallest item is returned")]
[Keywords("Min", "Lowest", "Smallest", "Least", "List", "Array")]
[Serializable]
public class TypeNumberCollectionMin : TypeNumber
{
[SerializeField] private GetCollection m_Collection = new GetCollection();
public override double Get(Args args)
{
using Args scoped = Args.Get(args);
int count = this.m_Collection.Capture(scoped);
if (count == 0) return 0f;
double min = 0f;
bool hasValue = false;
for (int i = 0; i < count; ++i)
{
if (!ArgsCollectionParameters.TryGetItem(this.m_Collection, scoped, i, out double item)) continue;
min = hasValue ? Math.Min(min, item) : item;
hasValue = true;
}
return min;
}
public override string ToString()
{
return $"Min of {this.m_Collection}";
}
protected override SubscriptionMode Subscription => SubscriptionMode.OnChange;
}
}