This repository has been archived on 2025-04-28. You can view files and clone it, but cannot push or open issues or pull requests.
ARPlusSystem/ARPlusSystem-250418/Library/PackageCache/com.unity.xr.arsubsystems@4.../Runtime/SerializableDictionary.cs

49 lines
1.1 KiB
C#

using System;
using System.Collections.Generic;
using UnityEngine;
namespace UnityEngine.XR.ARSubsystems
{
[Serializable]
class SerializableDictionary<TKey, TValue>
{
[Serializable]
struct KeyValuePair
{
public TKey key;
public TValue value;
}
public Dictionary<TKey, TValue> dictionary { get; } = new Dictionary<TKey, TValue>();
public void Serialize()
{
m_Storage = new KeyValuePair[dictionary.Count];
var index = 0;
foreach (var pair in dictionary)
{
m_Storage[index++] = new KeyValuePair
{
key = pair.Key,
value = pair.Value
};
}
}
public void Deserialize()
{
dictionary.Clear();
if (m_Storage == null)
return;
foreach (var pair in m_Storage)
{
dictionary.Add(pair.key, pair.value);
}
}
[SerializeField]
KeyValuePair[] m_Storage;
}
}