Ultra Lightweight Tweening Engine for Unity (Uween)
Uween is a simple tween library for Unity.
Features
Simple & Lightweight
Uween is super simple. Core system (Tween.cs
) is about 100 lines code. Simple is powerful.
Easy to use
// Go to x:100 in 1 second.
TweenX.Add(gameObject, 1f, 100f);
That's all.
Fluent syntax
// 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);
Unity friendly
Uween's design is completely focusing on Unity. It works as a simple Unity component and follows a Unity execution flow.
Setup
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.cs
Uween/Scripts/TweenC.cs
Uween/Scripts/TweenCA.cs
Uween/Scripts/TweenFillAmount.cs
Examples
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.
Quick help
Import
Add using Uween;
in your script.
using UnityEngine;
using System.Collections;
using Uween;
Starting tween
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.
Tween classes
- 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
.rx
is a euler angle.TweenRY.Add(g, d, float ry)
- Rotate Y to valuery
.ry
is a euler angle.TweenRZ.Add(g, d, float rz)
- Rotate Z to valuerz
.rz
is 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 valuesx
andy
.TweenXZ.Add(g, d, Vector2 xz)
- Move XZ to valuexz
.TweenXZ.Add(g, d, float x, float z)
- Move XZ to valuesx
andz
.TweenYZ.Add(g, d, Vector2 yz)
- Move YZ to valueyz
.TweenYZ.Add(g, d, float y, float z)
- Move YZ to valuesy
andz
.- Scale 2 values
TweenSXY.Add(g, d, Vector2 xy)
- Scale XY to valuexy
.TweenSXY.Add(g, d, float x, float y)
- Scale XY to valuesx
andy
.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 valuesx
andz
.TweenSYZ.Add(g, d, Vector2 yz)
- Scale YZ to valueyz
.TweenSYZ.Add(g, d, float y, float z)
- Scale XY to valuesy
andz
.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 valuesx
andy
.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 valuesx
andz
.TweenRYZ.Add(g, d, Vector2 yz)
- Rotate YZ to valueyz
.TweenRYZ.Add(g, d, float y, float z)
- Rotate YZ to valuesy
andz
.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
,y
andz
.- 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
,y
andz
.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
,y
andz
.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
,g
andb
.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
,b
anda
.TweenFillAmount.Add(g, d, float to)
- ChangeImage#fillAmount
to valueto
.
Note: g
is GameObject, d
is duration.
Fluent syntax
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);
Easings
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 amplitudea
of the sine wave and the periodp
of the sine wave..EaseInOutElasticWith(float a, float p)
- With the the amplitudea
of the sine wave and the periodp
of the sine wave..EaseOutElasticWith(float a, float p)
- With the the amplitudea
of the sine wave and the periodp
of the sine wave..EaseOutInElasticWith(float a, float p)
- With the the amplitudea
of the sine wave and the periodp
of 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()
Delay
You can insert a delay time before starting tween.
.Delay(float)
- Set a delay time (sec).
Callback
You can set to call method you like when tween completed.
.Then(f)
- Set a complete callback.f
is a no arg void method.
Initial value
You can set a initial value. It will be apply immediately to GameObject (before delay).
.From(v)
- Set a initial value tov
.
Relative value
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
To current value
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);
Pause/Resume
You can pause/resume active tweens in a GameObject.
g.PauseTweens()
- Pause active tweens ing
.g.PauseTweens<T>()
- Pause active tweens of typeT
ing
.g.ResumeTweens()
- Resume paused tweens ing
.g.ResumeTweens<T>()
- Resume paused tweens of typeT
ing
.
TweenNull
TweenNull will not tween any value. You can use this class for wait, delayed callback, etc...
// Callback after 3sec.
TweenNull(g, 3f).Then(callback)
License
Copyright 2014 Oink Games, Inc. and other contributors.
Code licensed under the MIT License: http://opensource.org/licenses/MIT