Class TweenFloat
A performance-optimized, sealed tween implementation that interpolates float values.
Avoids the generic-delegate overhead of Tween<T> and is the preferred choice
for animating scalar properties (alpha, volume, speed, fill amount, etc.).
Implements
Inherited Members
Namespace: Scylla.Core.Util.Tween
Assembly: ScyllaCore.dll
Syntax
public sealed class TweenFloat : TweenBase, ITween
Remarks
Interpolation: Uses Float(float, float, float) for standard playback and
FloatIncremental(float, float, float, int) when LoopType is
Incremental. The incremental formula is
start + change × (completedLoops + t), which accumulates the delta across
iterations without re-reading the getter on every frame.
Change value: The internal _changeValue field equals
endValue - startValue and is computed automatically at start-value capture
time (either in CaptureStartValue() or lazily in
ApplyValue(float)). This avoids repeated subtraction in the hot path.
To vs. From: By default the start value is captured from the getter at the
moment Play() is called. Call SetFrom(float) before
Play to override this with an explicit starting float.
Typical usage via the ScyllaTween factory:
<pre><code class="lang-csharp">var tween = ScyllaTween.To(() => transform.localScale.x, v => {
var s = transform.localScale;
s.x = v;
transform.localScale = s;
}, 2f, 0.5f) .SetEase(EaseType.OutBounce) .SetManaged(true) .Play();
Pool contract: Reset() clears getter, setter, and all value fields so the instance can be safely returned to TweenPool.
Constructors
TweenFloat()
Creates a new, unconfigured TweenFloat instance.
Declaration
public TweenFloat()
Remarks
Used by TweenPool when pre-allocating instances. Call Initialize(Func<float>, Action<float>, float, float) before playing.
TweenFloat(Func<float>, Action<float>, float, float)
Creates a fully configured TweenFloat and immediately calls Initialize(Func<float>, Action<float>, float, float).
Declaration
public TweenFloat(Func<float> getter, Action<float> setter, float endValue, float duration)
Parameters
| Type | Name | Description |
|---|---|---|
| Func<float> | getter | A delegate that reads the current float value of the target property.
Must not be |
| Action<float> | setter | A delegate that writes the interpolated float value to the target property each frame.
Must not be |
| float | endValue | The target float value to animate toward. |
| float | duration | Total playback time in seconds. Negative values are clamped to zero. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if |
Properties
EndValue
Gets the float target value toward which the tween interpolates.
Declaration
public float EndValue { get; }
Property Value
| Type | Description |
|---|---|
| float | The end value supplied to Initialize(Func<float>, Action<float>, float, float). |
StartValue
Gets the float value from which the tween interpolates.
Declaration
public float StartValue { get; }
Property Value
| Type | Description |
|---|---|
| float | The start value pinned at play time, or the value passed to SetFrom(float).
Returns |
Methods
ApplyValue(float)
Writes the interpolated value to the target property at the given eased progress. Must be implemented by derived classes to perform type-specific interpolation.
Declaration
protected override void ApplyValue(float easedProgress)
Parameters
| Type | Name | Description |
|---|---|---|
| float | easedProgress | The eased (and Yoyo-corrected) progress value computed by EasedProgress.
This value is intentionally unclamped; elastic and back easing can produce values below
|
Overrides
Remarks
On the first call when Progress is at or below zero and no start value has
been pinned, the getter is invoked and _changeValue is computed as
endValue - startValue. For subsequent frames, either
Float(float, float, float) (Restart/Yoyo) or
FloatIncremental(float, float, float, int) (Incremental) is called and the result
is written via the setter.
CaptureStartValue()
Called once during Play() (for new or restarted tweens) to snapshot the current value of the target property as the tween's start value, without applying any change.
Declaration
protected override void CaptureStartValue()
Overrides
Remarks
The base implementation is empty. Derived classes override this to read their getter
delegate and store the result in their start-value field, but only when a start value
has not already been pinned via a SetFrom call. This approach ensures that
the start value reflects the live property value at the moment play begins, not at
the moment the tween was created.
Initialize(Func<float>, Action<float>, float, float)
Configures this tween with all required parameters for float interpolation.
Resets the _usesFrom flag so the start value is captured from the getter at
play time (standard "To" tween behavior). Call SetFrom(float) afterward to
override this with an explicit starting value.
Declaration
public TweenFloat Initialize(Func<float> getter, Action<float> setter, float endValue, float duration)
Parameters
| Type | Name | Description |
|---|---|---|
| Func<float> | getter | A delegate that reads the current float value of the target property each frame.
Must not be |
| Action<float> | setter | A delegate that writes the interpolated float back to the target property each frame.
Must not be |
| float | endValue | The float value to animate toward. Captured by value; subsequent changes to the source variable are not reflected unless this method is called again or SetEndValue(float) is used. |
| float | duration | Playback duration in seconds. Clamped to zero; a value of zero produces an instant-complete tween on the first update frame. |
Returns
| Type | Description |
|---|---|
| TweenFloat | This tween instance for method chaining. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown if |
PrepareIncrementalLoop()
Called at the end of each Incremental loop iteration to allow derived classes to update internal state before the next iteration begins.
Declaration
protected override void PrepareIncrementalLoop()
Overrides
Remarks
The base implementation is empty. Derived classes that support incremental looping (e.g., TweenFloat, TweenVector3) override this to capture the current property value as the new start point, so each loop iteration adds the change amount on top of the previous iteration's result.
Reset()
Resets all tween state back to initial defaults, preparing the instance for reuse from a pool.
Declaration
public override void Reset()
Overrides
Remarks
Clears all callbacks, resets timing values, generates a new TweenID,
and sets State back to Created. This is
called automatically by the tween pool (TweenPool) before returning an
instance to a caller. Derived classes that override this method must call the base
implementation.
SetEndValue(float)
Updates the end value that the tween animates toward.
Declaration
public TweenFloat SetEndValue(float endValue)
Parameters
| Type | Name | Description |
|---|---|---|
| float | endValue | The new target float value. |
Returns
| Type | Description |
|---|---|
| TweenFloat | This tween instance for method chaining. |
Remarks
Safe to call while the tween is playing. The change takes effect on the next
Update(float) call. Note that _changeValue is recomputed
only when the start value is captured; if the tween is already playing you may also
need to recapture the start value (e.g., by calling Restart())
to keep the incremental delta consistent.
SetFrom(float)
Pins an explicit start value, converting this into a "From" tween that begins
at fromValue and animates toward the configured end value.
Declaration
public TweenFloat SetFrom(float fromValue)
Parameters
| Type | Name | Description |
|---|---|---|
| float | fromValue | The float value from which interpolation begins. Overrides automatic start-value capture at play time. |
Returns
| Type | Description |
|---|---|
| TweenFloat | This tween instance for method chaining. |