using System.Collections; using UnityEngine; namespace EnergyBarToolkit { public class RepeatedUGUILastIconAnimator : MonoBehaviour { public float animationTime = 2f; public float scaleFrom = 1f; public float scaleTo = 2f; public float alphaFrom = 1f; public float alphaTo; private MadiTween.EaseType scaleEaseType = MadiTween.EaseType.easeOutCubic; private RepeatedRendererUGUI barRenderer; public MadiTween.EaseType easeType { get { return scaleEaseType; } set { scaleEaseType = value; } } private void Start() { barRenderer = GetComponent(); StartCoroutine(Anim()); } public IEnumerator Anim() { while (base.enabled) { int visibleCount = barRenderer.GetVisibleIconCount(); if (visibleCount > 0) { Image2 image = barRenderer.GetIconImage(visibleCount - 1); Image2 clone = Object.Instantiate(image); clone.name = "anim icon"; clone.transform.SetParent(image.transform.parent, false); clone.transform.position = image.transform.position; clone.transform.SetSiblingIndex(image.transform.GetSiblingIndex()); float startTime = Time.time; float endTime = Time.time + animationTime; MadiTween.EasingFunction easingFunction = MadiTween.GetEasingFunction(scaleEaseType); while (Time.time < endTime) { float f = (Time.time - startTime) / animationTime; float scale = easingFunction(scaleFrom, scaleTo, f); clone.transform.localScale = new Vector3(scale, scale, scale); clone.color = new Color(a: easingFunction(alphaFrom, alphaTo, f), r: clone.color.r, g: clone.color.g, b: clone.color.b); yield return null; } Object.Destroy(clone.gameObject); } else { yield return new WaitForSeconds(animationTime); } } } } }