Skip to content

Commit 69a361f

Browse files
committed
Add component to change tweening settings
1 parent 58e6c0d commit 69a361f

File tree

4 files changed

+201
-18
lines changed

4 files changed

+201
-18
lines changed

Runtime/Tween.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -462,9 +462,9 @@ internal void Reset()
462462
this.flags = 0;
463463
this.reversed = false;
464464
this.snapping = false;
465-
this.autoStart = Tweening.defaultAutoStart;
466-
this.autoKill = Tweening.defaultAutoKill;
467-
this.recyclable = Tweening.defaultRecyclable;
465+
this.autoStart = Tweening.autoStart;
466+
this.autoKill = Tweening.autoKill;
467+
this.recyclable = Tweening.recyclable;
468468

469469
this.onUpdate = null;
470470
this.onStart = null;

Runtime/Tweening.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,6 @@ public static class Tweening
1313
/// </summary>
1414
public static Ease defaultEase = Ease.QuadOut;
1515

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-
3116
/// <summary>
3217
/// The default amount of seconds a tween takes to complete.
3318
/// </summary>
@@ -49,6 +34,21 @@ public static class Tweening
4934
/// </summary>
5035
public static int initialCapacity = 16;
5136

37+
/// <summary>
38+
/// Automatically starts tweens after being created, by default.
39+
/// </summary>
40+
public static bool autoStart = true;
41+
42+
/// <summary>
43+
/// Automatically kills tweens after being completed, by default.
44+
/// </summary>
45+
public static bool autoKill = true;
46+
47+
/// <summary>
48+
/// Keeps tweens in memory to be re-used after being killed, by default.
49+
/// </summary>
50+
public static bool recyclable = true;
51+
5252
/// <summary>
5353
/// The number of tweens currently alive (not necessarily active).
5454
/// </summary>

Runtime/TweeningSettings.cs

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
using UnityEngine;
2+
3+
namespace Zigurous.Tweening
4+
{
5+
/// <summary>
6+
/// A behavior that allows tweening settings to be changed in the editor.
7+
/// </summary>
8+
[AddComponentMenu("Zigurous/Tweening/Tweening Settings")]
9+
public sealed class TweeningSettings : MonoBehaviour
10+
{
11+
[Tooltip("The default Ease assigned to every tween.")]
12+
[SerializeField]
13+
private Ease _defaultEase = Ease.QuadOut;
14+
15+
/// <summary>
16+
/// The default Ease assigned to every tween.
17+
/// </summary>
18+
public Ease defaultEase
19+
{
20+
get => _defaultEase;
21+
set
22+
{
23+
_defaultEase = value;
24+
Tweening.defaultEase = value;
25+
}
26+
}
27+
28+
[Tooltip("The default amount of seconds a tween takes to complete.")]
29+
[SerializeField]
30+
private float _defaultDuration = 0.3f;
31+
32+
/// <summary>
33+
/// The default amount of seconds a tween takes to complete.
34+
/// </summary>
35+
public float defaultDuration
36+
{
37+
get => _defaultDuration;
38+
set
39+
{
40+
_defaultDuration = value;
41+
Tweening.defaultDuration = value;
42+
}
43+
}
44+
45+
[Tooltip("The default amount of seconds before every tween starts.")]
46+
[SerializeField]
47+
private float _defaultDelay = 0.0f;
48+
49+
/// <summary>
50+
/// The default amount of seconds before every tween starts.
51+
/// </summary>
52+
public float defaultDelay
53+
{
54+
get => _defaultDelay;
55+
set
56+
{
57+
_defaultDelay = value;
58+
Tweening.defaultDelay = value;
59+
}
60+
}
61+
62+
[Tooltip("The default overshoot value used in easing functions.")]
63+
[SerializeField]
64+
private float _overshoot = 1.70158f;
65+
66+
/// <summary>
67+
/// The overshoot value used in easing functions.
68+
/// </summary>
69+
public float overshoot
70+
{
71+
get => _overshoot;
72+
set
73+
{
74+
_overshoot = value;
75+
Tweening.overshoot = value;
76+
}
77+
}
78+
79+
[Tooltip("The initial amount of tweens that memory is allocated for when the system starts. Additional memory will be allocated as needed.")]
80+
[SerializeField]
81+
private int _initialCapacity = 16;
82+
83+
/// <summary>
84+
/// The initial amount of tweens that memory is allocated for when the
85+
/// system starts. Additional memory will be allocated as needed.
86+
/// </summary>
87+
public int initialCapacity
88+
{
89+
get => _initialCapacity;
90+
set
91+
{
92+
_initialCapacity = value;
93+
Tweening.initialCapacity = value;
94+
}
95+
}
96+
97+
[Tooltip("Automatically starts tweens after being created, by default.")]
98+
[SerializeField]
99+
private bool _autoStart = true;
100+
101+
/// <summary>
102+
/// Automatically starts tweens after being created, by default.
103+
/// </summary>
104+
public bool autoStart
105+
{
106+
get => _autoStart;
107+
set
108+
{
109+
_autoStart = value;
110+
Tweening.autoStart = value;
111+
}
112+
}
113+
114+
[Tooltip("Automatically kills tweens after being completed, by default.")]
115+
[SerializeField]
116+
private bool _autoKill = true;
117+
118+
/// <summary>
119+
/// Automatically kills tweens after being completed, by default.
120+
/// </summary>
121+
public bool autoKill
122+
{
123+
get => _autoKill;
124+
set
125+
{
126+
_autoKill = value;
127+
Tweening.autoKill = value;
128+
}
129+
}
130+
131+
[Tooltip("Keeps tweens in memory to be re-used after being killed, by default.")]
132+
[SerializeField]
133+
private bool _recyclable = true;
134+
135+
/// <summary>
136+
/// Keeps tweens in memory to be re-used after being killed, by default.
137+
/// </summary>
138+
public bool recyclable
139+
{
140+
get => _recyclable;
141+
set
142+
{
143+
_recyclable = value;
144+
Tweening.recyclable = value;
145+
}
146+
}
147+
148+
private void OnValidate()
149+
{
150+
UpdateSettings();
151+
}
152+
153+
private void Awake()
154+
{
155+
UpdateSettings();
156+
}
157+
158+
private void UpdateSettings()
159+
{
160+
Tweening.defaultEase = this.defaultEase;
161+
Tweening.defaultDuration = this.defaultDuration;
162+
Tweening.defaultDelay = this.defaultDelay;
163+
Tweening.overshoot = this.overshoot;
164+
Tweening.initialCapacity = this.initialCapacity;
165+
Tweening.autoStart = this.autoStart;
166+
Tweening.autoKill = this.autoKill;
167+
Tweening.recyclable = this.recyclable;
168+
}
169+
170+
}
171+
172+
}

Runtime/TweeningSettings.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)