Skip to content

Commit 3ede86e

Browse files
committed
Add support for Rect tweens
1 parent ab42947 commit 3ede86e

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

Runtime/Interpolation.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,16 @@ public static Quaternion Lerp(Quaternion a, Quaternion b, float t, bool snapping
9999
return snapping ? Snap(value) : value;
100100
}
101101

102+
/// <summary>
103+
/// Linearly interpolates between a and b by t.
104+
/// </summary>
105+
public static Rect Lerp(Rect a, Rect b, float t, bool snapping = false)
106+
{
107+
Vector2 position = Lerp(a.position, b.position, t, snapping);
108+
Vector2 size = Lerp(a.size, b.size, t, snapping);
109+
return new Rect(position, size);
110+
}
111+
102112
/// <summary>
103113
/// Linearly interpolates between a and b by t.
104114
/// </summary>

Runtime/Tweening.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,13 @@ public static Tween To(TweenGetter<Vector4> getter, TweenSetter<Vector4> setter,
159159
public static Tween To(TweenGetter<Quaternion> getter, TweenSetter<Quaternion> setter, Quaternion endValue, float duration) =>
160160
To(Interpolation.Lerp, getter, setter, endValue, duration);
161161

162+
/// <summary>
163+
/// Creates a tween that animates a parameter to a given end value over
164+
/// a set duration.
165+
/// </summary>
166+
public static Tween To(TweenGetter<Rect> getter, TweenSetter<Rect> setter, Rect endValue, float duration) =>
167+
To(Interpolation.Lerp, getter, setter, endValue, duration);
168+
162169
/// <summary>
163170
/// Creates a tween that animates a parameter to a given end value over
164171
/// a set duration.
@@ -252,6 +259,13 @@ public static Tween From(TweenGetter<Vector4> getter, TweenSetter<Vector4> sette
252259
public static Tween From(TweenGetter<Quaternion> getter, TweenSetter<Quaternion> setter, Quaternion endValue, float duration) =>
253260
From(Interpolation.Lerp, getter, setter, endValue, duration);
254261

262+
/// <summary>
263+
/// Creates a tween that animates a parameter from a given end value to
264+
/// the current value over a set duration.
265+
/// </summary>
266+
public static Tween From(TweenGetter<Rect> getter, TweenSetter<Rect> setter, Rect endValue, float duration) =>
267+
From(Interpolation.Lerp, getter, setter, endValue, duration);
268+
255269
/// <summary>
256270
/// Creates a tween that animates a parameter from a given end value to
257271
/// the current value over a set duration.

0 commit comments

Comments
 (0)