-
Notifications
You must be signed in to change notification settings - Fork 81
Expand file tree
/
Copy pathScriptableObjectDictionary.cs
More file actions
40 lines (35 loc) · 1.04 KB
/
ScriptableObjectDictionary.cs
File metadata and controls
40 lines (35 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using System;
using System.Collections.Generic;
using UnityEngine;
namespace ScriptableObjectManager
{
[Serializable]
public class ScriptableObjectDictionary<TKey, TValue> : ScriptableObject
{
[SerializeField]
[HideInInspector]
private List<TKey> keys = new List<TKey>();
[SerializeField]
public List<TValue> values = new List<TValue>();
protected Dictionary<TKey, TValue> target;
public Dictionary<TKey, TValue> Target
{
get
{
int size = keys.Count;
if (null == target || 0 == target.Count)
{
target = new Dictionary<TKey, TValue>();
for (int i = 0; i < size; i++) target.Add(keys[i], values[i]);
}
return target;
}
set
{
target = value;
keys = new List<TKey>(target.Keys);
values = new List<TValue>(target.Values);
}
}
}
}