private void AddNewItem() { if (_Dictionary.Count == _Dictionary.Max && _Dictionary.IsSizeLimited) { UnityEngine.Debug.Log("TOO MANY ITEMS!"); return; } TK key; if (typeof(TK) == typeof(string)) { int i = 0; while (_Dictionary.Keys.Contains((TK)Convert.ChangeType(i, typeof(TK)))) { i++; } key = (TK)Convert.ChangeType(i, typeof(TK)); } else if (typeof(TK) == typeof(int)) { int i = 0; while (_Dictionary.Keys.Contains((TK)(object)i)) { i++; } key = (TK)(object)i; } else if (typeof(TK).IsEnum) { _Dictionary.EnableLimit(Enum.GetValues(typeof(TK)).Cast <TK>().ToList <TK>().Count); List <TK> possible = Enum.GetValues(typeof(TK)).Cast <TK>().Except(_Dictionary.Keys).ToList <TK>(); if (possible.Count == 0) { key = _Dictionary.Keys.ElementAt(0); } else { key = possible.ElementAt(0); } } else { key = default(TK); } var value = default(TV); try { _Dictionary.Add(key, value); } catch (Exception e) { UnityEngine.Debug.Log(e.Message); } }