[System.Serializable] public class SerializableDictionary<TKey, TValue> : Dictionary<TKey, TValue>, ISerializationCallbackReceiver { [SerializeField] private List<TKey> keys = new List<TKey>(); [SerializeField] private List<TValue> values = new List<TValue>(); // save the dictionary to lists public void OnBeforeSerialize() { keys.Clear(); values.Clear(); foreach (KeyValuePair<TKey, TValue> pair in this) { keys.Add(pair.Key); values.Add(pair.Value); } } // load dictionary from lists public void OnAfterDeserialize() { this.Clear(); if (keys.Count != values.Count) throw new Exception("there are " + keys.Count + " keys and " + values.Count + " values after deserialization. Make sure that both key and value types are serializable."); for (int i = 0; i < keys.Count; i++) this.Add(keys[i], values[i]); } }


이 클래슀 λ§Œλ“  λ‹€μŒμ—, Dictionary λŒ€μ‹ μ— SerializableDictionary μ‚¬μš©ν•˜μ‹œλ©΄ λ©λ‹ˆλ‹€. 그리고 [SerializeField] private SerializableDictionary<string, int> 와 같이 μž‘μ„±ν•˜μ‹œλ©΄ μΈμŠ€νŽ™ν„° 창에 λ”•μ…”λ„ˆλ¦¬κ°€ λœΉλ‹ˆλ‹Ή.





7cf3c028e2f206a26d81f6e74283716f

μ΄λ ‡κ²Œ μ§ ! μΈμŠ€νŽ™ν„°μ°½μ— λ”•μ…”λ„ˆλ¦¬κ°€ λ„μ›Œμ‘Œλ„€μš”γ…Žγ…Ž