using System.Collections; namespace Unity.VisualScripting { /// /// Sets the value of a dictionary item with the specified key. /// [UnitCategory("Collections/Dictionaries")] [UnitSurtitle("Dictionary")] [UnitShortTitle("Set Item")] [UnitOrder(1)] [TypeIcon(typeof(IDictionary))] public sealed class SetDictionaryItem : Unit { /// /// The entry point for the node. /// [DoNotSerialize] [PortLabelHidden] public ControlInput enter { get; private set; } /// /// The dictionary. /// [DoNotSerialize] [PortLabelHidden] public ValueInput dictionary { get; private set; } /// /// The key of the item to set. /// [DoNotSerialize] public ValueInput key { get; private set; } /// /// The value to assign to the item. /// [DoNotSerialize] public ValueInput value { 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); dictionary = ValueInput(nameof(dictionary)); key = ValueInput(nameof(key)); value = ValueInput(nameof(value)); exit = ControlOutput(nameof(exit)); Requirement(dictionary, enter); Requirement(key, enter); Requirement(value, enter); Succession(enter, exit); } public ControlOutput Set(Flow flow) { var dictionary = flow.GetValue(this.dictionary); var key = flow.GetValue(this.key); var value = flow.GetValue(this.value); dictionary[key] = value; return exit; } } }