using System.Collections;
namespace Unity.VisualScripting
{
///
/// Gets the item at the specified index of a list.
///
[UnitCategory("Collections/Lists")]
[UnitSurtitle("List")]
[UnitShortTitle("Get Item")]
[UnitOrder(0)]
[TypeIcon(typeof(IList))]
public sealed class GetListItem : Unit
{
///
/// The list.
///
[DoNotSerialize]
[PortLabelHidden]
public ValueInput list { get; private set; }
///
/// The zero-based index.
///
[DoNotSerialize]
public ValueInput index { get; private set; }
///
/// The item.
///
[DoNotSerialize]
[PortLabelHidden]
public ValueOutput item { get; private set; }
protected override void Definition()
{
list = ValueInput(nameof(list));
index = ValueInput(nameof(index), 0);
item = ValueOutput(nameof(item), Get);
Requirement(list, item);
Requirement(index, item);
}
public object Get(Flow flow)
{
var list = flow.GetValue(this.list);
var index = flow.GetValue(this.index);
return list[index];
}
}
}