-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRObjectManager.cs
More file actions
94 lines (82 loc) · 2.3 KB
/
RObjectManager.cs
File metadata and controls
94 lines (82 loc) · 2.3 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
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
using System.Collections.Generic;
using UnityEngine;
namespace ZeroPass
{
public class RObjectManager : MonoBehaviour
{
private Dictionary<int, RObject> objects = new Dictionary<int, RObject>();
private List<int> pendingDestroys = new List<int>();
public static RObjectManager Instance
{
get;
private set;
}
public static void DestroyInstance()
{
Instance = null;
}
private void Awake()
{
Debug.Assert((Object)Instance == (Object)null);
Instance = this;
}
private void OnDestroy()
{
Debug.Assert((Object)Instance != (Object)null);
Debug.Assert((Object)Instance == (Object)this);
Cleanup();
Instance = null;
}
public void Cleanup()
{
foreach (KeyValuePair<int, RObject> @object in objects)
{
@object.Value.OnCleanUp();
}
objects.Clear();
pendingDestroys.Clear();
}
public RObject GetOrCreateObject(GameObject go)
{
int instanceID = go.GetInstanceID();
RObject value = null;
if (!objects.TryGetValue(instanceID, out value))
{
value = new RObject(go);
objects[instanceID] = value;
}
return value;
}
public RObject Get(GameObject go)
{
RObject value = null;
objects.TryGetValue(go.GetInstanceID(), out value);
return value;
}
public void QueueDestroy(RObject obj)
{
int id = obj.id;
if (!pendingDestroys.Contains(id))
{
pendingDestroys.Add(id);
}
}
private void LateUpdate()
{
for (int i = 0; i < pendingDestroys.Count; i++)
{
int key = pendingDestroys[i];
RObject value = null;
if (objects.TryGetValue(key, out value))
{
objects.Remove(key);
value.OnCleanUp();
}
}
pendingDestroys.Clear();
}
public void DumpEventData()
{
}
}
}