Skip to content

Commit 24ecf89

Browse files
committed
Added speed property to tween layer.
1 parent 6199d45 commit 24ecf89

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

Runtime/Tween.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ private Tween()
279279
/// Whether the tween animation is able to update. Affected by pausing and time scale.
280280
/// </summary>
281281
[PublicAPI]
282-
public bool IsAbleToUpdate => !IsPaused && !Layer.IsPaused && (IsUnscaled || Time.timeScale > 0f);
282+
public bool IsAbleToUpdate => !IsPaused && !Layer.IsPaused && Layer.Speed > 0f && (IsUnscaled || Time.timeScale > 0f);
283283

284284
/// <summary>
285285
/// Whether the tween animation should use Time.unscaledDeltaTime.
@@ -470,7 +470,7 @@ private IEnumerator Update()
470470
yield return null;
471471

472472
// Increment elapsed time
473-
ElapsedTime += IsUnscaled ? Mathf.Clamp(Time.unscaledDeltaTime, 0f, 0.2f) : Time.deltaTime;
473+
ElapsedTime += (IsUnscaled ? Mathf.Clamp(Time.unscaledDeltaTime, 0f, 0.2f) : Time.deltaTime) * Layer.Speed;
474474
}
475475

476476
// Snap to the end value

Runtime/TweenLayer.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ public sealed class TweenLayer : IReadOnlyList<Tween>
2323
[NotNull]
2424
private readonly HashSet<Tween> _tweens = new HashSet<Tween>();
2525

26+
private float _speed = 1f;
27+
2628
#endregion
2729

2830
#region Properties
@@ -32,6 +34,16 @@ public sealed class TweenLayer : IReadOnlyList<Tween>
3234
/// </summary>
3335
[PublicAPI]
3436
public bool IsPaused { get; set; }
37+
38+
/// <summary>
39+
/// Playback speed (time factor) of all tween animations on this layer.
40+
/// </summary>
41+
[PublicAPI]
42+
public float Speed
43+
{
44+
get => _speed;
45+
set => _speed = Mathf.Max(0f, value);
46+
}
3547

3648
[PublicAPI]
3749
public int Count => _tweens.Count;

0 commit comments

Comments
 (0)