Welcome to the Unity Lottie Animation plugin! This Unity library enables you to play Lottie animations as Texture2D in your Unity projects. It's a powerful and easy-to-use solution that leverages Samsung's rlottie library to bring smooth Lottie animations to your games and applications.
Lottie loads and renders animations and vectors exported in the bodymovin JSON format. Bodymovin JSON can be created and exported from After Effects with bodymovin, Sketch with Lottie Sketch Export, and from Haiku.
For the first time, designers can create and ship beautiful animations without an engineer painstakingly recreating it by hand. Since the animation is backed by JSON they are extremely small in size but can be large in complexity!
To install the Unity Lottie Animation to Texture2D plugin using the Unity Package Manager, follow these steps:
Window
> Package Manager
.+
button in the top-left corner and select Add package from git URL...
.Add
:
https://github.com/gindemit/unity-rlottie.git?path=/unity/RLottieUnity/Assets/LottiePlugin/#0.2.2
The LottiePlugin.UI
namespace includes a AnimatedImage
class which allows you to use Lottie animations as RawImage
in your Unity game.
Here are the steps to use the AnimatedImage
class in your Unity project:
Import the Class: First, make sure the AnimatedImage
class is included in your Unity project.
Create an RawImage: In your Unity scene, create a new RawImage UGUI game object and attach the AnimatedImage
script to it.
Assign Parameters: In the AnimatedImage
component, you will see several parameters:
TextAsset
representing the JSON data for your Lottie animation. You can drag and drop it from your Assets folder.Fill these in according to your needs.
Play/Stop the Animation: You can use the Play()
and Stop()
methods to control the animation at runtime. You can call these from any other script.
// Get a reference to the AnimatedImage
AnimatedImage animatedImage = gameObject.GetComponent<AnimatedImage>();
// Play the animation
animatedImage.Play();
// Stop the animation
animatedImage.Stop();
And that's it! You are now able to use Lottie animations in your Unity projects using the AnimatedImage
class.
Here's an example of how to use the AnimatedImage
class:
// Attach this script to a GameObject with AnimatedImage component
using UnityEngine;
using LottiePlugin.UI;
public class AnimationController : MonoBehaviour
{
private AnimatedImage animatedImage;
private void Awake()
{
animatedImage = GetComponent<AnimatedImage>();
}
private void Start()
{
animatedImage.Play(); // Start the animation
}
private void OnDisable()
{
animatedImage.Stop(); // Stop the animation
}
}
This script, when attached to the same GameObject as the AnimatedImage
component, will start the animation when the game starts and stop it when the GameObject is disabled.
Check out the 'Scene UI' Sample in Unity Package manager.
Window
> Package Manager
.https://github.com/gindemit/unity-rlottie/assets/5675979/3301d00e-fc9e-49c0-bc7f-7408f1f72ce4
If you encounter any issues or have questions, please create an issue on GitHub.
This plugin is built on top of Samsung's rlottie library, which is used internally for Lottie animation rendering.
This project is licensed under the MIT License. See the LICENSE file for details.