59 行
無檔案結尾符
1.4 KiB
C#
59 行
無檔案結尾符
1.4 KiB
C#
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.Serialization;
|
|
using UnityEngine.UI;
|
|
|
|
public class UIImageAnimator : MonoBehaviour
|
|
{
|
|
public Sprite[] m_SpriteArray;
|
|
|
|
public Sprite[] m_AltSpriteArray;
|
|
|
|
private bool toggleAlt = false;
|
|
|
|
private float normalSpeed = .05f;
|
|
private float altSpeed = .025f;
|
|
private float m_Speed ;
|
|
private int m_IndexSprite;
|
|
private Image m_Image;
|
|
Coroutine m_CorotineAnim;
|
|
public void Start()
|
|
{
|
|
m_Speed = normalSpeed;
|
|
m_Image = gameObject.GetComponent<Image>();
|
|
StartCoroutine(PlayAnimUI());
|
|
}
|
|
|
|
public void SetIndex(int index)
|
|
{
|
|
m_IndexSprite = index;
|
|
}
|
|
|
|
public void SetAlt(bool alt)
|
|
{
|
|
toggleAlt = alt;
|
|
m_Speed = alt ? altSpeed : normalSpeed;
|
|
Debug.Log(m_Speed);
|
|
}
|
|
|
|
public int GetSpriteIndex()
|
|
{
|
|
return m_IndexSprite;
|
|
}
|
|
|
|
IEnumerator PlayAnimUI()
|
|
{
|
|
yield return new WaitForSeconds(m_Speed);
|
|
if (m_IndexSprite >= m_SpriteArray.Length)
|
|
{
|
|
m_IndexSprite = 0;
|
|
}
|
|
|
|
m_Image.sprite = toggleAlt ? m_AltSpriteArray[m_IndexSprite] : m_SpriteArray[m_IndexSprite];
|
|
|
|
m_IndexSprite += 1;
|
|
m_CorotineAnim = StartCoroutine(PlayAnimUI());
|
|
}
|
|
} |