-
Notifications
You must be signed in to change notification settings - Fork 28
API Reference
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.
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.
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.
The following fields can be adjusted from the Unity Inspector:
[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.
[SerializeField] private RawImage _rawImage;
This field represents the RawImage
component on the game object. If not set, the component will be fetched at runtime.
[SerializeField] private float _animationSpeed = 1f;
This field represents the speed at which the animation is played. The default value is 1f
.
[SerializeField] private uint _textureWidth;
This field represents the width of the texture onto which the Lottie animation will be rendered.
[SerializeField] private uint _textureHeight;
This field represents the height of the texture onto which the Lottie animation will be rendered.
[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
.
[SerializeField] private bool _loop = true;
This field determines whether the animation should loop after it finishes playing. The default value is true
.
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.
public void Stop()
This method stops the Lottie animation and resets it to its initial state.
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.
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.
[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.
[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.
public ButtonClickedEvent OnClick => _onClick;
This is the event that is triggered when the button is clicked.
public Transform Transform { get; private set; }
This property represents the Transform
component of the game object.
internal TextAsset AnimationJson => _animationJson;
This property represents the JSON data of the Lottie animation.
internal RawImage RawImage => _rawImage;
This property represents the RawImage
component on the game object.
internal State[] States => _states;
This property represents an array of State
structures, each representing a different state of the button.
[SerializeField] private TextAsset _animationJson;
This field represents the JSON data of the Lottie animation.
[SerializeField] private float _animationSpeed = 1f;
This field represents the speed at which the animation is played. The default value is 1f
.
[SerializeField] private uint _textureWidth;
This field represents the width of the texture onto which the Lottie animation will be rendered.
[SerializeField] private uint _textureHeight;
This field represents the height of the texture onto which the Lottie animation will be rendered.
[SerializeField] private RawImage _rawImage;
This field represents the RawImage
component on the game object.
[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
.
[SerializeField] private State[] _states;
This field is an array of State
structures, each representing a different state of the button.
[SerializeField] private ButtonClickedEvent _onClick = new ButtonClickedEvent();
This field represents the ButtonClickedEvent
to be invoked when the button is clicked