Skip to content

Commit 9ed34a8

Browse files
committed
added TextColorTween. also added new delay feature to tweeners
1 parent 9f71904 commit 9ed34a8

File tree

5 files changed

+40
-4
lines changed

5 files changed

+40
-4
lines changed

Tween/ColorTween.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public abstract class ColorTween : MonoBehaviour
1313

1414
public Keyframe<Color>[] keys;
1515
public float duration;
16+
public float delay;
1617
public bool wrap;
1718
public bool runOnEnable=true;
1819

@@ -41,7 +42,7 @@ public void StopTween() {
4142

4243
#region Override Functions
4344
protected virtual void Init() {
44-
m_Tween = new Tweener<Color>(keys, duration, wrap);
45+
m_Tween = new Tweener<Color>(keys, duration, delay, wrap);
4546
if (m_Tween.Loop != null) {
4647
m_Tween.OnSetValue += OnSetValue;
4748
m_Tween.OnMoveValue += OnMoveValue;

Tween/FloatTween.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public abstract class FloatTween : MonoBehaviour
1313

1414
public Keyframe<float>[] keys;
1515
public float duration;
16+
public float delay;
1617
public bool wrap;
1718

1819
protected Tweener<float> m_Tween;
@@ -29,7 +30,7 @@ private void OnDisable() {
2930

3031
#region Override Functions
3132
protected virtual void Init() {
32-
m_Tween = new Tweener<float>(keys, duration, wrap);
33+
m_Tween = new Tweener<float>(keys, duration, delay, wrap);
3334
if (m_Tween.Loop != null) {
3435
m_Tween.OnSetValue += OnSetValue;
3536
m_Tween.OnMoveValue += OnMoveValue;

Tween/TextColorTween.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+

2+
using UnityEngine;
3+
using UnityEngine.UI;
4+
5+
namespace Tween {
6+
7+
[RequireComponent(typeof(Text))]
8+
public class TextColorTween : ColorTween
9+
{
10+
private Text m_Text;
11+
12+
#region Override Functions
13+
protected override void Init() {
14+
m_Text = GetComponent<Text>();
15+
base.Init();
16+
}
17+
18+
protected override void OnSetValue(Color _val) {
19+
m_Text.color = _val;
20+
}
21+
22+
protected override void OnMoveValue(Color _curr, Color _target, float _nTime) {
23+
m_Text.color = Color.Lerp(_curr, _target, _nTime);
24+
}
25+
#endregion
26+
27+
}
28+
29+
}

Tween/Tweener.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ public class Tweener<T>
1414

1515
private Keyframe<T>[] m_Keys;
1616
private float m_Duration;
17+
private float m_Delay;
1718
private IEnumerator m_Loop;
1819
private int m_Index = -1;
1920
private bool m_Wrap;
@@ -25,9 +26,10 @@ public IEnumerator Loop {
2526
}
2627

2728
#region Constructors
28-
public Tweener(Keyframe<T>[] _keys, float _duration, bool _wrap) {
29+
public Tweener(Keyframe<T>[] _keys, float _duration, float _delay, bool _wrap) {
2930
m_Keys = _keys;
3031
m_Duration = _duration;
32+
m_Delay = _delay;
3133
m_Wrap = _wrap;
3234

3335
if (m_Keys.Length > 0) {
@@ -38,6 +40,8 @@ public Tweener(Keyframe<T>[] _keys, float _duration, bool _wrap) {
3840

3941
#region Private Functions
4042
private IEnumerator RunTween() {
43+
yield return new WaitForSeconds(m_Delay);
44+
4145
var _key = GetNextKey();
4246
var _nextKey = GetNextKey();
4347
float _timer = 0;

Tween/Vector3Tween.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ public abstract class Vector3Tween : MonoBehaviour
1313

1414
public Keyframe<Vector3>[] keys;
1515
public float duration;
16+
public float delay;
1617
public bool wrap;
1718

1819
protected Tweener<Vector3> m_Tween;
@@ -29,7 +30,7 @@ private void OnDisable() {
2930

3031
#region Override Functions
3132
protected virtual void Init() {
32-
m_Tween = new Tweener<Vector3>(keys, duration, wrap);
33+
m_Tween = new Tweener<Vector3>(keys, duration, delay, wrap);
3334
if (m_Tween.Loop != null) {
3435
m_Tween.OnSetValue += OnSetValue;
3536
m_Tween.OnMoveValue += OnMoveValue;

0 commit comments

Comments
 (0)