You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

42 lines
863 B

using System;
using System.Collections.Generic;
using UnityEngine;
[Serializable]
public class SerializableDictionary<TKey, TValue>
{
[Serializable]
public class Node
{
public TKey key;
public TValue value;
}
[SerializeField] private List<Node> nodes;
private Dictionary<TKey, TValue> dictionary;
public Dictionary<TKey, TValue> Dictionary
{
get
{
if (dictionary == null)
{
dictionary = ToDictionary();
}
return dictionary;
}
}
private Dictionary<TKey, TValue> ToDictionary()
{
Dictionary<TKey, TValue> dictionary = new Dictionary<TKey, TValue>();
foreach(Node node in nodes)
{
dictionary.Add(node.key, node.value);
}
return dictionary;
}
}