added serialzed dictionary

This commit is contained in:
Sebastian Bularca
2026-03-19 22:20:34 +01:00
parent fedd1961a0
commit 9ec4c75ce2
129 changed files with 4088 additions and 0 deletions

View File

@@ -0,0 +1,56 @@
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
namespace AYellowpaper.SerializedCollections
{
[System.Serializable]
public partial class SerializedDictionary<TKey, TValue> : Dictionary<TKey, TValue>, ISerializationCallbackReceiver
{
[SerializeField]
internal List<SerializedKeyValuePair<TKey, TValue>> _serializedList = new List<SerializedKeyValuePair<TKey, TValue>>();
#if UNITY_EDITOR
internal IKeyable LookupTable
{
get
{
if (_lookupTable == null)
_lookupTable = new DictionaryLookupTable<TKey, TValue>(this);
return _lookupTable;
}
}
private DictionaryLookupTable<TKey, TValue> _lookupTable;
#endif
public void OnAfterDeserialize()
{
Clear();
foreach (var kvp in _serializedList)
{
#if UNITY_EDITOR
if (!ContainsKey(kvp.Key))
Add(kvp.Key, kvp.Value);
#else
Add(kvp.Key, kvp.Value);
#endif
}
#if UNITY_EDITOR
LookupTable.RecalculateOccurences();
#else
_serializedList.Clear();
#endif
}
public void OnBeforeSerialize()
{
#if UNITY_EDITOR
if (UnityEditor.BuildPipeline.isBuildingPlayer)
LookupTable.RemoveDuplicates();
#endif
}
}
}