-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUpdateManager.cs
60 lines (46 loc) · 1.56 KB
/
UpdateManager.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
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System;
using Engine;
namespace UtilityAI
{
public class UpdateManager
{
private SortedDictionary<string, LinkedList<Action>> updates = new SortedDictionary<string, LinkedList<Action>>();
public void Add(string group, Action function){
LinkedList<Action> list;
updates.TryGetValue(group, out list);
if (list == null) {
list = new LinkedList<Action>();
updates[group] = list;
}
list.AddLast(function);
}
public void Remove(string group, Action function){
LinkedList<Action> list;
updates.TryGetValue(group, out list);
if (list != null) {
list.Remove(function);
}
}
public void Update(){
foreach(var updateList in updates){
var node = updateList.Value.First;
UnityEngine.Profiling.Profiler.BeginSample(updateList.Key);
while (node != null) {
node.Value.Invoke();
node = node.Next;
}
UnityEngine.Profiling.Profiler.EndSample();
}
}
public bool Contains(string group, Action function)
{
LinkedList<Action> list;
updates.TryGetValue(group, out list);
if (list == null) return false;
return list.Contains(function);
}
}
}