using System; using System.Collections.Generic; namespace UnityEngine.Rendering { // // Unity can't serialize Dictionary so here's a custom wrapper that does. Note that you have to // extend it before it can be serialized as Unity won't serialized generic-based types either. // // Example: // public sealed class MyDictionary : SerializedDictionary {} // /// /// Serialized Dictionary /// /// Key Type /// Value Type [Serializable] public class SerializedDictionary : Dictionary, ISerializationCallbackReceiver { [SerializeField] List m_Keys = new List(); [SerializeField] List m_Values = new List(); /// /// OnBeforeSerialize implementation. /// public void OnBeforeSerialize() { m_Keys.Clear(); m_Values.Clear(); foreach (var kvp in this) { m_Keys.Add(kvp.Key); m_Values.Add(kvp.Value); } } /// /// OnAfterDeserialize implementation. /// public void OnAfterDeserialize() { for (int i = 0; i < m_Keys.Count; i++) Add(m_Keys[i], m_Values[i]); m_Keys.Clear(); m_Values.Clear(); } } }