ExtensionDictionary.cs 533 B

12345678910111213141516171819202122232425262728
  1. using UnityEngine;
  2. using System.Linq;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. public static class ExtensionDictionary
  6. {
  7. public static T2 Random<T1, T2>(this Dictionary<T1, T2> dic)
  8. {
  9. return dic.Values.ToList().Random();
  10. }
  11. public static bool UniqueAdd<T1, T2>(this Dictionary<T1, T2> dic, T1 t1, T2 t2)
  12. {
  13. if (dic.ContainsKey(t1))
  14. {
  15. return false;
  16. }
  17. else
  18. {
  19. dic.Add(t1, t2);
  20. return true;
  21. }
  22. }
  23. }