using System.Collections.Generic; using UnityEngine; namespace VertexColor.ScenePartition { [System.Serializable] public class SerializableDictionary : Dictionary, ISerializationCallbackReceiver { [SerializeField] private List dictionaryKeys = new List(); [SerializeField] private List dictionaryValues = new List(); public void OnBeforeSerialize() { dictionaryKeys.Clear(); dictionaryValues.Clear(); foreach (KeyValuePair item in this) { dictionaryKeys.Add(item.Key); dictionaryValues.Add(item.Value); } } public void OnAfterDeserialize() { Clear(); if (dictionaryKeys.Count != dictionaryValues.Count) return; for (int i = 0; i < dictionaryKeys.Count; i++) { Add(dictionaryKeys[i], dictionaryValues[i]); } } } [System.Serializable] public class SerializableSortedList : SortedList, ISerializationCallbackReceiver { [SerializeField] private List sortedListKeys = new List(); [SerializeField] private List sortedListValues = new List(); public void OnBeforeSerialize() { sortedListKeys.Clear(); sortedListValues.Clear(); foreach (KeyValuePair item in this) { sortedListKeys.Add(item.Key); sortedListValues.Add(item.Value); } } public void OnAfterDeserialize() { Clear(); if (sortedListKeys.Count != sortedListValues.Count) return; for (int i = 0; i < sortedListKeys.Count; i++) { Add(sortedListKeys[i], sortedListValues[i]); } } } [System.Serializable] public class SerializableSortedSet : SortedSet, ISerializationCallbackReceiver { [SerializeField] private List sortedSetValues = new List(); public void OnBeforeSerialize() { sortedSetValues.Clear(); sortedSetValues.AddRange(this); } public void OnAfterDeserialize() { Clear(); for (int i = 0; i < sortedSetValues.Count; i++) { Add(sortedSetValues[i]); } } } }