|
1 | | -namespace Zigurous.Tweening |
| 1 | +using UnityEngine; |
| 2 | + |
| 3 | +namespace Zigurous.Tweening |
2 | 4 | { |
3 | 5 | /// <summary> |
4 | 6 | /// Properties for changing global tweening settings. |
5 | 7 | /// </summary> |
6 | | - public static class Settings |
| 8 | + [AddComponentMenu("Zigurous/Tweening/Tweening Settings")] |
| 9 | + public sealed class Settings : MonoBehaviour |
7 | 10 | { |
8 | 11 | /// <summary> |
9 | 12 | /// The default Ease assigned to every tween. |
@@ -33,18 +36,160 @@ public static class Settings |
33 | 36 |
|
34 | 37 | /// <summary> |
35 | 38 | /// Automatically starts tweens after being created, by default. |
| 39 | + /// This setting can be overridden by individual tweens. |
36 | 40 | /// </summary> |
37 | 41 | public static bool autoStart = true; |
38 | 42 |
|
39 | 43 | /// <summary> |
40 | 44 | /// Automatically kills tweens after being completed, by default. |
| 45 | + /// This setting can be overridden by individual tweens. |
41 | 46 | /// </summary> |
42 | 47 | public static bool autoKill = true; |
43 | 48 |
|
44 | 49 | /// <summary> |
45 | 50 | /// Keeps tweens in memory to be re-used after being killed, by default. |
| 51 | + /// This setting can be overridden by individual tweens. |
46 | 52 | /// </summary> |
47 | 53 | public static bool recyclable = true; |
| 54 | + |
| 55 | + [Tooltip("The default Ease assigned to every tween.")] |
| 56 | + [SerializeField] |
| 57 | + private Ease _defaultEase = Ease.QuadOut; |
| 58 | + |
| 59 | + [Tooltip("The default amount of seconds a tween takes to complete.")] |
| 60 | + [SerializeField] |
| 61 | + private float _defaultDuration = 0.3f; |
| 62 | + |
| 63 | + [Tooltip("The default amount of seconds before every tween starts.")] |
| 64 | + [SerializeField] |
| 65 | + private float _defaultDelay = 0f; |
| 66 | + |
| 67 | + [Tooltip("The overshoot value used in easing functions.")] |
| 68 | + [SerializeField] |
| 69 | + private float _overshoot = 1.70158f; |
| 70 | + |
| 71 | + [Tooltip("The initial amount of tweens memory is allocated for when the system starts. Additional memory will be allocated as needed.")] |
| 72 | + [SerializeField] |
| 73 | + private int _initialCapacity = 16; |
| 74 | + |
| 75 | + [Tooltip("Automatically starts tweens after being created, by default. This setting can be overridden by individual tweens.")] |
| 76 | + [SerializeField] |
| 77 | + private bool _autoStart = true; |
| 78 | + |
| 79 | + [Tooltip("Automatically kills tweens after being completed, by default. This setting can be overridden by individual tweens.")] |
| 80 | + [SerializeField] |
| 81 | + private bool _autoKill = true; |
| 82 | + |
| 83 | + [Tooltip("Keeps tweens in memory to be re-used after being killed, by default. This setting can be overridden by individual tweens.")] |
| 84 | + [SerializeField] |
| 85 | + private bool _recyclable = true; |
| 86 | + |
| 87 | + private void OnValidate() |
| 88 | + { |
| 89 | + UpdateSettings(); |
| 90 | + } |
| 91 | + |
| 92 | + private void Awake() |
| 93 | + { |
| 94 | + UpdateSettings(); |
| 95 | + } |
| 96 | + |
| 97 | + private void UpdateSettings() |
| 98 | + { |
| 99 | + Settings.defaultEase = _defaultEase; |
| 100 | + Settings.defaultDuration = _defaultDuration; |
| 101 | + Settings.defaultDelay = _defaultDelay; |
| 102 | + Settings.overshoot = _overshoot; |
| 103 | + Settings.initialCapacity = _initialCapacity; |
| 104 | + Settings.autoStart = _autoStart; |
| 105 | + Settings.autoKill = _autoKill; |
| 106 | + Settings.recyclable = _recyclable; |
| 107 | + } |
| 108 | + |
| 109 | + /// <summary> |
| 110 | + /// Sets the default Ease assigned to every tween. |
| 111 | + /// </summary> |
| 112 | + /// <param name="ease">The Ease to set as the default.</param> |
| 113 | + public void SetDefaultEase(Ease ease) |
| 114 | + { |
| 115 | + _defaultEase = ease; |
| 116 | + Settings.defaultEase = ease; |
| 117 | + } |
| 118 | + |
| 119 | + /// <summary> |
| 120 | + /// Sets the default amount of seconds a tween takes to complete. |
| 121 | + /// </summary> |
| 122 | + /// <param name="duration">The amount of seconds to set as the default.</param> |
| 123 | + public void SetDefaultDuration(float duration) |
| 124 | + { |
| 125 | + _defaultDuration = duration; |
| 126 | + Settings.defaultDuration = duration; |
| 127 | + } |
| 128 | + |
| 129 | + /// <summary> |
| 130 | + /// Sets the default amount of seconds before every tween starts. |
| 131 | + /// </summary> |
| 132 | + /// <param name="delay">The amount of seconds to set as the default.</param> |
| 133 | + public void SetDefaultDelay(float delay) |
| 134 | + { |
| 135 | + _defaultDelay = delay; |
| 136 | + Settings.defaultDelay = delay; |
| 137 | + } |
| 138 | + |
| 139 | + /// <summary> |
| 140 | + /// Sets the overshoot value used in easing functions. |
| 141 | + /// </summary> |
| 142 | + /// <param name="overshoot">The overshoot value to set.</param> |
| 143 | + public void SetOvershoot(float overshoot) |
| 144 | + { |
| 145 | + _overshoot = overshoot; |
| 146 | + Settings.overshoot = overshoot; |
| 147 | + } |
| 148 | + |
| 149 | + /// <summary> |
| 150 | + /// Sets the initial amount of tweens memory is allocated for when the |
| 151 | + /// system starts. Additional memory will be allocated as needed. |
| 152 | + /// </summary> |
| 153 | + /// <param name="initialCapacity">The initial capacity to set.</param> |
| 154 | + public void SetInitialCapacity(int initialCapacity) |
| 155 | + { |
| 156 | + _initialCapacity = initialCapacity; |
| 157 | + Settings.initialCapacity = initialCapacity; |
| 158 | + } |
| 159 | + |
| 160 | + /// <summary> |
| 161 | + /// Sets whether to automatically start tweens after being created, |
| 162 | + /// by default. This setting can be overridden by individual tweens. |
| 163 | + /// </summary> |
| 164 | + /// <param name="autoStart">Whether to automatically start tweens after being created.</param> |
| 165 | + public void SetAutoStart(bool autoStart) |
| 166 | + { |
| 167 | + _autoStart = autoStart; |
| 168 | + Settings.autoStart = autoStart; |
| 169 | + } |
| 170 | + |
| 171 | + /// <summary> |
| 172 | + /// Sets whether to automatically kills tweens after being completed, |
| 173 | + /// by default. This setting can be overridden by individual tweens. |
| 174 | + /// </summary> |
| 175 | + /// <param name="autoKill">Whether to automatically kill tweens after being completed.</param> |
| 176 | + public void SetAutoKill(bool autoKill) |
| 177 | + { |
| 178 | + _autoKill = autoKill; |
| 179 | + Settings.autoKill = autoKill; |
| 180 | + } |
| 181 | + |
| 182 | + /// <summary> |
| 183 | + /// Sets whether to keep tweens in memory to be re-used after being |
| 184 | + /// killed, by default. This setting can be overridden by individual tweens. |
| 185 | + /// </summary> |
| 186 | + /// <param name="recyclable">Whether to allow tweens to be recycled.</param> |
| 187 | + public void SetRecyclable(bool recyclable) |
| 188 | + { |
| 189 | + _recyclable = recyclable; |
| 190 | + Settings.recyclable = recyclable; |
| 191 | + } |
| 192 | + |
48 | 193 | } |
49 | 194 |
|
50 | 195 | } |
0 commit comments