gindemit / unity-rlottie

Unity library that plays Lottie Animation to Texture2D
MIT License
147 stars 23 forks source link

Switch out lottie files at runtime #19

Open gardyna opened 8 months ago

gardyna commented 8 months ago

I have a situation where I have to choose between several lottie files at runtime to display. I don't think having several gameobjects in the scene and selecting between those is elegant. Would it be possible to add a "SetLottie" function to the AnimatedImage object?

gindemit commented 6 months ago

Hello @gardyna, thanks a lot for the suggestion! Sorry for the long reply, I was busy on other projects. I will implement the API for this feature in the next versions.

JonFaull commented 3 months ago

I have a situation where I have to choose between several lottie files at runtime to display. I don't think having several gameobjects in the scene and selecting between those is elegant. Would it be possible to add a "SetLottie" function to the AnimatedImage object?

This would be very useful.

gindemit commented 3 months ago

Hey @gardyna and @JonFaull I just reviewed again the existing implementation. The AnimatedImage monobeh does has a public method LoadFromAnimationJson() You can use it on the same AnimatedImage instance to load new animations. It will automatically unload the already loaded animation. No need to dispose it explicitly. You need to provide at least 3 parameters: string json, uint width, uint height

You can see an example how to use this method on the dev branch in the repo_root/unity/RLottieUnity/Assets/LottiePlugin/Tests/Runtime/src/AnimatedImageTests.cs file