-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTweenLibMain.cs
More file actions
87 lines (75 loc) · 3.06 KB
/
TweenLibMain.cs
File metadata and controls
87 lines (75 loc) · 3.06 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
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
namespace TyesStuff.Animation.TweenLib
{
public class TweenLibMain : MonoBehaviour
{
public static TweenLibMain Instance;
public List<TweenLibCollection> TweenCollections = new List<TweenLibCollection>();
private Dictionary<string, TweenLibTweenStyle> m_NameToStyle = new Dictionary<string, TweenLibTweenStyle>();
private List<TweenLibTween> m_CurrentTweens = new List<TweenLibTween>();
private Dictionary<string, TweenLibTween> m_NameToCurrentTween = new Dictionary<string, TweenLibTween>();
private void Start()
{
if (Instance == null)
{
Instance = this;
} else
{
Debug.LogError("Another TweenLibMain component already exists in the scene!");
Destroy(gameObject);
}
// Getting Tween Collections
foreach (TweenLibCollection Collection in TweenCollections)
{
foreach (TweenLibTweenStyle Style in Collection.TweenStyles)
{
m_NameToStyle.Add(Style.Name, Style);
}
}
}
#region Static methods to manage Tweens
public static TweenLibTween CreateTween(string TweenName, string TweenStyleName, float Duration)
{
string TweenNameChecked = TweenName;
if (Instance.m_NameToCurrentTween.ContainsKey(TweenName))
{
TweenNameChecked += Random.Range(11, 99).ToString(); // TODO: you should probably change this to something better
}
TweenLibTween NewTween = new TweenLibTween(TweenNameChecked, Duration, Instance.m_NameToStyle[TweenStyleName]);
Instance.m_CurrentTweens.Add(NewTween);
Instance.m_NameToCurrentTween.Add(TweenNameChecked, Instance.m_CurrentTweens.LastOrDefault());
return Instance.m_CurrentTweens[Instance.m_CurrentTweens.Count - 1];
}
public static void DestroyTweenByName(string TweenName)
{
Instance.m_CurrentTweens.Remove(Instance.m_NameToCurrentTween[TweenName]);
Instance.m_NameToCurrentTween.Remove(TweenName);
}
public static void DestroyTween(TweenLibTween Tween)
{
Instance.m_NameToCurrentTween.Remove(Tween.TweenName);
Instance.m_CurrentTweens.Remove(Tween);
}
#endregion
private void Update()
{
foreach (TweenLibTween Tween in m_CurrentTweens)
{
if (Tween.IsPlaying)
{
Tween.DeltaStep();
}
// check if the tween is okay to be removed
if (Tween.CurrentTime > (Tween.Duration + Tween.Delay) && Tween.DestroyOnFinish)
{
if (Tween.OnTweenEnded != null)
Tween.OnTweenEnded();
DestroyTween(Tween);
return;
}
}
}
}
}