using System; using System.Collections; using System.Collections.Generic; using System.Linq; using UnityEngine; public class KVPair { public Key key; public Value value; public KVPair() { } public KVPair(Key key, Value value) { this.key = key; this.value = value; } } public static class DictionaryExtension { public static bool IsAvailable(this Dictionary dictionary) { return dictionary != null && dictionary.Count > 0; } public static KVPair GetAtIndex(this Dictionary dictionary, int index) { List keys = dictionary.Keys.ToList(); List values = dictionary.Values.ToList(); KVPair kvPair = new KVPair(); kvPair.key = keys[index]; kvPair.value = values[index]; return kvPair; } public static int MyMin(this Dictionary dictionary, Func func) { List keys = dictionary.Keys.ToList(); List values = dictionary.Values.ToList(); float min = func(keys[0], values[0]); int minIndex = 0; for (int i = 1; i < keys.Count; i++) { if (min > func(keys[i], values[i])) { min = func(keys[i], values[i]); minIndex = i; } } return minIndex; } public static int MyMax(this Dictionary dictionary, Func func) { List keys = dictionary.Keys.ToList(); List values = dictionary.Values.ToList(); float max = func(keys[0], values[0]); int maxIndex = 0; for (int i = 1; i < keys.Count; i++) { if (max < func(keys[i], values[i])) { max = func(keys[i], values[i]); maxIndex = i; } } return maxIndex; } }