using UnityEngine; using System.Linq; using System.Collections; using System.Collections.Generic; public static class ExtensionDictionary { public static T2 Random(this Dictionary dic, bool remove = false, ExtList.RandomDelegate randomDelegate = null) { while (true) { int index = UnityEngine.Random.Range(0, dic.Count); T1 resultKey = dic.Keys.ToList()[index]; T2 resultValue = dic.Values.ToList()[index]; if (randomDelegate != null) { if (!randomDelegate(resultValue)) { continue; } } if (remove) { dic.Remove(resultKey); return resultValue; } else { return resultValue; } } } public static bool UniqueAdd(this Dictionary dic, T1 t1, T2 t2) { if (dic.ContainsKey(t1)) { return false; } else { dic.Add(t1, t2); return true; } } }