using System.Collections; namespace Unity.VisualScripting { /// /// Sets the item at the specified index of a list. /// [UnitCategory("Collections/Lists")] [UnitSurtitle("List")] [UnitShortTitle("Set Item")] [UnitOrder(1)] [TypeIcon(typeof(IList))] public sealed class SetListItem : Unit { /// /// The entry point for the node. /// [DoNotSerialize] [PortLabelHidden] public ControlInput enter { get; private set; } /// /// The list. /// [DoNotSerialize] [PortLabelHidden] public ValueInput list { get; private set; } /// /// The zero-based index. /// [DoNotSerialize] public ValueInput index { get; private set; } /// /// The item. /// [DoNotSerialize] public ValueInput item { get; private set; } /// /// The action to execute once the item has been assigned. /// [DoNotSerialize] [PortLabelHidden] public ControlOutput exit { get; private set; } protected override void Definition() { enter = ControlInput(nameof(enter), Set); list = ValueInput(nameof(list)); index = ValueInput(nameof(index), 0); item = ValueInput(nameof(item)); exit = ControlOutput(nameof(exit)); Requirement(list, enter); Requirement(index, enter); Requirement(item, enter); Succession(enter, exit); } public ControlOutput Set(Flow flow) { var list = flow.GetValue(this.list); var index = flow.GetValue(this.index); var item = flow.GetValue(this.item); list[index] = item; return exit; } } }