Uween is a simple tween library for Unity.
Uween is super simple. Core system (Tween.cs) is about 100 lines code. Simple is powerful.
// Go to x:100 in 1 second.
TweenX.Add(gameObject, 1f, 100f);That's all.
// Go to x:100 in 1 second with in-out-sine easing and 5 sec delay.
// Then do a next motion.
TweenX.Add(gameObject, 1f, 100f).EaseInOutSine().Delay(0.5f).Then(next_motion);Uween's design is completely focusing on Unity. It works as a simple Unity component and follows a Unity execution flow.
Simply copy a Uween directory to your Unity project.
Uween - Example directory is not needed.
If you don't use uGUI (requires Unity >= 4.6), delete the following files:
Uween/Scripts/TweenA.csUween/Scripts/TweenC.csUween/Scripts/TweenCA.csUween/Scripts/TweenFillAmount.cs
Open a Uween - Example/Scenes/Example.unity scene.
All code is written in Uween - Example/Scripts/Example.cs.
- This example uses uGUI so you requires Unity version >= 4.6.
Add using Uween; in your script.
using UnityEngine;
using System.Collections;
using Uween;Call a tween class's Add method.
TweenX.Add(g, 0.3f, 120f);
TweenY.Add(g, 0.5f, 240f);At least Add method has two parameters:
- GameObject - Tweening target.
- float - Tweening duration (sec).
and has more extra parameters depending on tween classes. For example, TweenX has a destination x value as 3rd parameter.
- Move 1 value
TweenX.Add(g, d, float x)- Move X to valuex.TweenY.Add(g, d, float y)- Move Y to valuey.TweenZ.Add(g, d, float z)- Move Z to valuez.- Scale 1 value
TweenSX.Add(g, d, float sx)- Scale X to valuesx.TweenSY.Add(g, d, float sy)- Scale Y to valuesy.TweenSZ.Add(g, d, float sz)- Scale Z to valuesz.- Rotate 1 value
TweenRX.Add(g, d, float rx)- Rotate X to valuerx.rxis a euler angle.TweenRY.Add(g, d, float ry)- Rotate Y to valuery.ryis a euler angle.TweenRZ.Add(g, d, float rz)- Rotate Z to valuerz.rzis a euler angle.- Move 2 values
TweenXY.Add(g, d, Vector2 xy)- Move XY to valuexy.TweenXY.Add(g, d, float x, float y)- Move XY to valuesxandy.TweenXZ.Add(g, d, Vector2 xz)- Move XZ to valuexz.TweenXZ.Add(g, d, float x, float z)- Move XZ to valuesxandz.TweenYZ.Add(g, d, Vector2 yz)- Move YZ to valueyz.TweenYZ.Add(g, d, float y, float z)- Move YZ to valuesyandz.- Scale 2 values
TweenSXY.Add(g, d, Vector2 xy)- Scale XY to valuexy.TweenSXY.Add(g, d, float x, float y)- Scale XY to valuesxandy.TweenSXY.Add(g, d, float v)- Scale XY to valuev.TweenSXZ.Add(g, d, Vector2 xz)- Scale XZ to valuexz.TweenSXZ.Add(g, d, float v)- Scale XZ to valuev.TweenSXZ.Add(g, d, float x, float z)- Scale XZ to valuesxandz.TweenSYZ.Add(g, d, Vector2 yz)- Scale YZ to valueyz.TweenSYZ.Add(g, d, float y, float z)- Scale XY to valuesyandz.TweenSYZ.Add(g, d, float v)- Scale YZ to valuev.- Rotate 2 values
TweenRXY.Add(g, d, Vector2 xy)- Rotate XY to valuexy.TweenRXY.Add(g, d, float x, float y)- Rotate XY to valuesxandy.TweenRXY.Add(g, d, float v)- Rotate XY to valuev.TweenRXZ.Add(g, d, Vector2 xz)- Rotate XZ to valuexz.TweenRXZ.Add(g, d, float v)- Rotate XZ to valuev.TweenRXZ.Add(g, d, float x, float z)- Rotate XZ to valuesxandz.TweenRYZ.Add(g, d, Vector2 yz)- Rotate YZ to valueyz.TweenRYZ.Add(g, d, float y, float z)- Rotate YZ to valuesyandz.TweenRYZ.Add(g, d, float v)- Rotate YZ to valuev.- Move 3 values
TweenXYZ.Add(g, d, Vector3 xyz)- Move XYZ to valuexyz.TweenXYZ.Add(g, d, float x, float y, float z)- Move XYZ to valuesx,yandz.- Scale 3 values
TweenSXYZ.Add(g, d, Vector2 xyz)- Scale XYZ to valuexyz.TweenSXYZ.Add(g, d, float x, float y, float z)- Scale XYZ to valuesx,yandz.TweenSXYZ.Add(g, d, float v)- Scale XYZ to valuev.- Rotate 3 values
TweenRXYZ.Add(g, d, Vector2 xyz)- Rotate XYZ to valuexy.TweenRXYZ.Add(g, d, float x, float y, float z)- Rotate XYZ to valuesx,yandz.TweenRXYZ.Add(g, d, float v)- Rotate XYZ to valuev.- Alias for 2D
TweenP- Same asTweenXY.TweenS- Same asTweenSXY.TweenR- Same asTweenRZ.- Alias for 3D
TweenP3- Same asTweenXYZ.TweenS3- Same asTweenSXYZ.TweenR3- Same asTweenRXYZ.- uGUI
TweenA.Add(g, d, float a)- Change Alpha to valuea.TweenC.Add(g, d, Color c)- Change Color to valuec(Alpha is ignored).TweenC.Add(g, d, Vector3 c)- Change Color to valuec.TweenC.Add(g, d, float r, float g, float b)- Change Color to valuer,gandb.TweenCA.Add(g, d, Color c)- Change Color to valuec(Alpha is not ignored).TweenCA.Add(g, d, Vector4 c)- Change Color to valuec.TweenCA.Add(g, d, float r, float g, float b, float a)- Change Color to valuer,g,banda.TweenFillAmount.Add(g, d, float to)- ChangeImage#fillAmountto valueto.
Note: g is GameObject, d is duration.
All the following feature can be called with fluent syntax. (Fluent syntax is also known as method chain)
Like:
TweenX.Add(gameObject, 1f, 100f).EaseInOutSine().Delay(0.5f).Then(next_motion);You can use all of Robert Penner's easings:
- Linear
- It's default.
- Back
.EaseInBack().EaseInOutBack().EaseOutBack().EaseOutInBack().EaseInBackWith(float s)- With the amount of overshoots..EaseInOutBackWith(float s)- With the amount of overshoots..EaseOutBackWith(float s)- With the amount of overshoots..EaseOutInBackWith(float s)- With the amount of overshoots.- Bounce
.EaseInBounce().EaseInOutBounce().EaseOutBounce().EaseOutInBounce()- Circular
.EaseInCircular().EaseInOutCircular().EaseOutCircular().EaseOutInCircular().EaseInCirc()- Alias.EaseInOutCirc()- Alias.EaseOutCirc()- Alias.EaseOutInCirc()- Alias- Cubic
.EaseInCubic().EaseInOutCubic().EaseOutCubic().EaseOutInCubic()- Elastic
.EaseInElastic().EaseInOutElastic().EaseOutElastic().EaseOutInElastic().EaseInElasticWith(float a, float p)- With the the amplitudeaof the sine wave and the periodpof the sine wave..EaseInOutElasticWith(float a, float p)- With the the amplitudeaof the sine wave and the periodpof the sine wave..EaseOutElasticWith(float a, float p)- With the the amplitudeaof the sine wave and the periodpof the sine wave..EaseOutInElasticWith(float a, float p)- With the the amplitudeaof the sine wave and the periodpof the sine wave.- Exponential
.EaseInExponential().EaseInOutExponential().EaseOutExponential().EaseOutInExponential().EaseInExpo()- Alias.EaseInOutExpo()- Alias.EaseOutExpo()- Alias.EaseOutInExpo()- Alias- Quadratic
.EaseInQuadratic().EaseInOutQuadratic().EaseOutQuadratic().EaseOutInQuadratic().EaseInQuad()- Alias.EaseInOutQuad()- Alias.EaseOutQuad()- Alias.EaseOutInQuad()- Alias- Quartic
.EaseInQuartic().EaseInOutQuartic().EaseOutQuartic().EaseOutInQuartic().EaseInQuart()- Alias.EaseInOutQuart()- Alias.EaseOutQuart()- Alias.EaseOutInQuart()- Alias- Quintic
.EaseInQuintic().EaseInOutQuintic().EaseOutQuintic().EaseOutInQuintic().EaseInQuint()- Alias.EaseInOutQuint()- Alias.EaseOutQuint()- Alias.EaseOutInQuint()- Alias- Sine
.EaseInSine().EaseInOutSine().EaseOutSine().EaseOutInSine()
You can insert a delay time before starting tween.
.Delay(float)- Set a delay time (sec).
You can set to call method you like when tween completed.
.Then(f)- Set a complete callback.fis a no arg void method.
You can set a initial value. It will be apply immediately to GameObject (before delay).
.From(v)- Set a initial value tov.
You can set a destination or initial value relative from current value.
.Relative()- Set a destination value to a value relative from current value.FromRelative(v)- Set a initial value to current value +v
If you don't set a destination value, it will automatically set as a current value.
// From 100px to current position
TweenX.Add(gameObject, 1f).From(100f);You can pause/resume active tweens in a GameObject.
g.PauseTweens()- Pause active tweens ing.g.PauseTweens<T>()- Pause active tweens of typeTing.g.ResumeTweens()- Resume paused tweens ing.g.ResumeTweens<T>()- Resume paused tweens of typeTing.
TweenNull will not tween any value. You can use this class for wait, delayed callback, etc...
// Callback after 3sec.
TweenNull(g, 3f).Then(callback)Copyright 2014 Oink Games, Inc. and other contributors.
Code licensed under the MIT License: http://opensource.org/licenses/MIT