Skip to content

Commit 822ec3d

Browse files
committed
Add support for short values
1 parent 02df49e commit 822ec3d

File tree

3 files changed

+43
-3
lines changed

3 files changed

+43
-3
lines changed

Documentation~/articles/supported-types.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ When creating tweens using the generic functions, the following types of values
1010

1111
- `float`
1212
- `double`
13-
- `long`
1413
- `int`
14+
- `long`
15+
- `short`
1516
- `Vector2`
1617
- `Vector2Int`
1718
- `Vector3`

Runtime/Interpolation.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,19 @@ public static int Lerp(int a, int b, float t, bool snapping = false)
7676
/// <returns>The interpolated value between the start and end value.</returns>
7777
public static long Lerp(long a, long b, float t, bool snapping = false)
7878
{
79-
long value = (long)Mathf.Lerp(a, b, t);
80-
return snapping ? (int)value : value;
79+
80+
/// <summary>
81+
/// Linearly interpolates between <paramref name="a"/> and
82+
/// <paramref name="b"/> by <paramref name="t"/>.
83+
/// </summary>
84+
/// <param name="a">The start value.</param>
85+
/// <param name="b">The end value.</param>
86+
/// <param name="t">The interpolation value between the start and end value.</param>
87+
/// <param name="snapping">Snaps the interpolated value to the nearest whole number.</param>
88+
/// <returns>The interpolated value between the start and end value.</returns>
89+
public static short Lerp(short a, short b, float t, bool snapping = false)
90+
{
91+
return (short)Mathf.Lerp(a, b, t);
8192
}
8293

8394
/// <summary>

Runtime/Tweening.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,20 @@ public static Tween To<S>(S source, TweenGetter<S, int> getter, TweenSetter<S, i
105105
public static Tween To<S>(S source, TweenGetter<S, long> getter, TweenSetter<S, long> setter, long endValue, float duration) =>
106106
To(Interpolation._long, source, getter, setter, endValue, duration);
107107

108+
/// <summary>
109+
/// Creates a tween that animates a parameter to a given end value over
110+
/// a set duration.
111+
/// </summary>
112+
/// <typeparam name="S">The type of object to tween.</typeparam>
113+
/// <param name="source">The source object to tween.</param>
114+
/// <param name="getter">The function that gets the current value of the parameter.</param>
115+
/// <param name="setter">The function that sets a new value of the parameter.</param>
116+
/// <param name="endValue">The end value of the parameter.</param>
117+
/// <param name="duration">The duration of the tween.</param>
118+
/// <returns>A new tween that animates the parameter.</returns>
119+
public static Tween To<S>(S source, TweenGetter<S, short> getter, TweenSetter<S, short> setter, short endValue, float duration) =>
120+
To(Interpolation._short, source, getter, setter, endValue, duration);
121+
108122
/// <summary>
109123
/// Creates a tween that animates a parameter to a given end value over
110124
/// a set duration.
@@ -304,6 +318,20 @@ public static Tween From<S>(S source, TweenGetter<S, int> getter, TweenSetter<S,
304318
public static Tween From<S>(S source, TweenGetter<S, long> getter, TweenSetter<S, long> setter, long endValue, float duration) =>
305319
From(Interpolation.Lerp, source, getter, setter, endValue, duration);
306320

321+
/// <summary>
322+
/// Creates a tween that animates a parameter from a given end value to
323+
/// the current value over a set duration.
324+
/// </summary>
325+
/// <typeparam name="S">The type of object to tween.</typeparam>
326+
/// <param name="source">The source object to tween.</param>
327+
/// <param name="getter">The function that gets the current value of the parameter.</param>
328+
/// <param name="setter">The function that sets a new value of the parameter.</param>
329+
/// <param name="endValue">The end value of the parameter.</param>
330+
/// <param name="duration">The duration of the tween.</param>
331+
/// <returns>A new tween that animates the parameter.</returns>
332+
public static Tween From<S>(S source, TweenGetter<S, short> getter, TweenSetter<S, short> setter, short endValue, float duration) =>
333+
From(Interpolation.Lerp, source, getter, setter, endValue, duration);
334+
307335
/// <summary>
308336
/// Creates a tween that animates a parameter from a given end value to
309337
/// the current value over a set duration.

0 commit comments

Comments
 (0)