Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1765745

Browse files
fixing serialization issue with generic types
1 parent 9ed34a8 commit 1765745

File tree

5 files changed

+96
-8
lines changed

5 files changed

+96
-8
lines changed

‎Tween/ColorTween.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ namespace Tween {
1111
public abstract class ColorTween : MonoBehaviour
1212
{
1313

14-
public Keyframe<Color>[] keys;
14+
//public Keyframe<Color>[] keys;
15+
public ColorKeyframe[] keys;
1516
public float duration;
1617
public float delay;
1718
public bool wrap;
@@ -30,6 +31,16 @@ private void OnDisable() {
3031
}
3132
#endregion
3233

34+
#region Private Functions
35+
private Keyframe<Color>[] GenericKeys(ColorKeyframe[] _keys) {
36+
var _ret = new List<Keyframe<Color>>();
37+
foreach (ColorKeyframe _frame in _keys) {
38+
_ret.Add(new Keyframe<Color>(_frame.value, _frame.nTime));
39+
}
40+
return _ret.ToArray();
41+
}
42+
#endregion
43+
3344
#region Public Functions
3445
public void StartTween() {
3546
Init();
@@ -42,7 +53,7 @@ public void StopTween() {
4253

4354
#region Override Functions
4455
protected virtual void Init() {
45-
m_Tween = new Tweener<Color>(keys, duration, delay, wrap);
56+
m_Tween = new Tweener<Color>(GenericKeys(keys), duration, delay, wrap);
4657
if (m_Tween.Loop != null) {
4758
m_Tween.OnSetValue += OnSetValue;
4859
m_Tween.OnMoveValue += OnMoveValue;

‎Tween/FloatTween.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ namespace Tween {
1111
public abstract class FloatTween : MonoBehaviour
1212
{
1313

14-
public Keyframe<float>[] keys;
14+
//public Keyframe<float>[] keys;
15+
public FloatKeyframe[] keys;
1516
public float duration;
1617
public float delay;
1718
public bool wrap;
@@ -28,9 +29,19 @@ private void OnDisable() {
2829
}
2930
#endregion
3031

32+
#region Private Functions
33+
private Keyframe<float>[] GenericKeys(FloatKeyframe[] _keys) {
34+
var _ret = new List<Keyframe<float>>();
35+
foreach (FloatKeyframe _frame in _keys) {
36+
_ret.Add(new Keyframe<float>(_frame.value, _frame.nTime));
37+
}
38+
return _ret.ToArray();
39+
}
40+
#endregion
41+
3142
#region Override Functions
3243
protected virtual void Init() {
33-
m_Tween = new Tweener<float>(keys, duration, delay, wrap);
44+
m_Tween = new Tweener<float>(GenericKeys(keys), duration, delay, wrap);
3445
if (m_Tween.Loop != null) {
3546
m_Tween.OnSetValue += OnSetValue;
3647
m_Tween.OnMoveValue += OnMoveValue;

‎Tween/Keyframe.cs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,39 @@
33

44
namespace Tween {
55

6-
[System.Serializable]
76
public class Keyframe<T>
87
{
98
public T value;
109
[Range(0,1)]
1110
public float nTime;
11+
12+
public Keyframe(T _val, float _n) {
13+
this.value = _val;
14+
this.nTime = _n;
15+
}
16+
}
17+
18+
[System.Serializable]
19+
public class Vec3Keyframe
20+
{
21+
public Vector3 value;
22+
[Range(0,1)]
23+
public float nTime;
24+
}
25+
26+
[System.Serializable]
27+
public class FloatKeyframe
28+
{
29+
public float value;
30+
[Range(0,1)]
31+
public float nTime;
32+
}
33+
34+
[System.Serializable]
35+
public class ColorKeyframe
36+
{
37+
public Color value;
38+
[Range(0,1)]
39+
public float nTime;
1240
}
1341
}

‎Tween/SpriteColorTween.cs

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

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

‎Tween/Vector3Tween.cs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ namespace Tween {
1010
/// </summary>
1111
public abstract class Vector3Tween : MonoBehaviour
1212
{
13-
14-
public Keyframe<Vector3>[] keys;
13+
//public Keyframe<Vector3>[] keys;
14+
public Vec3Keyframe[] keys;
1515
public float duration;
1616
public float delay;
1717
public bool wrap;
@@ -28,9 +28,19 @@ private void OnDisable() {
2828
}
2929
#endregion
3030

31+
#region Private Functions
32+
private Keyframe<Vector3>[] GenericKeys(Vec3Keyframe[] _keys) {
33+
var _ret = new List<Keyframe<Vector3>>();
34+
foreach (Vec3Keyframe _frame in _keys) {
35+
_ret.Add(new Keyframe<Vector3>(_frame.value, _frame.nTime));
36+
}
37+
return _ret.ToArray();
38+
}
39+
#endregion
40+
3141
#region Override Functions
3242
protected virtual void Init() {
33-
m_Tween = new Tweener<Vector3>(keys, duration, delay, wrap);
43+
m_Tween = new Tweener<Vector3>(GenericKeys(keys), duration, delay, wrap);
3444
if (m_Tween.Loop != null) {
3545
m_Tween.OnSetValue += OnSetValue;
3646
m_Tween.OnMoveValue += OnMoveValue;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /