Class Tween
Representation of a tween. A uuid is attributed to the tween on creation. Each instances can be manipulated with a variety of methods.
Properties
completedLoopsCount
The number of loops completed since the tween started.
duration
Duration of a tween's loop (in seconds). If the tween is not a loop then it's the duration of the tween itself.
easingFunction
Defines easing functions used internally and provides methods to calculate new values.
elapsedSinceDelay
Time elapsed in seconds (delay excluded).
elapsedTotal
Time elapsed in seconds (delay included).
id
UUID given on creation.
isAlive
While true
the tween is referenced in Str8Tween and can be controlled.
isFinished
If true
the tween finished playing.
isRunning
If true
the tween is currently playing.
killOnEnd
If true
the tween will be killed after playing.
loopsCount
The number of loops to do.
loopStyle
The type of loop to use.
target
GameObject on which the tween will be applied.
Constructors
Tween(CanvasRenderer, Single, EasingFunction, Single, Boolean, String)
Instantiate a new tween, initialize it and give it a UUID.
Parameters
canvasRenderer (CanvasRenderer) | The CanvasRenderer on which changes will be applied. |
toValue (Float) | A |
easingFunction (EasingFunction) | The easing function represents the type of easing. |
duration (Float) | Total tween duration (in seconds). |
killOnEnd (Boolean) | (Optional) If |
methodName (String) | Name of the method which called this constructor. |
Examples
Create new tween that changes CanvasRenderer's alpha :
using UnityEngine;
using Str8lines.Tweening;
public class MyClass : MonoBehaviour
{
public CanvasRenderer canvasRenderer;
private void Start()
{
Tween t = new Tween("fade", canvasRenderer, 0f, EasingFunction.Linear, 3f);
}
}
Tween(Graphic, Single, EasingFunction, Single, Boolean, String)
Instantiate a new tween, initialize it and give it a UUID.
Parameters
graphic (Graphic) | The Graphic on which changes will be applied. |
toValue (Float) | A |
easingFunction (EasingFunction) | The easing function represents the type of easing. |
duration (Float) | Total tween duration (in seconds). |
killOnEnd (Boolean) | (Optional) If |
methodName (String) | Name of the method which called this constructor. |
Examples
Create new tween that changes graphic's alpha :
using UnityEngine;
using Str8lines.Tweening;
public class MyClass : MonoBehaviour
{
public Graphic graphic;
private void Start()
{
Tween t = new Tween("fade", graphic, 0f, EasingFunction.Linear, 3f);
}
}
Tween(RectTransform, Vector3, EasingFunction, Single, Boolean, String)
Instantiate a new tween, initialize it and give it a UUID.
Parameters
rectTransform (RectTransform) | The RectTransform on which changes will be applied. |
toVector (Vector3) | A Vector3 that represents |
easingFunction (EasingFunction) | The easing function represents the type of easing. |
duration (Float) | Total tween duration (in seconds). |
killOnEnd (Boolean) | (Optional) If |
methodName (String) | Name of the method which called this constructor. |
Examples
Create new tween that changes target's position :
using UnityEngine;
using Str8lines.Tweening;
public class MyClass : MonoBehaviour
{
public RectTransform rectTransform;
private void Start()
{
Vector3 destination = new Vector3(0, 500, 0);
Tween t = new Tween("move", rectTransform, destination, EasingFunction.Linear, 3f);
}
}
Tween(SpriteRenderer, Single, EasingFunction, Single, Boolean, String)
Instantiate a new tween, initialize it and give it a UUID.
Parameters
spriteRenderer (SpriteRenderer) | The SpriteRenderer on which changes will be applied. |
toValue (Float) | A |
easingFunction (EasingFunction) | The easing function represents the type of easing. |
duration (Float) | Total tween duration (in seconds). |
killOnEnd (Boolean) | (Optional) If |
methodName (String) | Name of the method which called this constructor. |
Examples
Create new tween that changes SpriteRenderer's alpha :
using UnityEngine;
using Str8lines.Tweening;
public class MyClass : MonoBehaviour
{
public SpriteRenderer spriteRenderer;
private void Start()
{
Tween t = new Tween("fade", spriteRenderer, 0f, EasingFunction.Linear, 3f);
}
}
Methods
complete(Boolean, CompletionMode)
Completes the tween.
Parameters
triggerOnEnd (Boolean) | (Optional) If |
mode (CompletionMode) | (Optional) The completion mode defines the end values to apply. Default value is |
Remarks
Completing a tween sends the target to its final values.
Examples
Press space to complete.
using UnityEngine;
using Str8lines.Tweening;
public class MyClass : MonoBehaviour
{
public RectTransform rectTransform;
private Tween t;
private void Start()
{
Vector3 destination = new Vector3(0, 500, 0);
t = new Tween("move", rectTransform, destination, EasingFunction.Linear, 3f);
}
private void Update()
{
if (Input.GetKeyDown(KeyCode.Space)) t.complete();
}
}
delay()
Returns
Float
➜ The delay before the tween starts (in seconds).
Examples
using UnityEngine;
using Str8lines.Tweening;
public class MyClass : MonoBehaviour
{
public RectTransform rectTransform;
private void Start()
{
Vector3 destination = new Vector3(0, 500, 0);
Tween t = new Tween("move", rectTransform, destination, EasingFunction.Linear, 3f);
Debug.Log(t.delay());
}
}
delay(Single)
Add delay to the tween before it starts playing.
Parameters
delay (Float) | Time before the tween start (in seconds). |
Returns
Tween
➜ The tween delayed.
Examples
Add 2 seconds of delay before the tween starts.
using UnityEngine;
using Str8lines.Tweening;
public class MyClass : MonoBehaviour
{
public RectTransform rectTransform;
private void Start()
{
Vector3 destination = new Vector3(0, 500, 0);
Tween t = new Tween("move", rectTransform, destination, EasingFunction.Linear, 3f);
t.delay(2f);
}
}
kill()
Kills the tween. This removes the tween's callbacks and sets isAlive to false
. Str8Tween class will remove every reference to the tween.
Examples
Press space to kill.
using UnityEngine;
using Str8lines.Tweening;
public class MyClass : MonoBehaviour
{
public RectTransform rectTransform;
private Tween t;
private void Start()
{
Vector3 destination = new Vector3(0, 500, 0);
t = new Tween("move", rectTransform, destination, EasingFunction.Linear, 3f);
}
private void Update()
{
if (Input.GetKeyDown(KeyCode.Space)) t.kill();
}
}
loop(Int32, LoopStyle)
Makes the tween loop.
Parameters
loopsCount (Int) | (Optional) Number of loops to do. Default value is -1. |
loopStyle (LoopStyle) | (Optional) Type of loop. Default value is LoopStyle.Restart. |
Returns
Tween
➜ The tween which loops.
Remarks
Default loopsCount
's value is -1 which is equivalent to infinite loops.
Examples
Realizes five oscillating loops of a move tween.
using UnityEngine;
using Str8lines.Tweening;
public class MyClass : MonoBehaviour
{
public RectTransform rectTransform;
private void Start()
{
Vector3 destination = new Vector3(0, 500, 0);
Tween t = new Tween("move", rectTransform, destination, EasingFunction.Linear, 3f);
t.loop(5, LoopStyle.Oscillate);
}
}
onEnd(Tween.TweenDelegate)
Adds a callback to the tween's end event.
Parameters
callback (Tween.TweenDelegate) | Callback function to trigger. |
Returns
Tween
➜ The tween which will rise the end event.
Examples
Displays a message in console when the move tween ends.
using UnityEngine;
using Str8lines.Tweening;
public class MyClass : MonoBehaviour
{
public RectTransform rectTransform;
private void Start()
{
Vector3 destination = new Vector3(0, 500, 0);
Tween t = new Tween("move", rectTransform, destination, EasingFunction.Linear, 3f);
t.onEnd(_onEnd);
}
private void _onEnd()
{
UnityEngine.Debug.Log("End");
}
}
onLoop(Tween.TweenLoopDelegate)
Adds a callback to the tween's loop event.
Parameters
callback (Tween.TweenLoopDelegate) | Callback function to trigger. |
Returns
Tween
➜ The tween which will rise the loop event.
Examples
Displays the number of loops accomplished in console when the move tween loops.
using UnityEngine;
using Str8lines.Tweening;
public class MyClass : MonoBehaviour
{
public RectTransform rectTransform;
private void Start()
{
Vector3 destination = new Vector3(0, 500, 0);
Tween t = new Tween("move", rectTransform, destination, EasingFunction.Linear, 3f);
t.loop(5, LoopStyle.Oscillate).onLoop(_onLoop);
}
private void _onLoop(int loopsCount)
{
UnityEngine.Debug.Log("Loop count : " + loopsCount);
}
}
onStart(Tween.TweenDelegate)
Adds a callback to the tween's start event.
Parameters
callback (Tween.TweenDelegate) | Callback function to trigger. |
Returns
Tween
➜ The tween which will rise the start event.
Examples
Displays a message in console when the move tween starts.
using UnityEngine;
using Str8lines.Tweening;
public class MyClass : MonoBehaviour
{
public RectTransform rectTransform;
private void Start()
{
Vector3 destination = new Vector3(0, 500, 0);
Tween t = new Tween("move", rectTransform, destination, EasingFunction.Linear, 3f);
t.onStart(_onStart);
}
private void _onStart()
{
UnityEngine.Debug.Log("Start");
}
}
pause()
Pauses the tween.
Examples
Press space to pause.
using UnityEngine;
using Str8lines.Tweening;
public class MyClass : MonoBehaviour
{
public RectTransform rectTransform;
private Tween t;
private void Start()
{
Vector3 destination = new Vector3(0, 500, 0);
t = new Tween("move", rectTransform, destination, EasingFunction.Linear, 3f);
}
private void Update()
{
if (Input.GetKeyDown(KeyCode.Space)) t.pause();
}
}
play()
Plays the tween.
Examples
Press space to play.
using UnityEngine;
using Str8lines.Tweening;
public class MyClass : MonoBehaviour
{
public RectTransform rectTransform;
private Tween t;
private void Start()
{
Vector3 destination = new Vector3(0, 500, 0);
t = new Tween("move", rectTransform, destination, EasingFunction.Linear, 3f);
}
private void Update()
{
if (Input.GetKeyDown(KeyCode.Space)) t.play();
}
}
reset()
Resets the tween values.
Examples
Press space to reset.
using UnityEngine;
using Str8lines.Tweening;
public class MyClass : MonoBehaviour
{
public RectTransform rectTransform;
private Tween t;
private void Start()
{
Vector3 destination = new Vector3(0, 500, 0);
t = new Tween("move", rectTransform, destination, EasingFunction.Linear, 3f);
}
private void Update()
{
if (Input.GetKeyDown(KeyCode.Space)) t.reset();
}
}
stop(Boolean)
Stops the tween.
Parameters
triggerOnEnd (Boolean) | (Optional) If |
Remarks
Stopping a tween does not change the target's current values.
Examples
Press space to stop.
using UnityEngine;
using Str8lines.Tweening;
public class MyClass : MonoBehaviour
{
public RectTransform rectTransform;
private Tween t;
private void Start()
{
Vector3 destination = new Vector3(0, 500, 0);
t = new Tween("move", rectTransform, destination, EasingFunction.Linear, 3f);
}
private void Update()
{
if (Input.GetKeyDown(KeyCode.Space)) t.stop();
}
}
update(Single)
Determines new values from the time t
elapsed and applies it to the tween's target. Also triggers callbacks when required.
Parameters
t (Float) | The time elapsed (in seconds). |
Examples
Updates a tween at new frame.
using UnityEngine;
using Str8lines.Tweening;
public class MyClass : MonoBehaviour
{
public RectTransform rectTransform;
private Tween t;
private void Start()
{
Vector3 destination = new Vector3(0, 500, 0);
t = new Tween("move", rectTransform, destination, EasingFunction.Linear, 3f);
}
private void Update()
{
t.update(Time.deltaTime)
}
}