Class TweenExtensions
Fluent extension methods on ITween that provide convenient shortcuts for common configuration, playback, callback, loop, type-cast, and utility patterns.
Inherited Members
Namespace: Scylla.Core.Util.Tween
Assembly: ScyllaCore.dll
Syntax
public static class TweenExtensions
Remarks
All methods return ITween (or the concrete typed tween where stated) to support method chaining. Every method that modifies state or starts playback returns the same tween instance that was passed in - no new tween is created.
These extensions complement the core ITween interface and the
ScyllaTween factory without adding any concrete tween logic. For
Unity component shortcuts (Transform, Material, CanvasGroup, etc.) see the dedicated
Tween*Extensions classes in the Extensions subdirectory.
Methods
AsColor(ITween)
Attempts to cast the ITween to TweenColor for access to Color-specific members such as start and end values.
Declaration
public static TweenColor AsColor(this ITween tween)
Parameters
| Type | Name | Description |
|---|---|---|
| ITween | tween | The tween to cast. Must not be |
Returns
| Type | Description |
|---|---|
| TweenColor | The underlying TweenColor instance, or |
See Also
AsFloat(ITween)
Attempts to cast the ITween to TweenFloat for access to float-specific members such as StartValue and EndValue.
Declaration
public static TweenFloat AsFloat(this ITween tween)
Parameters
| Type | Name | Description |
|---|---|---|
| ITween | tween | The tween to cast. Must not be |
Returns
| Type | Description |
|---|---|
| TweenFloat | The underlying TweenFloat instance, or |
See Also
AsSequence(ITween)
Attempts to cast the ITween to TweenSequence for access to sequence-specific building methods such as Append(ITween), Join(ITween), and Insert(float, ITween).
Declaration
public static TweenSequence AsSequence(this ITween tween)
Parameters
| Type | Name | Description |
|---|---|---|
| ITween | tween | The tween to cast. Must not be |
Returns
| Type | Description |
|---|---|
| TweenSequence | The underlying TweenSequence instance, or |
See Also
AsVector3(ITween)
Attempts to cast the ITween to TweenVector3 for access to Vector3-specific members such as start and end values.
Declaration
public static TweenVector3 AsVector3(this ITween tween)
Parameters
| Type | Name | Description |
|---|---|---|
| ITween | tween | The tween to cast. Must not be |
Returns
| Type | Description |
|---|---|
| TweenVector3 | The underlying TweenVector3 instance, or |
See Also
GetRemainingTime(ITween)
Calculates the remaining playback time for the current loop iteration, not accounting for future loop repetitions or the initial delay.
Declaration
public static float GetRemainingTime(this ITween tween)
Parameters
| Type | Name | Description |
|---|---|---|
| ITween | tween | The tween to query. Must not be |
Returns
| Type | Description |
|---|---|
| float | The number of seconds remaining in the current iteration, computed as
|
Remarks
This value reflects the current iteration only. For the total remaining time across all remaining loops (including the delay), use GetTotalDuration(ITween) and subtract elapsed time manually.
See Also
GetTotalDuration(ITween)
Calculates the total playback time of the tween across all configured loop iterations plus the initial delay.
Declaration
public static float GetTotalDuration(this ITween tween)
Parameters
| Type | Name | Description |
|---|---|---|
| ITween | tween | The tween to query. Must not be |
Returns
| Type | Description |
|---|---|
| float |
PositiveInfinity if Loops is
Otherwise, |
Remarks
For sequences, the delay is defined at the sequence level and is not duplicated for each child tween. This method operates purely on the ITween interface and makes no assumptions about the concrete tween type.
See Also
IsActive(ITween)
Determines whether the tween is currently active - that is, in either the playing or paused state. A tween is considered active even when paused because it holds an intermediate animation state that has not yet been released.
Declaration
public static bool IsActive(this ITween tween)
Parameters
| Type | Name | Description |
|---|---|---|
| ITween | tween | The tween to query. Must not be |
Returns
| Type | Description |
|---|---|
| bool |
|
See Also
OnCompleteKill(ITween, Action)
Registers a callback that fires when the tween completes, then automatically kills the tween immediately afterward. This combines OnComplete(Action) with an implicit Kill(bool) so that a non-auto-kill tween is still cleaned up after use.
Declaration
public static ITween OnCompleteKill(this ITween tween, Action callback)
Parameters
| Type | Name | Description |
|---|---|---|
| ITween | tween | The tween to attach the callback to. Must not be |
| Action | callback | The action to invoke when the tween reaches its end value. May be |
Returns
| Type | Description |
|---|---|
| ITween | The same ITween instance, allowing further chaining. |
Remarks
This is particularly useful when AutoKill is set to
false (via SetAutoKill(bool)) and you still want the tween
to be disposed of after a single playthrough without needing to keep an external
reference for cleanup.
The kill is performed with complete: false, so the
OnKill(Action) callback fires after callback but
the tween's value is not re-applied.
See Also
OnProgress(ITween, Action<float>)
Registers a callback that is invoked on every update frame with the tween's current normalized progress value. This is a convenience wrapper around OnUpdate(Action) that exposes Progress as a parameter rather than requiring the caller to capture the tween reference.
Declaration
public static ITween OnProgress(this ITween tween, Action<float> callback)
Parameters
| Type | Name | Description |
|---|---|---|
| ITween | tween | The tween to attach the callback to. Must not be |
| Action<float> | callback | An action receiving the current Progress value (a
|
Returns
| Type | Description |
|---|---|
| ITween | The same ITween instance, allowing further chaining. |
Remarks
Note that Progress reflects linear elapsed time clamped to [0, 1] and does not include easing. If you need the eased progress, use the typed tween value directly via a setter or obtain it through the tween's own update callback.
See Also
PlayDelayed(ITween, float)
Sets a pre-play delay on the tween and immediately starts it, combining SetDelay(float) and Play() into a single call. The tween enters the Delayed state and waits for the specified duration before beginning interpolation.
Declaration
public static ITween PlayDelayed(this ITween tween, float delay)
Parameters
| Type | Name | Description |
|---|---|---|
| ITween | tween | The tween to configure and start. Must not be |
| float | delay | The number of seconds to wait before interpolation begins. Negative values are clamped to zero by the underlying SetDelay(float) implementation. |
Returns
| Type | Description |
|---|---|
| ITween | The same ITween instance, allowing further chaining. |
Remarks
The OnStart(Action) callback fires after the delay has elapsed, not at the moment Play() is called. The delay counts against GetTotalDuration(ITween) when looping.
See Also
PlayManaged(ITween)
Registers the tween with TweenManager for automatic per-frame updates and immediately starts playback, combining the effects of SetManaged(bool) and Play() into a single call.
Declaration
public static ITween PlayManaged(this ITween tween)
Parameters
| Type | Name | Description |
|---|---|---|
| ITween | tween | The tween to register and start. Must not be |
Returns
| Type | Description |
|---|---|
| ITween | The same ITween instance, allowing further chaining. |
Remarks
Managed tweens are driven by Update(float) each frame. The global time-scale (GlobalTimeScale) is applied to their delta time in addition to any per-tween TimeScale. Tweens whose Target is a destroyed UnityEngine.Object are culled automatically during the next update.
See Also
PlayWithEase(ITween, EaseType)
Applies the specified EaseType to the tween and immediately starts playback, combining SetEase(EaseType) and Play() into a single call.
Declaration
public static ITween PlayWithEase(this ITween tween, EaseType easeType)
Parameters
| Type | Name | Description |
|---|---|---|
| ITween | tween | The tween to configure and start. Must not be |
| EaseType | easeType | The easing function to use for interpolation. This overrides the tween's current ease (which defaults to DefaultEaseType). |
Returns
| Type | Description |
|---|---|
| ITween | The same ITween instance, allowing further chaining. |
Remarks
The tween is played as a manual tween unless SetManaged(bool) was already called. To play as a managed tween with a specific ease, call SetEase(EaseType) first and then PlayManaged(ITween).
See Also
SetLoopInfinite(ITween, LoopType)
Configures the tween to loop indefinitely using the specified
LoopType. This is shorthand for calling
SetLoops(int, LoopType) with a loops argument of -1.
Declaration
public static ITween SetLoopInfinite(this ITween tween, LoopType loopType = LoopType.Restart)
Parameters
| Type | Name | Description |
|---|---|---|
| ITween | tween | The tween to configure. Must not be |
| LoopType | loopType | How the tween should behave at the end of each iteration:
|
Returns
| Type | Description |
|---|---|
| ITween | The same ITween instance, allowing further chaining. |
Remarks
An infinitely looping tween will never reach the Complete state on its own. It must be killed via Kill(bool) or one of the batch kill methods on ScyllaTween to stop it. The GetTotalDuration(ITween) utility returns PositiveInfinity for infinite loops.
See Also
SetPingPong(ITween, int)
Configures the tween to play forward and then backward repeatedly (ping-pong / yoyo effect) for the specified number of complete back-and-forth cycles. This is shorthand for calling SetLoops(int, LoopType) with Yoyo.
Declaration
public static ITween SetPingPong(this ITween tween, int loops = -1)
Parameters
| Type | Name | Description |
|---|---|---|
| ITween | tween | The tween to configure. Must not be |
| int | loops | The total number of loop iterations (forward + backward counted separately). Pass
|
Returns
| Type | Description |
|---|---|
| ITween | The same ITween instance, allowing further chaining. |
See Also
TogglePause(ITween)
Toggles the tween between its playing and paused states. If the tween is paused it is resumed; if it is playing it is paused. If the tween is in any other state (e.g., Created, Complete, or Killed) the tween is returned unchanged.
Declaration
public static ITween TogglePause(this ITween tween)
Parameters
| Type | Name | Description |
|---|---|---|
| ITween | tween | The tween to toggle. Must not be |
Returns
| Type | Description |
|---|---|
| ITween | The same ITween instance, allowing further chaining. |
See Also
WaitForCompletion(ITween, Action)
Registers a callback to be invoked when the tween completes, providing a callback-based alternative to async/await. This is a direct pass-through to OnComplete(Action) and exists to make completion-waiting intent explicit in code that does not use a task library.
Declaration
public static ITween WaitForCompletion(this ITween tween, Action onComplete)
Parameters
| Type | Name | Description |
|---|---|---|
| ITween | tween | The tween to observe. Must not be |
| Action | onComplete | The callback to invoke when the tween reaches Complete.
May be |
Returns
| Type | Description |
|---|---|
| ITween | The same ITween instance, allowing further chaining. |
Remarks
For proper async/await integration consider using UniTask or a similar
task library that can wrap tween completion into an awaitable. This method merely
registers a synchronous callback; it does not make the tween awaitable.