HOTween.To
To animate an object, you need to create a Tweener. This is simply achieved using HOTween.To(...), in one of 3 possible ways:
HOTween.To(target, duration, propName, endValue)
- target
- The object containing the properties to tween.
- duration
- The seconds of duration of the tween.
- propName
- The name of the property or field to tween (must be public and non-static).
- endValue
- The value the property/field should reach with the tween.
Example
HOTween.To(myObject, 1, "fieldName", 2);
HOTween.To(target, duration, propName, endValue, isRelative)
- target
- The object containing the properties to tween.
- duration
- The seconds of duration of the tween.
- propName
- The name of the property or field to tween (must be public and non-static).
- endValue
- The value the property/field should reach with the tween (or should be moved by, if isRelative is set to true.
- isRelative
- If true, considers the endValue as relative instead than absolute (meaning it will animate BY instead than animate TO.
Example
HOTween.To(myObject, 1, "fieldName", 2, true);
HOTween.To(target, duration, propName, endValue, isRelative, easeType, delay)
- target
- The object containing the properties to tween.
- duration
- The seconds of duration of the tween.
- propName
- The name of the property or field to tween (must be public and non-static).
- endValue
- The value the property/field should reach with the tween (or should be moved by, if isRelative is set to true.
- isRelative
- If true, considers the endValue as relative instead than absolute (meaning it will animate BY instead than animate TO.
- easeType
- The ease to apply.
- delay
- The eventual delay before the tween will start.
Example
HOTween.To(myObject, 1, "fieldName", 2, true, EaseType.Linear, 1);
HOTween.To(target, duration, parameters)
- target
- The object containing the properties to tween.
- duration
- The seconds of duration of the tween.
- parameters
- A TweenParms object containing the tween parameters. You can pass an existing one, or create a new one inline via method chaining.
Example
HOTween.To(myObject, 1, new TweenParms().Prop("fieldName", 2).Ease(EaseType.easeOutQuad).Loops(2).OnComplete(myOnCompleteFunction));
HOTween.To will return a Tweener. You can either store it for direct use (or to add it to a Sequence), or you can ignore it and just let it run. Unless you expressly choose otherwise, once an animation is complete the Tweener will be destroyed.
HOTween.From
Works exactly as HOTween.To, but will animate from the given value instead than to.
Note that, unless you start the tween in a paused state, the OnStart callback will be called immediately, even if a delay was set. This happens because the target will immediately jump to the From value.
HOTween.From(target, duration, propName, fromValue)
- target
- The object containing the properties to tween.
- duration
- The seconds of duration of the tween.
- propName
- The name of the property or field to tween (must be public and non-static).
- fromValue
- The value the property/field should start from.
Example
HOTween.From(myObject, 1, "fieldName", 2);
HOTween.From(target, duration, propName, fromValue, isRelative)
- target
- The object containing the properties to tween.
- duration
- The seconds of duration of the tween.
- propName
- The name of the property or field to tween (must be public and non-static).
- fromValue
- The value the property/field should start from.
- isRelative
- If true, considers the fromValue as relative instead than absolute.
Example
HOTween.From(myObject, 1, "fieldName", 2, true);
HOTween.From(target, duration, propName, fromValue, isRelative, easeType, delay)
- target
- The object containing the properties to tween.
- duration
- The seconds of duration of the tween.
- propName
- The name of the property or field to tween (must be public and non-static).
- fromValue
- The value the property/field should start from.
- isRelative
- If true, considers the fromValue as relative instead than absolute.
- easeType
- The ease to apply.
- delay
- The eventual delay before the tween will start.
Example
HOTween.From(myObject, 1, "fieldName", 2, true, EaseType.Linear, 1);
HOTween.From(target, duration, parameters)
- target
- The object containing the properties to tween.
- duration
- The seconds of duration of the tween.
- parameters
- A TweenParms object containing the tween parameters. You can pass an existing one, or create a new one inline via method chaining.
Example
HOTween.From(myObject, 1, new TweenParms().Prop("fieldName", 2).Ease(EaseType.easeOutQuad).Loops(2).OnComplete(myOnCompleteFunction));
HOTween.From will return a Tweener. You can either store it for direct use (or to add it to a Sequence), or you can ignore it and just let it run. Unless you expressly choose otherwise, once an animation is complete the Tweener will be destroyed.
HOTween Static Methods and Properties
Think of HOTween's class as a manager for all the tweens (both Tweeners than Sequences) that you create, which lets you control all existing tweens with various filters:
Controls
Based on the additional parameters you pass to each control method, all control operations can be filtered in different ways. Where you read "first-level", it means that if a Tweener/Sequence is inside another Sequence, it is not taken into account (first-level Sequences control all their nested Tweeners/Sequences, thus there's no need to go deeper):
- ()
- All tweens (both Tweeners than Sequences) will be involved.
- (target)
- The operation will involve first-level Tweeners whose target is the given one.
- (id)
- The operation will involve first-level Tweeners/Sequences whose id is the given one.
- (intId)
- The operation will involve first-level Tweeners/Sequences whose intId is the given one.
- (tweener)
- The operation will involve the given first-level Tweener.
- (sequence)
- The operation will involve the given first-level Sequence.
Complete()
Completes the tween/s.
Kill()
Cleans and removes the tween/s from HOTween.
Pause()
Pauses the tween/s.
Play()
Plays the tween/s.
PlayBackwards()
Plays the tween/s in backwards direction.
PlayForward()
Plays the tween/s in forward direction.
Restart()
Restarts the tween/s from the beginning.
Reverse()
Reverse the tween/s, (means the virtual playhead will move backwards if it was going forward, or forward if it was going backwards).
Rewind()
Rewinds and pauses the tween/s.
Other Methods
GetAllTweens()
Returns a list of all existing IHOTweenComponent (Tweeners and Sequences — nested Tweeners/Sequences excluded) elements.
GetAllPlayingTweens()
Returns a list of all existing IHOTweenComponent (Tweeners and Sequences — nested Tweeners/Sequences excluded) elements that are currently playing.
GetAllPausedTweens()
Returns a list of all existing IHOTweenComponent (Tweeners and Sequences — nested Tweeners/Sequences excluded) elements that are currently paused.
GetTweenersByTarget(target, includeNestedTweens)
Returns a list of the existing Tweener elements whose target corresponds to the given one.
Set the includeNestedTweens parameter to true to search also within nested tweens (meaning Tweeners that are contained inside Sequences).
GetTweensById(intId, includeNestedTweens)
Returns a list of the existing IHOTweenComponent elements whose id corresponds to the given one.
Set the includeNestedTweens parameter to true to search also within nested tweens (meaning Tweeners/Sequences that are contained inside other Sequences).
GetTweensByIntId(id, includeNestedTweens)
Returns a list of the existing IHOTweenComponent elements whose intId corresponds to the given one.
Set the includeNestedTweens parameter to true to search also within nested tweens (meaning Tweeners/Sequences that are contained inside other Sequences).
IsLinkedTo(target)
Returns true if the given target is linked to any Tweener or Sequence (running or not, taking into account also nested tweens).
IsTweening(target/id/intId)
Returns true if the given target/id/intId is currently involved in any running Tweener or Sequence (taking into account also nested tweens). Returns false both if the given target is not inside a Tweener, than if the relative Tweener is paused. To simply check if a target is attached to a Tweener or Sequence use IsLinkedTo instead.
Properties
- defEaseType
- The default EaseType for new Tweeners/Sequences that don't specify it.
- defLoopType
- The default LoopType for new Tweeners/Sequences that don't specify it.
- defTimeScale
- The default time scale for new Tweeners/Sequences that don't specify it.
- defUpdateType
- The default UpdateType for new Tweeners/Sequences that don't specify it.
- showPathGizmos
- If true, shows the eventual paths in use by PlugVector3Path.
- totTweens
- The total number of first-level Tweeners and Sequences, paused or not (first level means that Tweeners or Sequences contained in other Sequences don't count).
- warningLevel
- The level of debug output in case an error is encountered and resolved without throwing exceptions.
Tweener
Tweeners are the low-level workers, and are directly responsible of the animations of an object. You create one each time you use HOTween.To, and you can store a reference to it to use its methods or properties:
Methods
ApplyCallback()
Assigns the given type of callback to this Tweener, overwriting any existing callbacks of the same type (which could have been set via TweenParms or another call to ApplyCallback).
Complete()
Completes the tween.
GetPathLength()
If the Tweener contains a path tween (with PlugVector3Path), returns the length of the path, otherwise returns -1.
GetPointOnPath()
If the Tweener contains a path tween (with PlugVector3Path), returns a Vector3 point at the given percentage (0 to 1) on the path, correctly considering its constant speed.
GoTo()
Sends the tween to the given time (taking also loops into account). If the time is bigger than the full tween duration, it goes to the end.
If the tween was playing, it will continue playing. If it was paused, it will stay paused.
GoToAndPlay()
Sends the tween to the given time (taking also loops into account) and plays it. If the time is bigger than the full tween duration, it goes to the end.
Kill()
Cleans and removes the tween from HOTween.
Pause()
Pauses the tween.
Play()
Plays the tween.
PlayBackwards()
Plays the tween in backwards direction.
PlayForward()
Plays the tween in forward direction.
ResetAndChangeParms()
Completely resets the Tweener except its target, and applies the new given parameters to it. Check HOTween API to learn more.
C# Example
myTweener = HOTween.To(someTransform, 2, new TweenParms().Prop("position", new Vector3(0,1,2)));
myTweener.ResetAndChangeParms(TweenType.To, 4, new TweenParms().Prop("rotation", new Vector3(0,180,0)));
ResetPath()
Resets a path that had been portioned via UsePartialPath.
Restart()
Restarts the tween from the beginning.
Reverse()
Reverses the tween, (means the virtual playhead will move backwards if it was going forward, or forward if it was going backwards).
Rewind()
Rewinds and pauses the tween.
UsePartialPath()
If the Tweener contains a path tween (with PlugVector3Path), allows to use only a portion of that path, between the given waypoints. Duration and easing will be automatically re-adapted, or you can enter new ones. Check HOTween API to learn more.
C# Example
myTweener = HOTween.To(someTransform, 2, new TweenParms().Prop("position", new PlugVector3Path(myPath)));
myTweener.UsePartialPath(1, 3);
WaitForCompletion()
A Coroutine which can be used to wait for the completion (delays and loops included) of the tween.
C# Example
public class CoroutineExample : MonoBehaviour
{
void Start() {
StartCoroutine( MyCoroutine() );
}
IEnumerator MyCoroutine() {
yield return StartCoroutine( HOTween.To( transform, 1, "position", new Vector3(1,1,1) ).WaitForCompletion() );
...
}
}
WaitForRewind()
A Coroutine which can be used to wait for the rewinding of the tween (see WaitForCompletion to understand how it works.
Properties (can be changed even while the tween is playing)
- autoKillOnComplete
- If set to false, doesn't clean nor remove this Tweener from HOTween's list when it is completed.
- easeAnimationCurve
- Assigns a Unity AnimationCurve to use as easing for this tween, overriding all previously set easings.
- easeType
- The EaseType used by this tween. Setting it overrides all previously set easings.
- enabled
- If set to false, this Tweener won't be updated, and any use of animation methods (Play/Pause/Rewind/etc.) will be ignored (both if called directly via the Tweener instance, than if using HOTween.Play/Pause/Rewind/etc.).
- id
- Eventual ID of this tween (more than one Tweener/Sequence can share the same ID, thus allowing for grouped operations).
- intId
- Eventual int ID of this tween.
- loops
- Number of times this tween will run (-1 means infinite loops).
- loopType
- The LoopType used by this tween.
- position
- Gets and sets the time position of this tween (loops are included when not infinite, delay is not).
- timeScale
- Time scale used by this tween.
Read-Only Properties
- completedLoops
- Number of loops that have been completed.
- delay
- The delay that was set for this tween.
- duration
- Duration of this tween, loops and delay excluded.
- elapsed
- Elapsed time within the current loop (delay excluded). Note that elapsed will be equal to duration only when all the loops are completed, otherwise each time a loop is completed, completedLoops is augmented by 1 and elapsed is reset to 0.
- elapsedDelay
- Elapsed delay.
- fullDuration
- Full duration of this tween, loops included (when not infinite) but delay excluded.
- fullElapsed
- Full elapsed time including loops (but without considering tween delay).
- hasStarted
- Returns true after this tween was started for the first time.
- isComplete
- Returns true while this tween is complete.
- isEmpty
- Returns true if this Tweener has no property to tween (means that no valid property to tween was set).
- isLoopingBack
- Returns true when this tween is in the "going back" part of a Yoyo/YoyoInverse loop.
- isPaused
- Returns true if this tween currently paused.
- isReversed
- Returns true if this tween is set to go backwards (due to a call to Reverse()).
- target
- The Tweener's target.
- updateType
- The UpdateType used by this tween.
Tween Parameters (TweenParms)
Tween parameters are represented by a TweenParms object, who is created via method chaining. Method chaining simply consists of a series of functions joined together, like Func1().Func2().Func3().
To create a tween's parms, you start with a new TweenParms(), and then chain the desired methods, which represent different options. Code assist will help you see which parameters are available, and to quickly auto-complete them.
All parameters are specific to the current tween and optional (but you will have to add at least one Prop, otherwise the tween won't know what to animate). For all the parameters that you don't chain, default values will be used.
Example
new TweenParms().Prop("fieldName", 2).Ease(EaseType.easeOutQuad).Loops(2).OnComplete(myOnCompleteFunction);
The available parameters are:
Properties parameters
Prop(propName, endValue, isRelative)
Sets a property to tween, and the tween value and type.
You can chain as many Props as you wish.
- propName
- The name of the property or field to tween (must be public and non-static).
- endValue
- The value the property/field should reach with the tween (or should be moved by, if isRelative is set to true.
- isRelative
- If true, considers the endValue as relative instead than absolute (meaning it will animate BY instead than animate TO.
Example
HOTween.To(myObject, 1, new TweenParms().Prop("fieldName1",2).Prop("fieldName2",1,true).Ease(EaseType.easeOutQuad).Loops(2).OnComplete(myOnCompleteFunction));
Prop(propName, tweenPlugin)
Sets a property to tween, directly using the given plugin.
You can chain as many Props as you wish.
- propName
- The name of the property or field to tween (must be public and non-static).
- tweenPlugin
- The plugin to use for this property's tween.
Example
HOTween.To(myObject, 1, new TweenParms().Prop("fieldName1",new PlugInt(2)).Prop("fieldName2",1,true).Ease(EaseType.easeOutQuad).Loops(2).OnComplete(myOnCompleteFunction));
NewProp(propName, endValue, isRelative) / NewProp(propName, tweenPlugin)
Works exactly as Prop(...), but erases all the previous Props that you set (useful if you want to use the same TweenParms object with more than one tween).
Optional parameters
AutoKill(autoKill)
Setting this parameter to false will prevent the tween to be automatically destroyed when it is complete. To destroy it, you will need to directly Kill it.
Example
HOTween.To(myObject, 1, new TweenParms().Prop("fieldName",1,true).AutoKill(false).Loops(2).OnComplete(myOnCompleteFunction));
Delay(delay)
Sets the seconds of delay before the tween will start.
- delay
- The seconds of delay.
Example
HOTween.To(myObject, 1, new TweenParms().Prop("fieldName",1,true).Delay(2).Loops(2).OnComplete(myOnCompleteFunction));
Ease(easeType / animationCurve)
Sets the EaseType for this tween (overshoot of Back easings and amplitude/period of Elastic ones can be customized, check the EaseType enum in the API for available types and usage).
You can alternatively assign a Unity AnimationCurve instead than one of the regular ease curves.
- easeType
- The EaseType for this tween.
- animationCurve
- The AnimationCurve to use as easing for this tween.
Example
HOTween.To(myObject, 1, new TweenParms().Prop("fieldName",1,true).Ease(EaseType.easeOutQuad).Loops(2).OnComplete(myOnCompleteFunction));
Id(idName)
Sets the eventual ID for this Tweener.
The same ID can be applied to multiple Tweeners and Sequences, thus allowing for grouped operations (all HOTween static controls can filter operations per ID).
- idName
- The ID to set.
Example
HOTween.To(myObject, 1, new TweenParms().Prop("fieldName",1,true).Id("myTween").Loops(2).OnComplete(myOnCompleteFunction));
IntId(id)
Sets the eventual numerical (int) ID for this Tweener.
Works exactly as Id(), but since it uses ints instead than strings it's way faster (thus is the best option if you need to squeeze maximum performance, like on mobile phones).
The same ID can be applied to multiple Tweeners and Sequences, thus allowing for grouped operations (all HOTween static controls can filter operations per ID).
- id
- The ID to set.
Example
HOTween.To(myObject, 1, new TweenParms().Prop("fieldName",1,true).IntId(10).Loops(2).OnComplete(myOnCompleteFunction));
KeepEnabled/KeepDisabled(behaviour/behaviour[]/gameObject/gameObject[])
Keeps the given target disabled or enabled (in case of Behaviours - activated or deactivated in case of GameObjects) while the tween is running. When the tween is complete/rewinded/paused, the target is reset to the exact state it had before the tween started playing. You can pass a single target, or an array of targets.
Example
HOTween.To(myObject.transform, 2, new TweenParms().Prop("position",new Vector3(1,2,4)).KeepDisabled(myComponent).Loops(2).OnComplete(myOnCompleteFunction));
Loops(loops, loopType)
Sets the type and total number of loops that will be played.
- loops
- The number of loops to execute. 1 means a single run with no loops, -1 or Mathf.Infinity indicate infinite loops.
- loopType
- The LoopType to use (check LoopType in the API to see the available options in detail: Restart, Yoyo, YoyoInverse, Incremental).
Example
HOTween.To(myObject, 1, new TweenParms().Prop("fieldName",1,true).Loops(3,LoopType.Yoyo).OnComplete(myOnCompleteFunction));
Pause()
A special parameter, which will immediately set the tween in a paused state.
Example
HOTween.To(myObject, 1, new TweenParms().Prop("fieldName",1,true).Pause().Loops(2).OnComplete(myOnCompleteFunction));
PixelPerfect()
A special parameter, which will tween float/Vector2/Vector3 values using integers. Also works with PlugVector3X/Y/Z
Example
HOTween.To(myTransform, 1, new TweenParms().Prop("position", new Vector3(3,10,12)).PixelPerfect());
TimeScale(timeScale)
Sets the time scale to use.
- timeScale
- The time scale to use.
Example
HOTween.To(myObject, 1, new TweenParms().Prop("fieldName",1,true).TimeScale(2).Loops(2).OnComplete(myOnCompleteFunction));
UpdateType(updateType)
The UpdateType to use (check the UpdateType enum in the API for available types).
- updateType
- The UpdateType to use (Update, LateUpdate, FixedUpdate, TimeScaleIndependentUpdate).
Example
HOTween.To(myObject, 1, new TweenParms().Prop("fieldName",1,true).UpdateType(UpdateType.LateUpdate).Loops(2).OnComplete(myOnCompleteFunction));
SpeedBased()
When set, this will make the tween become speed-based instead than time-based. When this happens, duration will be interpreted as "speed x second" (for example, if tweening a Vector3 with a duration of 2, the animation will move with a speed of 2 units x second).
Note that the easing will have no effect when movement is speed-based, and speed-based can't be used inside Sequences.
Example
HOTween.To(myObject.transform, 2, new TweenParms().Prop("position",new Vector3(1,2,4)).SpeedBased().Loops(2).OnComplete(myOnCompleteFunction));
Callback parameters
OnComplete(callbackFunction, additionalParameters)
A function to call when the tween is fully completed, all loops included.
- callbackFunction
- The function to call. It must return void and either have no parameters, or a single parameter of type TweenEvent (which will contain a tween property, with a reference to this Tweener, and a parms array, with all the additional parameters you might've given it).
- additionalParameters
- A comma separated list of eventual additional parameters.
Callback function without parameters
HOTween.To(myObject, 1, new TweenParms().Prop("fieldName",1,true).OnComplete(MyFunction));
private void MyFunction() {}
private function MyFunction() {}
Callback function with parameters
HOTween.To(myObject, 1, new TweenParms().Prop("fieldName",1,true).OnComplete(MyFunction,1,2,3));
private void MyFunction( TweenEvent data ) {
Debug.Log( data.tween );
if ( data.parms != null ) {
Debug.Log( data.parms[0] );
}
}
private function MyFunction( data:TweenEvent ) {
Debug.Log( data.tween );
if ( data.parms != null ) {
Debug.Log( data.parms[0] );
}
}
OnComplete(sendMessageTarget, methodName, value)
A Unity SendMessage to execute when the tween is fully completed, all loops included.
- sendMessageTarget
- The GameObject to target for SendMessage.
- methodName
- The name of the method that will be called on every MonoBehaviour in the target GameObject.
- value
- An optional value to pass to SendMessage.
OnComplete with SendMessage behaviour
HOTween.To(myObject, 1, new TweenParms().Prop("fieldName",1,true).OnComplete(myGameObject, "methodName", someValue));
OnPause(callbackFunction, additionalParameters)
A function to call when the tween is paused.
- callbackFunction
- The function to call. It must return void and either have no parameters, or a single parameter of type TweenEvent (which will contain a tween property, with a reference to this Tweener, and a parms array, with all the additional parameters you might've given it).
- additionalParameters
- A comma separated list of eventual additional parameters.
Callback function without parameters
HOTween.To(myObject, 1, new TweenParms().Prop("fieldName",1,true).OnPause(MyFunction));
private void MyFunction() {}
private function MyFunction() {}
Callback function with parameters
HOTween.To(myObject, 1, new TweenParms().Prop("fieldName",1,true).OnPause(MyFunction,1,2,3));
private void MyFunction( TweenEvent data ) {
Debug.Log( data.tween );
if ( data.parms != null ) {
Debug.Log( data.parms[0] );
}
}
private function MyFunction( data:TweenEvent ) {
Debug.Log( data.tween );
if ( data.parms != null ) {
Debug.Log( data.parms[0] );
}
}
OnPlay(callbackFunction, additionalParameters)
A function to call when the tween starts playing, or it is resumed from a paused state.
- callbackFunction
- The function to call. It must return void and either have no parameters, or a single parameter of type TweenEvent (which will contain a tween property, with a reference to this Tweener, and a parms array, with all the additional parameters you might've given it).
- additionalParameters
- A comma separated list of eventual additional parameters.
Callback function without parameters
HOTween.To(myObject, 1, new TweenParms().Prop("fieldName",1,true).OnPlay(MyFunction));
private void MyFunction() {}
private function MyFunction() {}
Callback function with parameters
HOTween.To(myObject, 1, new TweenParms().Prop("fieldName",1,true).OnPlay(MyFunction,1,2,3));
private void MyFunction( TweenEvent data ) {
Debug.Log( data.tween );
if ( data.parms != null ) {
Debug.Log( data.parms[0] );
}
}
private function MyFunction( data:TweenEvent ) {
Debug.Log( data.tween );
if ( data.parms != null ) {
Debug.Log( data.parms[0] );
}
}
OnPluginOverwritten(callbackFunction, additionalParameters)
A function to call each time one of the plugins used in a tween is overwritten by another. Note that this obviously works only if you enabled the OverwriteManager correctly.
- callbackFunction
- The function to call. It must return void and either have no parameters, or a single parameter of type TweenEvent (which will contain a tween property, with a reference to this Tweener, and a parms array, with all the additional parameters you might've given it).
- additionalParameters
- A comma separated list of eventual additional parameters.
Callback function without parameters
HOTween.To(myObject, 1, new TweenParms().Prop("fieldName",1,true).OnPluginOverwritten(MyFunction));
private void MyFunction() {}
private function MyFunction() {}
Callback function with parameters
HOTween.To(myObject, 1, new TweenParms().Prop("fieldName",1,true).OnPluginOverwritten(MyFunction,1,2,3));
private void MyFunction( TweenEvent data ) {
Debug.Log( data.tween );
if ( data.parms != null ) {
Debug.Log( data.parms[0] );
}
}
private function MyFunction( data:TweenEvent ) {
Debug.Log( data.tween );
if ( data.parms != null ) {
Debug.Log( data.parms[0] );
}
}
OnRewinded(callbackFunction, additionalParameters)
A function to call each time the tween is fully rewinded, loops included (either because Rewind was called, or because it finished playing backwards).
- callbackFunction
- The function to call. It must return void and either have no parameters, or a single parameter of type TweenEvent (which will contain a tween property, with a reference to this Tweener, and a parms array, with all the additional parameters you might've given it).
- additionalParameters
- A comma separated list of eventual additional parameters.
Callback function without parameters
HOTween.To(myObject, 1, new TweenParms().Prop("fieldName",1,true).OnRewinded(MyFunction));
private void MyFunction() {}
private function MyFunction() {}
Callback function with parameters
HOTween.To(myObject, 1, new TweenParms().Prop("fieldName",1,true).OnRewinded(MyFunction,1,2,3));
private void MyFunction( TweenEvent data ) {
Debug.Log( data.tween );
if ( data.parms != null ) {
Debug.Log( data.parms[0] );
}
}
private function MyFunction( data:TweenEvent ) {
Debug.Log( data.tween );
if ( data.parms != null ) {
Debug.Log( data.parms[0] );
}
}
OnStart(callbackFunction, additionalParameters)
A function to call the first time the tween is started.
- callbackFunction
- The function to call. It must return void and either have no parameters, or a single parameter of type TweenEvent (which will contain a tween property, with a reference to this Tweener, and a parms array, with all the additional parameters you might've given it).
- additionalParameters
- A comma separated list of eventual additional parameters.
Callback function without parameters
HOTween.To(myObject, 1, new TweenParms().Prop("fieldName",1,true).OnStart(MyFunction));
private void MyFunction() {}
private function MyFunction() {}
Callback function with parameters
HOTween.To(myObject, 1, new TweenParms().Prop("fieldName",1,true).OnStart(MyFunction,1,2,3));
private void MyFunction( TweenEvent data ) {
Debug.Log( data.tween );
if ( data.parms != null ) {
Debug.Log( data.parms[0] );
}
}
private function MyFunction( data:TweenEvent ) {
Debug.Log( data.tween );
if ( data.parms != null ) {
Debug.Log( data.parms[0] );
}
}
OnStepComplete(callbackFunction, additionalParameters)
A function to call each time a single loop is completed.
- callbackFunction
- The function to call. It must return void and either have no parameters, or a single parameter of type TweenEvent (which will contain a tween property, with a reference to this Tweener, and a parms array, with all the additional parameters you might've given it).
- additionalParameters
- A comma separated list of eventual additional parameters.
Callback function without parameters
HOTween.To(myObject, 1, new TweenParms().Prop("fieldName",1,true).OnStepComplete(MyFunction));
private void MyFunction() {}
private function MyFunction() {}
Callback function with parameters
HOTween.To(myObject, 1, new TweenParms().Prop("fieldName",1,true).OnStepComplete(MyFunction,1,2,3));
private void MyFunction( TweenEvent data ) {
Debug.Log( data.tween );
if ( data.parms != null ) {
Debug.Log( data.parms[0] );
}
}
private function MyFunction( data:TweenEvent ) {
Debug.Log( data.tween );
if ( data.parms != null ) {
Debug.Log( data.parms[0] );
}
}
OnUpdate(callbackFunction, additionalParameters)
A function to call each time the tween is updated.
- callbackFunction
- The function to call. It must return void and either have no parameters, or a single parameter of type TweenEvent (which will contain a tween property, with a reference to this Tweener, and a parms array, with all the additional parameters you might've given it).
- additionalParameters
- A comma separated list of eventual additional parameters.
Callback function without parameters
HOTween.To(myObject, 1, new TweenParms().Prop("fieldName",1,true).OnUpdate(MyFunction));
private void MyFunction() {}
private function MyFunction() {}
Callback function with parameters
HOTween.To(myObject, 1, new TweenParms().Prop("fieldName",1,true).OnUpdate(MyFunction,1,2,3));
private void MyFunction( TweenEvent data ) {
Debug.Log( data.tween );
if ( data.parms != null ) {
Debug.Log( data.parms[0] );
}
}
private function MyFunction( data:TweenEvent ) {
Debug.Log( data.tween );
if ( data.parms != null ) {
Debug.Log( data.parms[0] );
}
}
Tween Plugins
To access plugins, you have to use/import the Holoville.HOTween.Plugins package in your script.
When you set up a Prop parameter, HOTween auto-detects the default tween plugin to use, based on the type of the property and the end value. However, there are times when you don't want to use a default plugin (like when you want to animate a property in a "different" way). In those cases, instead of simply writing the endVal, you can direcly set the desired plugin, instantiating it as a Prop.
Default number animation VS using a plugin who tweens through integers
HOTween.To(myObject, 1, new TweenParms().Prop("fieldName",90));
HOTween.To(myObject, 1, new TweenParms().Prop("fieldName",new PlugInt(90)));
Every plugin has these 3 main parameters (of which only endVal is required):
- endValue
- The value to tween to.
- ease/animationCurve
- The EaseType or AnimationCurve to use for easing.
- isRelative
- If true, the given endValue is considered relative instead than absolute (this means that the animation will tween BY the end value, instead than TO it).
Additionally, some plugins have additional parameters, which are set via method chaining.
Using a regular plugin
HOTween.To(myObject, 1, new TweenParms().Prop("fieldName",new PlugInt(90,EaseType.easeInQuad,true)));
Using a plugin with additional chained parameters
HOTween.To(myObject, 1, new TweenParms().Prop("fieldName",new PlugVector3Path(path,EaseType.easeInQuad,true).ClosePath()));
Default Plugins
Default plugins are set automatically, depending on the type of property (float, Vector3, Quaternion, etc.), thus you will never need to directly set them.
- PlugColor(endValue,ease/animationCurve,isRelative)
- Animates Color values.
- PlugFloat(endValue,ease/animationCurve,isRelative)
- Animates numbers.
- PlugQuaternion(endValue,ease/animationCurve,isRelative)
- Animates Quaternion values (endValue can be either a Quaternion or a Vector3 representing the rotation's euler angles).
- PlugRect(endValue,ease/animationCurve,isRelative)
- Animates Rect objects.
- PlugString(endValue,ease/animationCurve,isRelative)
- Animates a string, writing each character overtime. If isRelative is set to true, the endValue will be added to any existing string. Otherwise, existing strings will be overwritten while the new one is composed.
- PlugVector2(endValue,ease/animationCurve,isRelative)
- Animates Vector2 values.
- PlugVector3(endValue,ease/animationCurve,isRelative)
- Animates Vector3 values.
- PlugVector4(endValue,ease/animationCurve,isRelative)
- Animates Vector4 values.
Additional Plugins
I will add more plugins overtime, so check HOTween API to see the full list.
PlugInt(endValue,ease/animationCurve,isRelative)
Animates a number value stepping only through integers.
PlugQuaternion(endValue,ease/animationCurve,isRelative)
This is actually a default plugin, but it's here because you can directly set it in case you want to use its additional method chaining parameters:
- Beyond360()
- Choose whether you want to calculate angles bigger than 360 degrees or not. In the first case, the endValue will be reached using the full degrees of the given rotation. In the second case, the endValue will be reached from the shortest direction. If the endValue is set as relative, this option will have no effect, and full beyond 360 rotations will always be used.
PlugSetColor(endValue,ease/animationCurve,isRelative)
Animates a color of your choice. Used for changing material colors different from the default one (like _SpecColor or _Emission). Target for this tween must be of type Material.
Additional parameters (applied via method chaining):
- Property(colorName)
- Sets the color property to tween.
Example
HOTween.To(myGameObject.renderer.material, 1, new TweenParms().Prop("color", new PlugSetColor(Color.red).Property("_TintColor")).Ease(EaseType.easeOutBounce));
PlugVector3Path(path,ease/animationCurve,isRelative,pathType)
Animates a Vector3 (like a Transform.position) along a path composed of control points, using constant speed regardless of the segments lengths (compatible with every ease type).
If the initial point of the path is different from the target's position (and isRelative is set to false), an additional curve will be automatically created, to allow the target to reach the path.
pathType is an optional parameter, which can be set either to PathType.Linear (to calculate the path as a series of straight segments between waypoints), or to PathType.Curved (to calculate the path as a series of smooth curves between waypoints). If you don't set it, default is PathType.Curved.
Additional parameters (applied via method chaining):
- ClosePath()
- Automatically closes the given path, allowing cycled motions.
- LockPosition(axis)
- Prevents the target from tweening along the given axis (HOTween.Axis).
- LookAt(transform) / LookAt(position)
- Tells the target to always look at the given Transform or position.
- OrientToPath(lookAhead, lockRotationAxis)
- Orients the tween target along the path. The lookAhead option lets you choose a lookAhead percentage (0 to 1). The lockRotationAxis parameter lets you lock one or more axis (HOTween.Axis) so that they don't rotate while following the path.
- Is2D(isSideScrolling)
- Tells the path to work in Unity 2D coordinates. The optional parameter needs to be TRUE in case of 2D side-scrollers, FALSE in case of 2D top-down (FALSE by default).
PlugVector3X(endValue,ease/animationCurve,isRelative)
Animates only the X value of a Vector3.
PlugVector3Y(endValue,ease/animationCurve,isRelative)
Animates only the Y value of a Vector3.
PlugVector3Z(endValue,ease/animationCurve,isRelative)
Animates only the Z value of a Vector3.
Sequence
Sequences are used to wrap Tweeners or other Sequences inside a timeline, which can then be controlled as it was a simple tween.
Contrary to Tweeners, Sequences are created in a paused state, and you'll have to call mySequence.Play() to start them.
Delays and loops added to Tweeners won't work correctly inside Sequences. Use AppendInterval to add delays between each Sequence element instead
Creating a new Sequence
Before adding stuff to a Sequence, you have to create it. This is simply done by using the new keyword, and then setting the desired sequence parameters (SequenceParms) with method chaining - exactly as TweenParms worked.
A new sequence with 3 Yoyo loops and an OnComplete callback
mySequence = new Sequence(new SequenceParms().Loops(3,LoopType.Yoyo).OnComplete(MyFunction));
Adding tweens, intervals, and other sequences to an existing sequence
Append(tweenComponent)
Adds the given Tweener/Sequence to the right of the sequence, and returns the new Sequence total time length (loops excluded).
- tweenComponent
- The tween component (a Tweener or another Sequence) to append. Tweeners can be directly created via HOTween.To, or passed as a reference.
Example
mySequence.Append(HOTween.To(myGameObject1.transform, 1, new TweenParms().Prop("position", new Vector3(10,20,30)).Prop("rotation", new Vector3(0,720,0)).Prop("localScale", new Vector3(4,4,4)).Ease(EaseType.easeOutBounce)));
AppendCallback(parameters...)
Adds the given callback to the right of the sequence. NOTE: these callbacks will work only with root Sequences, and not with nested ones.
AppendInterval(duration)
Appends an interval to the right of the sequence, and returns the new Sequence total time length (loops excluded).
- duration
- The seconds of duration of the interval.
Example
mySequence.AppendInterval(1);
Insert(atTime,tweenComponent)
Inserts the given Tweener/Sequence at the given time, and returns the new Sequence total time length (loops excluded).
- atTime
- The time position at which the Tweener/Sequence should be added. The total length of the sequence will be modified accordingly.
- tweenComponent
- The tween component (a Tweener or another Sequence) to insert. Tweeners can be directly created via HOTween.To, or passed as a reference.
Example
mySequence.Insert(1, HOTween.To(myGameObject1.transform, 1, new TweenParms().Prop("position", new Vector3(10,20,30)).Prop("rotation", new Vector3(0,720,0)).Prop("localScale", new Vector3(4,4,4)).Ease(EaseType.easeOutBounce)));
InsertCallback(atTime, parameters...)
Inserts the given callback at the given time. NOTE: these callbacks will work only with root Sequences, and not with nested ones.
Prepend(tweenComponent)
Adds the given Tweener/Sequence to the left of the sequence, moving all the existing sequence components to the right, and returns the new Sequence total time length (loops excluded).
- tweenComponent
- The tween component (a Tweener or another Sequence) to prepend. Tweeners can be directly created via HOTween.To, or passed as a reference.
Example
mySequence.Prepend(HOTween.To(myGameObject1.transform, 1, new TweenParms().Prop("position", new Vector3(10,20,30)).Prop("rotation", new Vector3(0,720,0)).Prop("localScale", new Vector3(4,4,4)).Ease(EaseType.easeOutBounce)));
PrependInterval
Prepends an interval to the left of the sequence, moving all the existing sequence components to the right, and returns the new Sequence total time length (loops excluded).
- duration
- The seconds of duration of the interval.
Example
mySequence.PrependInterval(1);
Methods
ApplyCallback()
Assigns the given type of callback to this Sequence, overwriting any existing callbacks of the same type (which could have been set via SequenceParms or another call to ApplyCallback).
Clear(parameters)
Clears the sequence and applies the new given SequenceParms, so it can be re-used.
Complete()
Completes the Sequence.
GoTo()
Sends the Sequence to the given time (taking also loops into account). If the time is bigger than the full Sequence duration, it goes to the end.
If the Sequence was playing, it will continue playing. If it was paused, it will stay paused.
GoToAndPlay()
Sends the Sequence to the given time (taking also loops into account) and plays it. If the time is bigger than the full Sequence duration, it goes to the end.
Kill()
Cleans and removes the Sequence from HOTween.
Pause()
Pauses the Sequence.
Play()
Plays the Sequence.
PlayBackwards()
Plays the tween in forward direction.
PlayForward()
Plays the Sequence in forward direction.
Restart()
Restarts the Sequence from the beginning.
Reverse()
Reverses the Sequence, (means the virtual playhead will move backwards if it was going forward, or forward if it was going backwards).
Rewind()
Rewinds and pauses the Sequence.
WaitForCompletion()
A Coroutine which can be used to wait for the completion (loops included) of the sequence.
C# Example
void SomeFunction() {
StartCoroutine( MyCoroutine() );
}
IEnumerator MyCoroutine() {
yield return StartCoroutine( mySequence.WaitForCompletion() );
...
}
WaitForRewind()
A Coroutine which can be used to wait for the rewinding of the sequence (see WaitForCompletion to understand how it works.
Properties (can be changed even while the tween is playing)
- autoKillOnComplete
- If set to false, doesn't clean nor remove this Sequence from HOTween's list when it is completed.
- enabled
- If set to false, this Sequence won't be updated, and any use of animation methods (Play/Pause/Rewind/etc.) will be ignored (both if called directly via the Sequence instance, than if using HOTween.Play/Pause/Rewind/etc.).
- id
- Eventual ID of this Sequence (more than one Tweener/Sequence can share the same ID, thus allowing for grouped operations).
- intId
- Eventual int ID of this Sequence.
- loops
- Number of times this Sequence will run (-1 means infinite loops).
- loopType
- The LoopType used by this Sequence.
- position
- Gets and sets the time position of this Sequence (loops are included when not infinite).
- timeScale
- Time scale used by this Sequence.
Read-Only Properties
- completedLoops
- Number of loops that have been completed.
- duration
- Duration of this Sequence, loops excluded.
- elapsed
- Elapsed time within the current loop. Note that elapsed will be equal to duration only when all the loops are completed, otherwise each time a loop is completed, completedLoops is augmented by 1 and elapsed is reset to 0.
- fullDuration
- Full duration of this Sequence, loops included (when not infinite).
- fullElapsed
- Full elapsed time including loops.
- hasStarted
- Returns true after this Sequence was started for the first time.
- isComplete
- Returns true while this Sequence is complete.
- isEmpty
- Returns true if this Sequence contains no other Tweeners or Sequences.
- isLoopingBack
- Returns true when this Sequence is in the "going back" part of a Yoyo loop.
- isPaused
- Returns true if this Sequence is currently paused.
- isReversed
- Returns true if this Sequence is set to go backwards (due to a call to Reverse()).
- updateType
- The UpdateType used by this Sequence.
Sequence Parameters (SequenceParms)
Sequence parameters are represented by a SequenceParms object, who is created via method chaining, and works exactly as TweenParms. Method chaining simply consists of a series of functions joined together, like Func1().Func2().Func3().
To create a Sequence's parms, you start with a new SequenceParms(), and then chain the desired methods, which represent different options. Code assist will help you see which parameters are available, and to quickly auto-complete them.
All parameters are specific to the current Sequence and optional. For all the parameters that you don't chain, default values will be used.
Example
new SequenceParms().Id("sequence_01").Loops(2).OnComplete(MyOnCompleteFunction);
The available parameters are:
Optional parameters
AutoKill(autoKill)
Setting this parameter to false will prevent the Sequence to be automatically destroyed when it is complete. To destroy it, you will need to directly Kill it.
Example
mySequence = new Sequence( new SequenceParms().AutoKill(false).Id("sequence_01").Loops(2).OnComplete(MyFunction) );
Id(idName)
Sets the eventual ID for this Sequence.
The same ID can be applied to multiple Tweeners and Sequences, thus allowing for grouped operations (all HOTween static controls can filter operations per ID).
- idName
- The ID to set.
Example
mySequence = new Sequence( new SequenceParms().Id("sequence_01").Loops(2).OnComplete(MyFunction) );
IntId(id)
Sets the eventual numerical (int) ID for this Sequence.
Works exactly as Id(), but since it uses ints instead than strings it's way faster (thus is the best option if you need to squeeze maximum performance, like on mobile phones).
The same ID can be applied to multiple Tweeners and Sequences, thus allowing for grouped operations (all HOTween static controls can filter operations per ID).
- id
- The ID to set.
Example
mySequence = new Sequence( new SequenceParms().IntId(10).Loops(2).OnComplete(MyFunction) );
KeepEnabled/KeepDisabled(behaviour/behaviour[]/gameObject/gameObject[])
Keeps the given target disabled or enabled (in case of Behaviours - activated or deactivated in case of GameObjects) while the tween is running. When the tween is complete/rewinded/paused, the target is reset to the exact state it had before the tween started playing. You can pass a single target, or an array of targets.
Example
HOTween.To(myObject.transform, 2, new TweenParms().Prop("position",new Vector3(1,2,4)).KeepDisabled(myComponent).Loops(2).OnComplete(myOnCompleteFunction));
Loops(loops, loopType)
Sets the type and total number of loops that will be played.
- loops
- The number of loops to execute. 1 means a single run with no loops, -1 or Mathf.Infinity indicate infinite loops.
- loopType
- The LoopType to use (check LoopType in the API to see the available options in detail: Restart, Yoyo, YoyoInverse).
Example
mySequence = new Sequence( new SequenceParms().Loops(2,LoopType.Yoyo).AutoKill(false).Id("sequence_01").OnComplete(MyFunction) );
TimeScale(timeScale)
Sets the time scale to use.
- timeScale
- The time scale to use.
Example
mySequence = new Sequence( new SequenceParms().TimeScale(2).AutoKill(false).Id("sequence_01").OnComplete(MyFunction) );
UpdateType(updateType)
The UpdateType to use (check the UpdateType enum in the API for available types).
- updateType
- The UpdateType to use (Update, LateUpdate, FixedUpdate, TimeScaleIndependentUpdate).
Example
mySequence = new Sequence( new SequenceParms().UpdateType(UpdateType.FixedUpdate).AutoKill(false).Id("sequence_01").OnComplete(MyFunction) );
Callback parameters
OnComplete(callbackFunction, additionalParameters)
A function to call when the Sequence is fully completed, all loops included.
- callbackFunction
- The function to call. It must return void and either have no parameters, or a single parameter of type TweenEvent (which will contain a tween property, with a reference to this Sequence, and a parms array, with all the additional parameters you might've given it).
- additionalParameters
- A comma separated list of eventual additional parameters.
Callback function without parameters
mySequence = new Sequence( new SequenceParms().Loops(2).OnComplete(MyFunction) );
private void MyFunction() {}
private function MyFunction() {}
Callback function with parameters
mySequence = new Sequence( new SequenceParms().Loops(2).OnComplete(MyFunction,1,2,3) );
private void MyFunction( TweenEvent data ) {
Debug.Log( data.tween );
if ( data.parms != null ) {
Debug.Log( data.parms[0] );
}
}
private function MyFunction( data:TweenEvent ) {
Debug.Log( data.tween );
if ( data.parms != null ) {
Debug.Log( data.parms[0] );
}
}
OnComplete(sendMessageTarget, methodName, value)
A Unity SendMessage to execute when the Sequence is fully completed, all loops included.
- sendMessageTarget
- The GameObject to target for SendMessage.
- methodName
- The name of the method that will be called on every MonoBehaviour in the target GameObject.
- value
- An optional value to pass to SendMessage.
OnComplete with SendMessage behaviour
mySequence = new Sequence(new SequenceParms().Loops(2).OnComplete(myGameObject, "methodName", someValue));
OnPause(callbackFunction, additionalParameters)
A function to call when the Sequence is paused.
- callbackFunction
- The function to call. It must return void and either have no parameters, or a single parameter of type TweenEvent (which will contain a tween property, with a reference to this Sequence, and a parms array, with all the additional parameters you might've given it).
- additionalParameters
- A comma separated list of eventual additional parameters.
Callback function without parameters
mySequence = new Sequence( new SequenceParms().Loops(2).OnPause(MyFunction) );
private void MyFunction() {}
private function MyFunction() {}
Callback function with parameters
mySequence = new Sequence( new SequenceParms().Loops(2).OnPause(MyFunction,1,2,3) );
private void MyFunction( TweenEvent data ) {
Debug.Log( data.tween );
if ( data.parms != null ) {
Debug.Log( data.parms[0] );
}
}
private function MyFunction( data:TweenEvent ) {
Debug.Log( data.tween );
if ( data.parms != null ) {
Debug.Log( data.parms[0] );
}
}
OnPlay(callbackFunction, additionalParameters)
A function to call when the Sequence starts playing, or it is resumed from a paused state.
- callbackFunction
- The function to call. It must return void and either have no parameters, or a single parameter of type TweenEvent (which will contain a tween property, with a reference to this Sequence, and a parms array, with all the additional parameters you might've given it).
- additionalParameters
- A comma separated list of eventual additional parameters.
Callback function without parameters
mySequence = new Sequence( new SequenceParms().Loops(2).OnPlay(MyFunction) );
private void MyFunction() {}
private function MyFunction() {}
Callback function with parameters
mySequence = new Sequence( new SequenceParms().Loops(2).OnPlay(MyFunction,1,2,3) );
private void MyFunction( TweenEvent data ) {
Debug.Log( data.tween );
if ( data.parms != null ) {
Debug.Log( data.parms[0] );
}
}
private function MyFunction( data:TweenEvent ) {
Debug.Log( data.tween );
if ( data.parms != null ) {
Debug.Log( data.parms[0] );
}
}
OnRewinded(callbackFunction, additionalParameters)
A function to call when the Sequence is fully rewinded, loops included (either because Rewind was called, or because it finished playing backwards).
- callbackFunction
- The function to call. It must return void and either have no parameters, or a single parameter of type TweenEvent (which will contain a tween property, with a reference to this Sequence, and a parms array, with all the additional parameters you might've given it).
- additionalParameters
- A comma separated list of eventual additional parameters.
Callback function without parameters
mySequence = new Sequence( new SequenceParms().Loops(2).OnRewinded(MyFunction) );
private void MyFunction() {}
private function MyFunction() {}
Callback function with parameters
mySequence = new Sequence( new SequenceParms().Loops(2).OnRewinded(MyFunction,1,2,3) );
private void MyFunction( TweenEvent data ) {
Debug.Log( data.tween );
if ( data.parms != null ) {
Debug.Log( data.parms[0] );
}
}
private function MyFunction( data:TweenEvent ) {
Debug.Log( data.tween );
if ( data.parms != null ) {
Debug.Log( data.parms[0] );
}
}
OnStart(callbackFunction, additionalParameters)
A function to call the first time the Sequence is started.
- callbackFunction
- The function to call. It must return void and either have no parameters, or a single parameter of type TweenEvent (which will contain a tween property, with a reference to this Sequence, and a parms array, with all the additional parameters you might've given it).
- additionalParameters
- A comma separated list of eventual additional parameters.
Callback function without parameters
mySequence = new Sequence( new SequenceParms().Loops(2).OnStart(MyFunction) );
private void MyFunction() {}
private function MyFunction() {}
Callback function with parameters
mySequence = new Sequence( new SequenceParms().Loops(2).OnStart(MyFunction,1,2,3) );
private void MyFunction( TweenEvent data ) {
Debug.Log( data.tween );
if ( data.parms != null ) {
Debug.Log( data.parms[0] );
}
}
private function MyFunction( data:TweenEvent ) {
Debug.Log( data.tween );
if ( data.parms != null ) {
Debug.Log( data.parms[0] );
}
}
OnStepComplete(callbackFunction, additionalParameters)
A function to call each time a single loop is completed.
- callbackFunction
- The function to call. It must return void and either have no parameters, or a single parameter of type TweenEvent (which will contain a tween property, with a reference to this Sequence, and a parms array, with all the additional parameters you might've given it).
- additionalParameters
- A comma separated list of eventual additional parameters.
Callback function without parameters
mySequence = new Sequence( new SequenceParms().Loops(2).OnStepComplete(MyFunction) );
private void MyFunction() {}
private function MyFunction() {}
Callback function with parameters
mySequence = new Sequence( new SequenceParms().Loops(2).OnStepComplete(MyFunction,1,2,3) );
private void MyFunction( TweenEvent data ) {
Debug.Log( data.tween );
if ( data.parms != null ) {
Debug.Log( data.parms[0] );
}
}
private function MyFunction( data:TweenEvent ) {
Debug.Log( data.tween );
if ( data.parms != null ) {
Debug.Log( data.parms[0] );
}
}
OnUpdate(callbackFunction, additionalParameters)
A function to call each time the Sequence is updated.
- callbackFunction
- The function to call. It must return void and either have no parameters, or a single parameter of type TweenEvent (which will contain a tween property, with a reference to this Sequence, and a parms array, with all the additional parameters you might've given it).
- additionalParameters
- A comma separated list of eventual additional parameters.
Callback function without parameters
mySequence = new Sequence( new SequenceParms().Loops(2).OnUpdate(MyFunction) );
private void MyFunction() {}
private function MyFunction() {}
Callback function with parameters
mySequence = new Sequence( new SequenceParms().Loops(2).OnUpdate(MyFunction,1,2,3) );
private void MyFunction( TweenEvent data ) {
Debug.Log( data.tween );
if ( data.parms != null ) {
Debug.Log( data.parms[0] );
}
}
private function MyFunction( data:TweenEvent ) {
Debug.Log( data.tween );
if ( data.parms != null ) {
Debug.Log( data.parms[0] );
}
}
TweenVar
TweenVar is a special object you can create to setup a "virtual" tween, which will not be automatically tweened nor updated, but will just set and return a value when you call myTweenVar.Update(elapsed, isRelative).
To see its details, check HOTween API.
Example: creating and storing a TweenVar
TweenVar myTV = new TweenVar(10,20,1);
Debug.Log(myTV.Update(0.5f));
Example: getting an immediate value without storing a TweenVar
Debug.Log(new TweenVar(10,20,1).Update(0.5f));
Methods
Update(elapsedTime, isRelative)
Sets and returns the value at which the TweenVar would be after the given time.
If isRelative is set to true, the given time is added to the previous elapsed time, otherwise it is considered as absolute.
Example
TweenVar myTV = new TweenVar(10,20,1);
Debug.Log(myTV.Update(0.5f));
Debug.Log(myTV.Update(0.5f));
Debug.Log(myTV.Update(0.5f,true));
Properties
- duration
- Virtual duration (you could also set it to 1 or 100 to treat is as a percentage).
- startVal
- Start value (you can consider it as a FROM).
- endVal
- End value (you can consider it as a TO).
- easeType
- The EaseType to use for time calculations.
Read-Only Properties
- value
- The current value of this TweenVar (set when you create the TweenVar, and changed each time you call Update).
- elapsed
- The current elapsed time (changed each time you call Update).