using System; using System.Collections.Generic; using UnityEngine; namespace TinaX { public class Serialization : ISerializationCallbackReceiver { [SerializeField] List keys; [SerializeField] List values; private Dictionary target; public Dictionary ToDictionary() => this.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]); } } } [Serializable] public class Serialization { [SerializeField] #pragma warning disable CA2235 // Mark all non-serializable fields List target; #pragma warning restore CA2235 // Mark all non-serializable fields public List ToList() => this.target; public Serialization(List target) { this.target = target; } } }