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.

AnimatedButton Class

The AnimatedButton class is part of the LottiePlugin.UI namespace. It extends the Selectable class and implements the IPointerClickHandler and ISubmitHandler interfaces. It's used for creating interactive buttons with Lottie animations.

Structures

State

[System.Serializable]
public struct State
{
    public string Name;
    public int FrameNumber;
}

This is a serializable structure that represents a state of the button. Each state has a Name and FrameNumber indicating the frame in which this state starts in the Lottie animation.

Events

ButtonClickedEvent

[System.Serializable]
public class ButtonClickedEvent : UnityEngine.Events.UnityEvent<int, State> { }

This class is a type of UnityEvent that takes an integer and State struct as parameters. It's invoked when the button is pressed.

Properties

OnClick

public ButtonClickedEvent OnClick => _onClick;

This is the event that is triggered when the button is clicked.

Transform

public Transform Transform { get; private set; }

This property represents the Transform component of the game object.

AnimationJson

internal TextAsset AnimationJson => _animationJson;

This property represents the JSON data of the Lottie animation.

RawImage

internal RawImage RawImage => _rawImage;

This property represents the RawImage component on the game object.

States

internal State[] States => _states;

This property represents an array of State structures, each representing a different state of the button.

Serializable Fields

_animationJson

[SerializeField] private TextAsset _animationJson;

This field represents the JSON data of the Lottie animation.

_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.

_rawImage

[SerializeField] private RawImage _rawImage;

This field represents the RawImage component on the game object.

_ignoreInputWhileAnimating

[SerializeField] private bool _ignoreInputWhileAnimating = true;

This field, when set to true, makes the button ignore click events while it's animating. The default value is true.

_states

[SerializeField] private State[] _states;

This field is an array of State structures, each representing a different state of the button.

_onClick

[SerializeField] private ButtonClickedEvent _onClick = new ButtonClickedEvent();

This field represents the ButtonClickedEvent to be invoked when the button is clicked