Skip to content

API Reference

Gindemit Konstantin edited this page May 12, 2023 · 2 revisions

API Reference

AnimatedImage Class

The AnimatedImage class is part of the LottiePlugin.UI namespace, designed to handle the playback of Lottie animations in Unity. This class is attached to a game object with a RawImage component. It provides methods to manage the animation, including starting, stopping, and rendering the Lottie animation.

Properties

Transform

public Transform Transform { get; }

This is the Transform component of the game object to which the AnimatedImage class is attached. This property is read-only.

RawImage

public RawImage RawImage { get => _rawImage; }

This property represents the RawImage component on the game object. The RawImage component is used to render the Lottie animation. This property is read-only.

Serializable Fields

The following fields can be adjusted from the Unity Inspector:

_animationJson

[SerializeField] private TextAsset _animationJson;

This field represents the JSON data of the Lottie animation. This should be a Unity TextAsset containing the animation's JSON data.

_rawImage

[SerializeField] private RawImage _rawImage;

This field represents the RawImage component on the game object. If not set, the component will be fetched at runtime.

_animationSpeed

[SerializeField] private float _animationSpeed = 1f;

This field represents the speed at which the animation is played. The default value is 1f.

_textureWidth

[SerializeField] private uint _textureWidth;

This field represents the width of the texture onto which the Lottie animation will be rendered.

_textureHeight

[SerializeField] private uint _textureHeight;

This field represents the height of the texture onto which the Lottie animation will be rendered.

_playOnAwake

[SerializeField] private bool _playOnAwake = true;

This field determines whether the Lottie animation will start playing as soon as the game object is enabled. The default value is true.

_loop

[SerializeField] private bool _loop = true;

This field determines whether the animation should loop after it finishes playing. The default value is true.

Methods

Play()

public void Play()

This method starts the Lottie animation. If the animation is already playing, it will first stop the existing animation before starting a new one.

Stop()

public void Stop()

This method stops the Lottie animation and resets it to its initial state.

Additional Notes

The Lottie animation is rendered after WaitForEndOfFrame. This means that the animation will be updated after all rendering and GUI events have been processed for the current frame. This ensures the animation update and render align with the Unity game loop.

Remember to always check your animation's JSON data and RawImage component before playing the animation. If these are not properly set, the AnimatedImage class will not be able to render the animation.

Clone this wiki locally