-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTweenManager.cs
More file actions
114 lines (103 loc) · 3.21 KB
/
TweenManager.cs
File metadata and controls
114 lines (103 loc) · 3.21 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
using System.Collections.Generic;
namespace Tween
{
public static class TweenManager
{
private static List<TweenBase> activeTweens = new List<TweenBase>();
private static Dictionary<string, TweenBase> tweensById = new Dictionary<string, TweenBase>();
public static void Add(TweenBase tween)
{
if (!tween.IsDisposed)
{
if (!string.IsNullOrEmpty(tween.Id) && tweensById.ContainsKey(tween.Id))
{
tweensById[tween.Id].Dispose();
tweensById.Remove(tween.Id);
activeTweens.Remove(tween);
}
activeTweens.Add(tween);
if (!string.IsNullOrEmpty(tween.Id))
{
tweensById[tween.Id] = tween;
}
}
}
public static void Update(float scaledDt, float unscaledDt)
{
for (int i = activeTweens.Count - 1; i >= 0; i--)
{
if (activeTweens[i].IsDisposed)
{
if (!string.IsNullOrEmpty(activeTweens[i].Id))
{
tweensById.Remove(activeTweens[i].Id);
}
activeTweens.RemoveAt(i);
continue;
}
activeTweens[i].Update(scaledDt, unscaledDt);
if (activeTweens[i].IsCompleted)
{
if (!string.IsNullOrEmpty(activeTweens[i].Id))
{
tweensById.Remove(activeTweens[i].Id);
}
activeTweens[i].Dispose();
activeTweens.RemoveAt(i);
}
}
}
public static void Remove(TweenBase tween)
{
if (tween != null && !tween.IsDisposed)
{
if (!string.IsNullOrEmpty(tween.Id))
{
tweensById.Remove(tween.Id);
}
tween.Dispose();
activeTweens.Remove(tween);
}
}
public static void Clear()
{
foreach (var tween in activeTweens)
{
if (!string.IsNullOrEmpty(tween.Id))
{
tweensById.Remove(tween.Id);
}
tween.Dispose();
}
activeTweens.Clear();
tweensById.Clear();
}
public static void ClearByPrefix(string prefix)
{
foreach (var tween in activeTweens)
{
if (!string.IsNullOrEmpty(tween.Id) && tween.Id.StartsWith(prefix))
{
tweensById.Remove(tween.Id);
}
tween.Dispose();
}
activeTweens.Clear();
tweensById.Clear();
}
public static void PauseAll()
{
foreach (var tween in activeTweens)
{
tween.Pause();
}
}
public static void ResumeAll()
{
foreach (var tween in activeTweens)
{
tween.Resume();
}
}
}
}