-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathContainer.cs
68 lines (61 loc) · 2.21 KB
/
Container.cs
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
using System.Collections.Generic;
public class Container {
public static Container instance {
set {
m_instance = value;
}
get {
if (m_instance == null) {
m_instance = new Container();
m_instance.reservoir = new Dictionary<string, Dictionary<string, object>>();
}
return m_instance;
}
}
protected static Container m_instance;
protected Dictionary<string, Dictionary<string, object>> reservoir;
public T GetData<T>(string type, string name, string source = "N/A") {
if (reservoir.ContainsKey(type)) {
if (reservoir[type].ContainsKey(name)) {
T obj = (T)reservoir[type][name];
//Debug.Log("Peeked for: " + obj);
return obj;
}
}
//Debug.Log("Object not found: " + name);
return default(T);
}
public T[] GetDataList<T>(string type, string name, string source = "N/A") {
if (reservoir.ContainsKey(type)) {
if (reservoir[type].ContainsKey(name)) {
T[] obj = (T[])reservoir[type][name];
//Debug.Log("Peeked for: " + obj);
return obj;
}
}
//Debug.Log("Object not found: " + name);
return default(T[]);
}
public void PutData<T>(string type, string name, T[] data) {
if (!reservoir.ContainsKey(type)) {
reservoir.Add(type, new Dictionary<string, object>());
}
if (!reservoir[type].ContainsKey(name)) {
reservoir[type].Add(name, data);
} else {
reservoir[type][name] = data;
}
//Debug.Log("Pushing to Pool: " + name);
}
public void PutData<T>(string type, string name, T data) {
if (!reservoir.ContainsKey(type)) {
reservoir.Add(type, new Dictionary<string, object>());
}
if (!reservoir[type].ContainsKey(name)) {
reservoir[type].Add(name, data);
} else {
reservoir[type][name] = data;
}
//Debug.Log("Pushing to Pool: " + name);
}
}