/// <summary> /// Not yet documented. /// </summary> public bool Equals(EditableKeyValuePair <TKey, TValue> other) { // We consider these to be equal if only the key is equal return(PropertyValueEntry <TKey> .EqualityComparer(this.Key, other.Key)); }
/// <summary> /// Sets the actual target tree value. /// </summary> protected override void SetActualValueImplementation(int index, EditableKeyValuePair <TKey, TValue> value) { var parentProperty = this.Property.Parent; var parentEntry = (IPropertyValueEntry <TDictionary>)parentProperty.ValueEntry; var handler = (IDictionaryHandler <TKey>)parentEntry.GetDictionaryHandler(); var dict = parentEntry.Values[index]; TKey oldKey = handler.GetKey(index, this.Property.Index); TValue oldValue; dict.TryGetValue(oldKey, out oldValue); TKey newKey = value.Key; TValue newValue = value.Value; if (!PropertyValueEntry <TKey> .EqualityComparer(oldKey, newKey)) { // Key has changed; ignore if new key already exists in dictionary if (dict.ContainsKey(newKey)) { this.hasTempInvalidKey = true; this.tempInvalidKey = newKey; } else { bool isPrefab = this.SerializationBackend == SerializationBackend.ODIN && this.Property.Tree.HasPrefabs; this.hasTempInvalidKey = false; this.tempInvalidKey = default(TKey); dict.Remove(oldKey); dict.Add(newKey, newValue); if (isPrefab && handler.SupportsPrefabModifications) { this.Property.Tree.RegisterPrefabDictionaryRemoveKeyModification(parentProperty, index, oldKey); this.Property.Tree.RegisterPrefabDictionaryAddKeyModification(parentProperty, index, newKey); } // // Changing just one key may have changed the entire ordering of the dictionary. // Keep everything valid by refreshing the names and paths of every single child // property of the dictionary. // handler.ForceUpdate(); parentProperty.Children.ClearPathCache(); parentProperty.Children.Update(); for (int i = 0; i < parentProperty.Children.Count; i++) { parentProperty.Children[i].ForceUpdatePropertyNameAndPath(i); } // // Get the value entry which now represents the new key, and register a value // modification for it immediately, so as not to lose the old value. // if (isPrefab) { string childName = DictionaryKeyUtility.GetDictionaryKeyString(newKey); var child = parentProperty.Children[childName]; child.ValueEntry.Update(); child = child.Children["Value"]; child.ValueEntry.Update(); if (handler.SupportsPrefabModifications) { this.Property.Tree.RegisterPrefabValueModification(child, index, forceImmediate: true); } } } } else if (!PropertyValueEntry <TValue> .EqualityComparer(oldValue, newValue)) { // Only value has changed, this is much simpler dict[newKey] = newValue; } }
protected override int GetChildCount(EditableKeyValuePair <TKey, TValue> value) { return(ChildInfos[this.backend].Length); }