Class TweenVector2
A performance-optimized, sealed tween implementation that interpolates UnityEngine.Vector2 values component-by-component. Suitable for animating 2D positions, UV offsets, anchor positions, pivot points, and any other two-component float property.
Implements
Inherited Members
Namespace: Scylla.Core.Util.Tween
Assembly: ScyllaCore.dll
Syntax
public sealed class TweenVector2 : TweenBase, ITween
Remarks
Interpolation: Uses Vector2(Vector2, Vector2, float) for standard playback and Vector2Incremental(Vector2, Vector2, float, int) when LoopType is Incremental. Both functions perform unclamped per-component linear math so that elastic and back easing produce the correct overshoot on both axes.
Change value: The internal _changeValue field is precomputed as
endValue - startValue and is used only during incremental loops to avoid
repeated subtraction in the hot path.
To vs. From: By default the start value is captured from the getter when
Play() is called. Call SetFrom(Vector2) before
Play to pin an explicit starting UnityEngine.Vector2.
Pool contract: Reset() zeroes all value fields and clears the getter and setter delegates so the instance can be safely returned to TweenPool.
Constructors
TweenVector2()
Creates a new, unconfigured TweenVector2 instance.
Declaration
public TweenVector2()
Remarks
Used by TweenPool when pre-allocating instances. Call Initialize(Func<Vector2>, Action<Vector2>, Vector2, float) before playing.
TweenVector2(Func<Vector2>, Action<Vector2>, Vector2, float)
Creates a fully configured TweenVector2 and immediately calls Initialize(Func<Vector2>, Action<Vector2>, Vector2, float).
Declaration
public TweenVector2(Func<Vector2> getter, Action<Vector2> setter, Vector2 endValue, float duration)
Parameters
| Type | Name | Description |
|---|---|---|
| Func<Vector2> | getter | A delegate that reads the current UnityEngine.Vector2 value of the target property.
Must not be |
| Action<Vector2> | setter | A delegate that writes the interpolated UnityEngine.Vector2 to the target property
each frame. Must not be |
| Vector2 | endValue | The target UnityEngine.Vector2 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 UnityEngine.Vector2 target value toward which the tween interpolates.
Declaration
public Vector2 EndValue { get; }
Property Value
| Type | Description |
|---|---|
| Vector2 | The end value supplied to Initialize(Func<Vector2>, Action<Vector2>, Vector2, float). |
StartValue
Gets the UnityEngine.Vector2 value from which the tween interpolates.
Declaration
public Vector2 StartValue { get; }
Property Value
| Type | Description |
|---|---|
| Vector2 | The start value pinned at play time, or the value passed to SetFrom(Vector2). Returns UnityEngine.Vector2.zero before the tween has started and no explicit start value has been set. |
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, the result stored as _startValue, and
_changeValue is computed as _endValue - _startValue. For subsequent
frames, either Vector2(Vector2, Vector2, float) (Restart/Yoyo) or
Vector2Incremental(Vector2, Vector2, float, int) (Incremental) is used and the result
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<Vector2>, Action<Vector2>, Vector2, float)
Configures this tween with all required parameters for UnityEngine.Vector2 interpolation.
Resets the _usesFrom flag so the start value is captured from the getter at
play time (standard "To" tween behavior). Call SetFrom(Vector2) afterward to
override with an explicit starting value.
Declaration
public TweenVector2 Initialize(Func<Vector2> getter, Action<Vector2> setter, Vector2 endValue, float duration)
Parameters
| Type | Name | Description |
|---|---|---|
| Func<Vector2> | getter | A delegate that reads the current UnityEngine.Vector2 of the target property each
frame. Must not be |
| Action<Vector2> | setter | A delegate that writes the interpolated UnityEngine.Vector2 to the target property
each frame. Must not be |
| Vector2 | endValue | The UnityEngine.Vector2 to animate toward. Captured by value; subsequent changes to the source variable are not reflected unless this method is called again or SetEndValue(Vector2) 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 |
|---|---|
| TweenVector2 | 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(Vector2)
Updates the UnityEngine.Vector2 end value that the tween animates toward.
Declaration
public TweenVector2 SetEndValue(Vector2 endValue)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector2 | endValue | The new target UnityEngine.Vector2 value. |
Returns
| Type | Description |
|---|---|
| TweenVector2 | 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.
SetFrom(Vector2)
Pins an explicit start value, converting this into a "From" tween that begins at
fromValue and animates toward the configured end value.
Declaration
public TweenVector2 SetFrom(Vector2 fromValue)
Parameters
| Type | Name | Description |
|---|---|---|
| Vector2 | fromValue | The UnityEngine.Vector2 from which interpolation begins. Overrides automatic start-value capture at play time. |
Returns
| Type | Description |
|---|---|
| TweenVector2 | This tween instance for method chaining. |