using System.Collections; namespace Unity.VisualScripting { /// /// Gets a dictionary item with the specified key. /// [UnitCategory("Collections/Dictionaries")] [UnitSurtitle("Dictionary")] [UnitShortTitle("Get Item")] [UnitOrder(0)] [TypeIcon(typeof(IDictionary))] public sealed class GetDictionaryItem : Unit { /// /// The dictionary. /// [DoNotSerialize] [PortLabelHidden] public ValueInput dictionary { get; private set; } /// /// The key of the item. /// [DoNotSerialize] public ValueInput key { get; private set; } /// /// The value of the item. /// [DoNotSerialize] [PortLabelHidden] public ValueOutput value { get; private set; } protected override void Definition() { dictionary = ValueInput(nameof(dictionary)); key = ValueInput(nameof(key)); value = ValueOutput(nameof(value), Get); Requirement(dictionary, value); Requirement(key, value); } private object Get(Flow flow) { var dictionary = flow.GetValue(this.dictionary); var key = flow.GetValue(this.key); return dictionary[key]; } } }