From a22c505984697881f5f911a165ee022087b69e09 Mon Sep 17 00:00:00 2001 From: chai <215380520@qq.com> Date: Mon, 20 May 2024 22:36:58 +0800 Subject: *rename --- .../Decompile/UnitySerializedDictionary.cs | 35 ++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 Thronefall_v1.0/Decompile/UnitySerializedDictionary.cs (limited to 'Thronefall_v1.0/Decompile/UnitySerializedDictionary.cs') diff --git a/Thronefall_v1.0/Decompile/UnitySerializedDictionary.cs b/Thronefall_v1.0/Decompile/UnitySerializedDictionary.cs new file mode 100644 index 0000000..3fc1906 --- /dev/null +++ b/Thronefall_v1.0/Decompile/UnitySerializedDictionary.cs @@ -0,0 +1,35 @@ +using System.Collections.Generic; +using UnityEngine; + +public abstract class UnitySerializedDictionary : Dictionary, ISerializationCallbackReceiver +{ + [SerializeField] + [HideInInspector] + private List keyData = new List(); + + [SerializeField] + [HideInInspector] + private List valueData = new List(); + + void ISerializationCallbackReceiver.OnAfterDeserialize() + { + Clear(); + for (int i = 0; i < keyData.Count && i < valueData.Count; i++) + { + base[keyData[i]] = valueData[i]; + } + } + + void ISerializationCallbackReceiver.OnBeforeSerialize() + { + keyData.Clear(); + valueData.Clear(); + using Enumerator enumerator = GetEnumerator(); + while (enumerator.MoveNext()) + { + KeyValuePair current = enumerator.Current; + keyData.Add(current.Key); + valueData.Add(current.Value); + } + } +} -- cgit v1.1-26-g67d0