A game about forced loneliness, made by TACStudios
1using System.Collections; 2 3namespace Unity.VisualScripting 4{ 5 /// <summary> 6 /// Merges two or more dictionaries together. 7 /// </summary> 8 /// <remarks> 9 /// If the same key is found more than once, only the value 10 /// of the first dictionary with this key will be used. 11 /// </remarks> 12 [UnitCategory("Collections/Dictionaries")] 13 [UnitOrder(5)] 14 public sealed class MergeDictionaries : MultiInputUnit<IDictionary> 15 { 16 /// <summary> 17 /// The merged dictionary. 18 /// </summary> 19 [DoNotSerialize] 20 [PortLabelHidden] 21 public ValueOutput dictionary { get; private set; } 22 23 protected override void Definition() 24 { 25 dictionary = ValueOutput(nameof(dictionary), Merge); 26 27 base.Definition(); 28 29 foreach (var input in multiInputs) 30 { 31 Requirement(input, dictionary); 32 } 33 } 34 35 public IDictionary Merge(Flow flow) 36 { 37 var dictionary = new AotDictionary(); 38 39 for (var i = 0; i < inputCount; i++) 40 { 41 var inputDictionary = flow.GetValue<IDictionary>(multiInputs[i]); 42 43 var enumerator = inputDictionary.GetEnumerator(); 44 45 while (enumerator.MoveNext()) 46 { 47 if (!dictionary.Contains(enumerator.Key)) 48 { 49 dictionary.Add(enumerator.Key, enumerator.Value); 50 } 51 } 52 } 53 54 return dictionary; 55 } 56 } 57}