在NGUI里面经常用到UISprite打包图片,在这个图集上的图片可以制作序列帧动画,代码如下
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class SequenceFrame : MonoBehaviour
{
[Range(0, 0.3f)]
public float m_TickTime;
float m_AllTime = 0.0f;
List<UISpriteData> m_SpriteDatas;
string[] mStrSpriteName;
uint SpritePos = 0;
UISprite mSpriteScript;
// Use this for initialization
void Start()
{
m_SpriteDatas = transform.GetComponent<UISprite>().atlas.spriteList;
mSpriteScript = transform.GetComponent<UISprite>();
mStrSpriteName = new string[m_SpriteDatas.Count];
for (int i = 0; i != m_SpriteDatas.Count; ++i)
{
mStrSpriteName[i] = m_SpriteDatas[i].name;
}
}
// Update is called once per frame
void Update()
{
if (Time.deltaTime > m_AllTime)
{
m_AllTime += m_TickTime;
}
else
{
++SpritePos;
if (SpritePos >= m_SpriteDatas.Count)
SpritePos = 0;
mSpriteScript.spriteName = mStrSpriteName[SpritePos];
m_AllTime -= Time.deltaTime;
}
}
}