|
| 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 | +} |
0 commit comments