12using System.Collections.Generic;
14using System.Collections;
18 [Obsolete(
"It is no longer required to annotate SerializableDictionary with an SDictionary attribute")]
25 List<int> GetDuplicationInformation();
26 void ClearDuplicates();
40 IEnumerable<KeyValuePair<TKey, TValue>>,
42 ISerializationCallbackReceiver,
46 private List<TKey> _keys =
new List<TKey>();
49 private List<TValue> _values =
new List<TValue>();
52 private Dictionary<TKey, TValue> _dictionary =
new Dictionary<TKey, TValue>();
54 #region DICTIONARY API
56 public TValue
this[TKey key] {
57 get {
return _dictionary[key]; }
58 set { _dictionary[key] = value; }
61 public Dictionary<TKey, TValue>.KeyCollection
Keys {
62 get {
return _dictionary.Keys; }
65 public Dictionary<TKey, TValue>.ValueCollection
Values {
66 get {
return _dictionary.Values; }
70 get {
return _dictionary.Count; }
73 public void Add(TKey key, TValue value) {
74 _dictionary.Add(key, value);
82 return _dictionary.ContainsKey(key);
86 return _dictionary.ContainsValue(value);
90 return _dictionary.Remove(key);
94 return _dictionary.TryGetValue(key, out value);
98 return _dictionary.GetEnumerator();
101 IEnumerator IEnumerable.GetEnumerator() {
102 return _dictionary.GetEnumerator();
106 return serializableDictionary._dictionary;
120 StringBuilder toReturn =
new StringBuilder();
121 List<TKey> keys = _dictionary.Keys.ToList<TKey>();
122 List<TValue> values = _dictionary.Values.ToList<TValue>();
123 toReturn.Append(
"[");
124 for (
int i = 0; i < keys.Count; i++) {
125 toReturn.Append(
"{");
126 toReturn.Append(keys[i].
ToString());
127 toReturn.Append(
" : ");
128 toReturn.Append(values[i].
ToString());
129 toReturn.Append(
"}, \n");
131 toReturn.Remove(toReturn.Length - 3, 3);
132 toReturn.Append(
"]");
133 return toReturn.ToString();
139 if (_keys !=
null && _values !=
null) {
140 int count = Mathf.Min(_keys.Count, _values.Count);
141 for (
int i = 0; i < count; i++) {
143 TValue value = _values[i];
149 _dictionary[key] = value;
160 public List<int> GetDuplicationInformation() {
161 Dictionary<TKey, int> info =
new Dictionary<TKey, int>();
163 for (
int i = 0; i < _keys.Count; i++) {
169 if (info.ContainsKey(key)) {
176 List<int> dups =
new List<int>();
177 for (
int i = 0; i < _keys.Count; i++) {
189 public void ClearDuplicates() {
190 HashSet<TKey> takenKeys =
new HashSet<TKey>();
191 for (
int i = 0; i < _keys.Count; i++) {
193 if (takenKeys.Contains(key)) {
206 _keys =
new List<TKey>();
209 if (_values ==
null) {
210 _values =
new List<TValue>();
214 for (
int i = _keys.Count; i-- != 0;) {
216 if (key ==
null)
continue;
218 if (!_dictionary.ContainsKey(key)) {
225 Dictionary<TKey, TValue>.Enumerator enumerator = _dictionary.GetEnumerator();
226 while (enumerator.MoveNext()) {
227 var pair = enumerator.Current;
230 if (!_keys.Contains(pair.Key)) {
232 _values.Add(pair.Value);
236 _values.Add(pair.Value);
241 IEnumerator<KeyValuePair<TKey, TValue>> IEnumerable<KeyValuePair<TKey, TValue>>.GetEnumerator() {
242 return ((IEnumerable<KeyValuePair<TKey, TValue>>)_dictionary).GetEnumerator();
In order to have this class be serialized, you will always need to create your own non-generic versio...
virtual float KeyDisplayRatio()
Returns how much of the display space should be allocated to the key. Should be a value in the range ...
bool TryGetValue(TKey key, out TValue value)
Dictionary< TKey, TValue >.ValueCollection Values
Dictionary< TKey, TValue >.Enumerator GetEnumerator()
bool ContainsValue(TValue value)
override string ToString()
void OnAfterDeserialize()
void Add(TKey key, TValue value)
bool ContainsKey(TKey key)
Dictionary< TKey, TValue >.KeyCollection Keys