//-------------------------------------------------------- // [Author]: 第二世界 // [ Date ]: Sunday, December 10, 2017 //-------------------------------------------------------- using UnityEngine; using System.Collections; using UnityEngine.UI; using System; namespace Snxxz.UI { public class FrameEffect : MonoBehaviour { [SerializeField] Image m_Behaviour; [SerializeField] Sprite[] m_Sprites; float interval = 0.1f; int index = 0; float timer = 0f; float tempSumTime = 1f; [SerializeField] float onceTime = 1f; [SerializeField] float sumTime = 1f; [SerializeField] int aniIndex = 0; public bool loop = true; public event Action CompleteAct; private void OnEnable() { if (m_Sprites != null && m_Sprites.Length > 0) { interval = onceTime / m_Sprites.Length; index = 0; timer = 0f; tempSumTime = sumTime; } } private void LateUpdate() { timer += Time.deltaTime; tempSumTime -= Time.deltaTime; if(tempSumTime > 0) { if (timer > interval) { m_Behaviour.overrideSprite = m_Sprites[index]; index = (++index) % m_Sprites.Length; timer -= interval; } } else { if(loop) { tempSumTime = sumTime; } if(CompleteAct != null) { CompleteAct(aniIndex); } } } } }