A game about forced loneliness, made by TACStudios
1using System.Collections;
2
3namespace Unity.VisualScripting
4{
5 /// <summary>
6 /// Gets a dictionary item with the specified key.
7 /// </summary>
8 [UnitCategory("Collections/Dictionaries")]
9 [UnitSurtitle("Dictionary")]
10 [UnitShortTitle("Get Item")]
11 [UnitOrder(0)]
12 [TypeIcon(typeof(IDictionary))]
13 public sealed class GetDictionaryItem : Unit
14 {
15 /// <summary>
16 /// The dictionary.
17 /// </summary>
18 [DoNotSerialize]
19 [PortLabelHidden]
20 public ValueInput dictionary { get; private set; }
21
22 /// <summary>
23 /// The key of the item.
24 /// </summary>
25 [DoNotSerialize]
26 public ValueInput key { get; private set; }
27
28 /// <summary>
29 /// The value of the item.
30 /// </summary>
31 [DoNotSerialize]
32 [PortLabelHidden]
33 public ValueOutput value { get; private set; }
34
35 protected override void Definition()
36 {
37 dictionary = ValueInput<IDictionary>(nameof(dictionary));
38 key = ValueInput<object>(nameof(key));
39 value = ValueOutput(nameof(value), Get);
40
41 Requirement(dictionary, value);
42 Requirement(key, value);
43 }
44
45 private object Get(Flow flow)
46 {
47 var dictionary = flow.GetValue<IDictionary>(this.dictionary);
48 var key = flow.GetValue<object>(this.key);
49
50 return dictionary[key];
51 }
52 }
53}