using System.Collections; namespace Unity.VisualScripting { /// /// Removes a dictionary item with a specified key. /// [UnitCategory("Collections/Dictionaries")] [UnitSurtitle("Dictionary")] [UnitShortTitle("Remove Item")] [UnitOrder(3)] public sealed class RemoveDictionaryItem : Unit { /// /// The entry point for the node. /// [DoNotSerialize] [PortLabelHidden] public ControlInput enter { get; private set; } /// /// The dictionary. /// [DoNotSerialize] [PortLabel("Dictionary")] [PortLabelHidden] public ValueInput dictionaryInput { get; private set; } /// /// The dictionary without the removed item. /// Note that the input dictionary is modified directly and then returned. /// [DoNotSerialize] [PortLabel("Dictionary")] [PortLabelHidden] public ValueOutput dictionaryOutput { get; private set; } /// /// The key of the item to remove. /// [DoNotSerialize] public ValueInput key { get; private set; } /// /// The action to execute once the item has been removed. /// [DoNotSerialize] [PortLabelHidden] public ControlOutput exit { get; private set; } protected override void Definition() { enter = ControlInput(nameof(enter), Remove); dictionaryInput = ValueInput(nameof(dictionaryInput)); dictionaryOutput = ValueOutput(nameof(dictionaryOutput)); key = ValueInput(nameof(key)); exit = ControlOutput(nameof(exit)); Requirement(dictionaryInput, enter); Requirement(key, enter); Assignment(enter, dictionaryOutput); Succession(enter, exit); } public ControlOutput Remove(Flow flow) { var dictionary = flow.GetValue(dictionaryInput); var key = flow.GetValue(this.key); flow.SetValue(dictionaryOutput, dictionary); dictionary.Remove(key); return exit; } } }