Created
February 27, 2018 01:07
-
-
Save bellicapax/9fb5f9c1468aa6d92e95426c0e9fb735 to your computer and use it in GitHub Desktop.
An example implementation of a serializable Dictionary<string, int>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
namespace System.Collections.Generic | |
{ | |
[Serializable] | |
public class StringIntTuple : SerializableKeyValuePair<string, int> | |
{ | |
public StringIntTuple(string item1, int item2) : base(item1, item2) { } | |
} | |
[Serializable] | |
public class StringIntDictionary : SerializableDictionary<string, int> | |
{ | |
[SerializeField] private List<StringIntTuple> _pairs = new List<StringIntTuple>(); | |
protected override List<SerializableKeyValuePair<string, int>> _keyValuePairs | |
{ | |
get | |
{ | |
var list = new List<SerializableKeyValuePair<string, int>>(); | |
foreach (var pair in _pairs) | |
{ | |
list.Add(new SerializableKeyValuePair<string, int>(pair.Key, pair.Value)); | |
} | |
return list; | |
} | |
set | |
{ | |
_pairs.Clear(); | |
foreach (var kvp in value) | |
{ | |
_pairs.Add(new StringIntTuple(kvp.Key, kvp.Value)); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment