From 1c9a77aacf7f335887b6a74bf315566b447da058 Mon Sep 17 00:00:00 2001 From: gilzoide Date: Thu, 1 Feb 2024 20:24:07 -0300 Subject: [PATCH] Use async update in AnimatedImage and AnimatedButton This avoids running the internal rendering from rlottie in Unity's main thread. --- .../Assets/LottiePlugin/Runtime/src/UI/AnimatedButton.cs | 5 ++++- .../Assets/LottiePlugin/Runtime/src/UI/AnimatedImage.cs | 8 +++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/unity/RLottieUnity/Assets/LottiePlugin/Runtime/src/UI/AnimatedButton.cs b/unity/RLottieUnity/Assets/LottiePlugin/Runtime/src/UI/AnimatedButton.cs index bda2e1f..b56e77c 100644 --- a/unity/RLottieUnity/Assets/LottiePlugin/Runtime/src/UI/AnimatedButton.cs +++ b/unity/RLottieUnity/Assets/LottiePlugin/Runtime/src/UI/AnimatedButton.cs @@ -143,8 +143,11 @@ private IEnumerator AnimateToNextState() _lottieAnimation.CurrentFrame <= _lottieAnimation.TotalFramesCount) || _lottieAnimation.CurrentFrame < nextState.FrameNumber) { + yield return null; + _lottieAnimation.UpdateAsync(_animationSpeed); + yield return _waitForEndOfFrame; - _lottieAnimation.Update(_animationSpeed); + _lottieAnimation.DrawOneFrameAsyncGetResult(); if (_lottieAnimation.CurrentFrame == 0) { _updateAnimationCoroutine = null; diff --git a/unity/RLottieUnity/Assets/LottiePlugin/Runtime/src/UI/AnimatedImage.cs b/unity/RLottieUnity/Assets/LottiePlugin/Runtime/src/UI/AnimatedImage.cs index 5bd1533..190c905 100644 --- a/unity/RLottieUnity/Assets/LottiePlugin/Runtime/src/UI/AnimatedImage.cs +++ b/unity/RLottieUnity/Assets/LottiePlugin/Runtime/src/UI/AnimatedImage.cs @@ -116,10 +116,16 @@ private IEnumerator RenderLottieAnimationCoroutine() { while (true) { + yield return null; + if (_lottieAnimation != null) + { + _lottieAnimation.UpdateAsync(_animationSpeed); + } + yield return _waitForEndOfFrame; if (_lottieAnimation != null) { - _lottieAnimation.Update(_animationSpeed); + _lottieAnimation.DrawOneFrameAsyncGetResult(); if (!_loop && _lottieAnimation.CurrentFrame == _lottieAnimation.TotalFramesCount - 1) { Stop();