2023-06-25 15:51:54 +02:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
namespace VertexColor.ScenePartition
|
|
|
|
{
|
2023-06-26 01:03:14 +02:00
|
|
|
[System.Serializable]
|
2023-06-25 15:51:54 +02:00
|
|
|
public class SerializableDictionary<TKey, TValue> : Dictionary<TKey, TValue>, ISerializationCallbackReceiver
|
|
|
|
{
|
|
|
|
[SerializeField]
|
2023-06-26 01:03:14 +02:00
|
|
|
private List<TKey> dictionaryKeys = new List<TKey>();
|
|
|
|
|
2023-06-25 15:51:54 +02:00
|
|
|
[SerializeField]
|
2023-06-26 01:03:14 +02:00
|
|
|
private List<TValue> dictionaryValues = new List<TValue>();
|
2023-06-25 15:51:54 +02:00
|
|
|
|
|
|
|
public void OnBeforeSerialize()
|
|
|
|
{
|
2023-06-26 01:03:14 +02:00
|
|
|
dictionaryKeys.Clear();
|
|
|
|
dictionaryValues.Clear();
|
2023-06-25 15:51:54 +02:00
|
|
|
|
2023-06-26 01:03:14 +02:00
|
|
|
foreach (KeyValuePair<TKey, TValue> item in this)
|
2023-06-25 15:51:54 +02:00
|
|
|
{
|
2023-06-26 01:03:14 +02:00
|
|
|
dictionaryKeys.Add(item.Key);
|
|
|
|
dictionaryValues.Add(item.Value);
|
2023-06-25 15:51:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void OnAfterDeserialize()
|
|
|
|
{
|
|
|
|
Clear();
|
|
|
|
|
2023-06-26 01:03:14 +02:00
|
|
|
if (dictionaryKeys.Count != dictionaryValues.Count) return;
|
2023-06-25 15:51:54 +02:00
|
|
|
|
2023-06-26 01:03:14 +02:00
|
|
|
for (int i = 0; i < dictionaryKeys.Count; i++)
|
2023-06-25 15:51:54 +02:00
|
|
|
{
|
2023-06-26 01:03:14 +02:00
|
|
|
Add(dictionaryKeys[i], dictionaryValues[i]);
|
2023-06-25 15:51:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-26 01:03:14 +02:00
|
|
|
[System.Serializable]
|
2023-06-25 15:51:54 +02:00
|
|
|
public class SerializableSortedList<TKey, TValue> : SortedList<TKey, TValue>, ISerializationCallbackReceiver
|
|
|
|
{
|
|
|
|
[SerializeField]
|
2023-06-26 01:03:14 +02:00
|
|
|
private List<TKey> sortedListKeys = new List<TKey>();
|
|
|
|
|
2023-06-25 15:51:54 +02:00
|
|
|
[SerializeField]
|
2023-06-26 01:03:14 +02:00
|
|
|
private List<TValue> sortedListValues = new List<TValue>();
|
2023-06-25 15:51:54 +02:00
|
|
|
|
|
|
|
public void OnBeforeSerialize()
|
|
|
|
{
|
2023-06-26 01:03:14 +02:00
|
|
|
sortedListKeys.Clear();
|
|
|
|
sortedListValues.Clear();
|
2023-06-25 15:51:54 +02:00
|
|
|
|
2023-06-26 01:03:14 +02:00
|
|
|
foreach (KeyValuePair<TKey, TValue> item in this)
|
2023-06-25 15:51:54 +02:00
|
|
|
{
|
2023-06-26 01:03:14 +02:00
|
|
|
sortedListKeys.Add(item.Key);
|
|
|
|
sortedListValues.Add(item.Value);
|
2023-06-25 15:51:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void OnAfterDeserialize()
|
|
|
|
{
|
|
|
|
Clear();
|
|
|
|
|
2023-06-26 01:03:14 +02:00
|
|
|
if (sortedListKeys.Count != sortedListValues.Count) return;
|
2023-06-25 15:51:54 +02:00
|
|
|
|
2023-06-26 01:03:14 +02:00
|
|
|
for (int i = 0; i < sortedListKeys.Count; i++)
|
2023-06-25 15:51:54 +02:00
|
|
|
{
|
2023-06-26 01:03:14 +02:00
|
|
|
Add(sortedListKeys[i], sortedListValues[i]);
|
2023-06-25 15:51:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-26 01:03:14 +02:00
|
|
|
[System.Serializable]
|
2023-06-25 15:51:54 +02:00
|
|
|
public class SerializableSortedSet<T> : SortedSet<T>, ISerializationCallbackReceiver
|
|
|
|
{
|
|
|
|
[SerializeField]
|
2023-06-26 01:03:14 +02:00
|
|
|
private List<T> sortedSetValues = new List<T>();
|
2023-06-25 15:51:54 +02:00
|
|
|
|
|
|
|
public void OnBeforeSerialize()
|
|
|
|
{
|
2023-06-26 01:03:14 +02:00
|
|
|
sortedSetValues.Clear();
|
|
|
|
sortedSetValues.AddRange(this);
|
2023-06-25 15:51:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void OnAfterDeserialize()
|
|
|
|
{
|
|
|
|
Clear();
|
|
|
|
|
2023-06-26 01:03:14 +02:00
|
|
|
for (int i = 0; i < sortedSetValues.Count; i++)
|
2023-06-25 15:51:54 +02:00
|
|
|
{
|
2023-06-26 01:03:14 +02:00
|
|
|
Add(sortedSetValues[i]);
|
2023-06-25 15:51:54 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|