Skip to content

Commit 3b7efa5

Browse files
committed
Move settings to main Tweening class
1 parent ef367ae commit 3b7efa5

File tree

6 files changed

+61
-87
lines changed

6 files changed

+61
-87
lines changed

Runtime/EaseFunction.cs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,6 @@ public static class EaseFunction
6363
{ Ease.BounceInOut, BounceInOut },
6464
};
6565

66-
private static float c1 = Settings.overshoot;
67-
private static float c2 = c1 * 1.525f;
68-
private static float c3 = c1 + 1.0f;
69-
private static float c4 = (2.0f * Mathf.PI) / 3.0f;
70-
private static float c5 = (2.0f * Mathf.PI) / 4.5f;
71-
7266
public static float Linear(float x)
7367
{
7468
return x;
@@ -193,16 +187,17 @@ public static float CircInOut(float x)
193187

194188
public static float BackIn(float x)
195189
{
196-
return c3 * x * x * x - c1 * x * x;
190+
return (Tweening.overshoot + 1.0f) * x * x * x - Tweening.overshoot * x * x;
197191
}
198192

199193
public static float BackOut(float x)
200194
{
201-
return 1.0f + c3 * Mathf.Pow(x - 1.0f, 3.0f) + c1 * Mathf.Pow(x - 1.0f, 2.0f);
195+
return 1.0f + (Tweening.overshoot + 1.0f) * Mathf.Pow(x - 1.0f, 3.0f) + Tweening.overshoot * Mathf.Pow(x - 1.0f, 2.0f);
202196
}
203197

204198
public static float BackInOut(float x)
205199
{
200+
float c2 = Tweening.overshoot * 1.525f;
206201
return x < 0.5f ?
207202
(Mathf.Pow(2.0f * x, 2.0f) * ((c2 + 1.0f) * 2.0f * x - c2)) / 2.0f :
208203
(Mathf.Pow(2.0f * x - 2.0f, 2.0f) * ((c2 + 1.0f) * (x * 2.0f - 2.0f) + c2) + 2.0f) / 2.0f;
@@ -211,20 +206,20 @@ public static float BackInOut(float x)
211206
public static float ElasticIn(float x)
212207
{
213208
return x <= 0.0f ? 0.0f : x >= 1.0f ? 1.0f :
214-
-Mathf.Pow(2.0f, 10.0f * x - 10.0f) * Mathf.Sin((x * 10.0f - 10.75f) * c4);
209+
-Mathf.Pow(2.0f, 10.0f * x - 10.0f) * Mathf.Sin((x * 10.0f - 10.75f) * ((2.0f * Mathf.PI) / 3.0f));
215210
}
216211

217212
public static float ElasticOut(float x)
218213
{
219214
return x <= 0.0f ? 0.0f : x >= 1.0f ? 1.0f :
220-
Mathf.Pow(2.0f, -10.0f * x) * Mathf.Sin((x * 10.0f - 0.75f) * c4) + 1.0f;
215+
Mathf.Pow(2.0f, -10.0f * x) * Mathf.Sin((x * 10.0f - 0.75f) * ((2.0f * Mathf.PI) / 3.0f)) + 1.0f;
221216
}
222217

223218
public static float ElasticInOut(float x)
224219
{
225220
return x <= 0.0f ? 0.0f : x >= 1.0f ? 1.0f : x < 0.5f ?
226-
-(Mathf.Pow(2.0f, 20.0f * x - 10.0f) * Mathf.Sin((20.0f * x - 11.125f) * c5)) / 2.0f :
227-
Mathf.Pow(2.0f, -20.0f * x + 10.0f) * Mathf.Sin((20.0f * x - 11.125f) * c5) / 2.0f + 1.0f;
221+
-(Mathf.Pow(2.0f, 20.0f * x - 10.0f) * Mathf.Sin((20.0f * x - 11.125f) * ((2.0f * Mathf.PI) / 4.5f))) / 2.0f :
222+
Mathf.Pow(2.0f, -20.0f * x + 10.0f) * Mathf.Sin((20.0f * x - 11.125f) * ((2.0f * Mathf.PI) / 4.5f)) / 2.0f + 1.0f;
228223
}
229224

230225
public static float BounceIn(float x)

Runtime/Settings.cs

Lines changed: 0 additions & 51 deletions
This file was deleted.

Runtime/Settings.cs.meta

Lines changed: 0 additions & 11 deletions
This file was deleted.

Runtime/Tween.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,12 @@ public abstract class Tween
5959
/// <summary>
6060
/// The easing function type used by the tween to animate values.
6161
/// </summary>
62-
public Ease ease = Settings.defaultEase;
62+
public Ease ease = Tweening.defaultEase;
6363

6464
/// <summary>
6565
/// The amount of seconds the tween takes to complete.
6666
/// </summary>
67-
public float duration = Settings.defaultDuration;
67+
public float duration = Tweening.defaultDuration;
6868

6969
/// <summary>
7070
/// The amount of seconds that have elapsed since the tween started.
@@ -80,7 +80,7 @@ public abstract class Tween
8080
/// The amount of seconds the tween waits before playing after being
8181
/// started.
8282
/// </summary>
83-
public float delay = Settings.defaultDelay;
83+
public float delay = Tweening.defaultDelay;
8484

8585
/// <summary>
8686
/// The amount of seconds that have elapsed during the tween's delayed
@@ -104,17 +104,17 @@ public abstract class Tween
104104
/// <summary>
105105
/// Keeps the tween in memory to be re-used after being killed.
106106
/// </summary>
107-
public bool recyclable = Settings.defaultRecyclable;
107+
public bool recyclable = Tweening.defaultRecyclable;
108108

109109
/// <summary>
110110
/// Automatically starts the tween after being created.
111111
/// </summary>
112-
public bool autoStart = Settings.defaultAutoStart;
112+
public bool autoStart = Tweening.defaultAutoStart;
113113

114114
/// <summary>
115115
/// Automatically kills the tween after being completed.
116116
/// </summary>
117-
public bool autoKill = Settings.defaultAutoKill;
117+
public bool autoKill = Tweening.defaultAutoKill;
118118

119119
/// <summary>
120120
/// The callback invoked every time the tween is updated, i.e., any time
@@ -308,15 +308,15 @@ internal void Reset()
308308
this.id = -1;
309309
this.state = TweenState.Ready;
310310
this.internalState = InternalTweenState.Queued;
311-
this.ease = Settings.defaultEase;
312-
this.duration = Settings.defaultDuration;
311+
this.ease = Tweening.defaultEase;
312+
this.duration = Tweening.defaultDuration;
313313
this.elapsed = 0.0f;
314-
this.delay = Settings.defaultDelay;
314+
this.delay = Tweening.defaultDelay;
315315
this.delayElapsed = 0.0f;
316316
this.reversed = false;
317-
this.autoStart = Settings.defaultAutoStart;
318-
this.autoKill = Settings.defaultAutoKill;
319-
this.recyclable = Settings.defaultRecyclable;
317+
this.autoStart = Tweening.defaultAutoStart;
318+
this.autoKill = Tweening.defaultAutoKill;
319+
this.recyclable = Tweening.defaultRecyclable;
320320

321321
this.onUpdate = null;
322322
this.onStart = null;

Runtime/TweenManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ internal sealed class TweenManager : MonoBehaviour
1212
/// <summary>
1313
/// A list of all alive tween objects.
1414
/// </summary>
15-
internal List<Tween> tweens = new List<Tween>(Settings.initialCapacity);
15+
internal List<Tween> tweens = new List<Tween>(Tweening.initialCapacity);
1616

1717
private static bool _isUnloading = false;
1818
private static object _lock = new object();

Runtime/Tweening.cs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,47 @@ namespace Zigurous.Tweening
88
/// </summary>
99
public static class Tweening
1010
{
11+
/// <summary>
12+
/// The default Ease assigned to every tween.
13+
/// </summary>
14+
public static Ease defaultEase = Ease.QuadOut;
15+
16+
/// <summary>
17+
/// Automatically starts tweens after being created, by default.
18+
/// </summary>
19+
public static bool defaultAutoStart = true;
20+
21+
/// <summary>
22+
/// Automatically kills tweens after being completed, by default.
23+
/// </summary>
24+
public static bool defaultAutoKill = true;
25+
26+
/// <summary>
27+
/// Keeps tweens in memory to be re-used after being killed, by default.
28+
/// </summary>
29+
public static bool defaultRecyclable = true;
30+
31+
/// <summary>
32+
/// The default amount of seconds a tween takes to complete.
33+
/// </summary>
34+
public static float defaultDuration = 0.3f;
35+
36+
/// <summary>
37+
/// The default amount of seconds before every tween starts.
38+
/// </summary>
39+
public static float defaultDelay = 0.0f;
40+
41+
/// <summary>
42+
/// The default overshoot value used in easing functions.
43+
/// </summary>
44+
public static float overshoot = 1.70158f;
45+
46+
/// <summary>
47+
/// The initial amount of tweens that memory is allocated for when the
48+
/// system starts. Additional memory will be allocated as needed.
49+
/// </summary>
50+
public static int initialCapacity = 16;
51+
1152
/// <summary>
1253
/// The number of tweens currently alive (not necessarily active).
1354
/// </summary>

0 commit comments

Comments
 (0)