LightTween Documentation
Introduction
LightTween is a lightweight animation library for Unity, inspired by DOTween and iTween. It allows you to easily animate different properties of objects in your Unity projects with a fluid and intuitive API.
LightTween has been designed to be simple to use while offering optimal performance, perfect for projects that require animations without the overhead of larger libraries.
Features
- Position animation (moving objects)
- Rotation animation
- Scale animation
- Color animation
- Multiple easing functions for natural movements
- Fluid API with method chaining
- Callbacks to react to the end of animations
Getting Started
Installation
To add LightTween to your Unity project:
- Download the LightTween package from the Advanced Unity HUB package manager
- Import the package into your Unity project
- Add
using LightTween;
at the top of your scripts to access the features
Basic Usage
Position Animation
Move an object to a specific position:
LightTween.Move(gameObject, new Vector3(3, 2, 0), 2.0f)
.SetEase(EaseType.EaseOutBounce)
.OnComplete(() => Debug.Log("Animation completed!"));
This command moves the object to position (3, 2, 0) in 2 seconds, with a bounce effect at the end, and displays a message when the animation is complete.
Scale Animation
Modify an object's size:
LightTween.Scale(gameObject, new Vector3(2, 2, 2), 1.0f)
.SetEase(EaseType.EaseInQuad);
This command scales the object to (2, 2, 2) in 1 second, with a gradual acceleration.
Rotation Animation
Rotate an object:
LightTween.Rotate(gameObject, new Vector3(0, 360, 0), 1.5f)
.SetEase(EaseType.EaseInOutBack);
This command rotates the object 360 degrees around the Y axis in 1.5 seconds, with an overshoot effect at the beginning and end.
Color Animation
Change an object's color:
LightTween.Color(gameObject.GetComponent<Renderer>(), Color.red, 3.0f)
.SetEase(EaseType.EaseInOutCubic);
This command changes the object's material color to red over a duration of 3 seconds, with a smooth transition.
Chaining Animations
LightTween makes it easy to chain multiple animations to create complex sequences:
LightTween.Scale(sphere, new Vector3(2, 2, 2), 1.0f)
.SetEase(EaseType.EaseInQuad)
.OnComplete(() => {
LightTween.Scale(sphere, Vector3.one, 1.0f)
.SetEase(EaseType.EaseOutQuad);
});
This example first enlarges a sphere, then returns it to its original size once the first animation is complete.
Easing Types
LightTween offers different easing functions to make your animations more natural:
EaseType.Linear
- Constant speedEaseType.EaseInQuad
- Gradual acceleration (quadratic)EaseType.EaseOutQuad
- Gradual deceleration (quadratic)EaseType.EaseInOutQuad
- Acceleration then deceleration (quadratic)EaseType.EaseInCubic
- Gradual acceleration (cubic)EaseType.EaseOutCubic
- Gradual deceleration (cubic)EaseType.EaseInOutCubic
- Acceleration then deceleration (cubic)EaseType.EaseInBack
- Slight reverse motion before startingEaseType.EaseOutBack
- Overshoot at the endEaseType.EaseInOutBack
- Reverse motion at start and overshoot at the end- And several others...
Callbacks and Events
LightTween allows you to add callbacks to react to certain events:
OnComplete()
- Called when the animation is completeOnStart()
- Called when the animation startsOnUpdate()
- Called with each animation update
LightTween.Move(gameObject, target, 2.0f)
.OnStart(() => Debug.Log("Animation started!"))
.OnUpdate(() => UpdateUI())
.OnComplete(() => PlaySound());
Complete Example
Here's a complete example showing different uses of LightTween:
using UnityEngine;
public class LightTweenExample : MonoBehaviour
{
public GameObject cube;
public GameObject sphere;
public GameObject cylinder;
void Start()
{
// Basic usage example
LightTween.Move(cube, new Vector3(3, 2, 0), 2.0f)
.SetEase(EaseType.EaseOutBounce)
.OnComplete(() => Debug.Log("Cube movement completed!"));
// Chain multiple animations with OnComplete
LightTween.Scale(sphere, new Vector3(2, 2, 2), 1.0f)
.SetEase(EaseType.EaseInQuad)
.OnComplete(() => {
LightTween.Scale(sphere, Vector3.one, 1.0f)
.SetEase(EaseType.EaseOutQuad);
});
// Color animation
if (cylinder.GetComponent<Renderer>() != null)
{
LightTween.Color(cylinder.GetComponent<Renderer>(), Color.red, 3.0f)
.SetEase(EaseType.EaseInOutCubic);
}
}
void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
// Animate rotation when space key is pressed
LightTween.Rotate(cube, new Vector3(0, 360, 0), 1.5f)
.SetEase(EaseType.EaseInOutBack);
}
if (Input.GetKeyDown(KeyCode.R))
{
// Reset objects to their initial position
cube.transform.position = Vector3.zero;
sphere.transform.localScale = Vector3.one;
if (cylinder.GetComponent<Renderer>() != null)
{
cylinder.GetComponent<Renderer>().material.color = Color.white;
}
}
}
}
Tips and Best Practices
- Use appropriate animation durations: 0.2-0.5s for quick animations, 1-3s for longer animations
- Choose easing types that match the expected physical behavior (bounce, elasticity, etc.)
- Avoid launching too many simultaneous animations on the same object
- Use callbacks to create complex animation sequences
- For repeating animations, consider using coroutines in combination with LightTween
LightTween is optimized for user interface animations and light visual effects. For complex physics-based animations, consider using Unity's animation system or other solutions.