// Serialization.cs using UnityEngine; using System.Collections; using System.Collections.Generic; using System; // List [Serializable] public class Serialization { [SerializeField] List target; public List ToList() { return target; } public Serialization(List target) { this.target = target; } } // Dictionary [Serializable] public class Serialization : ISerializationCallbackReceiver { [SerializeField] List keys; [SerializeField] List values; Dictionary target; public Dictionary ToDictionary() { return target; } public Serialization(Dictionary target) { this.target = target; } public void OnBeforeSerialize() { keys = new List(target.Keys); values = new List(target.Values); } public void OnAfterDeserialize() { var count = Math.Min(keys.Count, values.Count); target = new Dictionary(count); for (var i = 0; i < count; ++i) { target.Add(keys[i], values[i]); } } }