92 lines
1.7 KiB
C#
92 lines
1.7 KiB
C#
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
|
||
|
||
[System.Serializable]
|
||
public class Scenesprites
|
||
{
|
||
public List<Sprite> mysprites = new List<Sprite>();
|
||
}
|
||
|
||
|
||
public class SceneSpriteAniationPro : MonoBehaviour
|
||
{
|
||
[Header("帧动画的图")]
|
||
public List<Mysprites> sprites;
|
||
[Header("播放动画的image")]
|
||
public SpriteRenderer image;
|
||
[Header("帧时间,单位毫秒,默认100")]
|
||
public float Aintime = 100f;
|
||
[Header("播放动画的编号")]
|
||
public int myspritesIndex = 0;
|
||
|
||
|
||
private int index = 0;
|
||
private Mysprites myspritesAni;
|
||
private bool _stop=false;
|
||
// Start is called before the first frame update
|
||
|
||
private void Awake()
|
||
{
|
||
SetAni(myspritesIndex);
|
||
}
|
||
void Start()
|
||
{
|
||
if (image == null)
|
||
{
|
||
Debug.LogError("image is null");
|
||
}
|
||
if (sprites.Count == 0)
|
||
{
|
||
Debug.LogError("sprites is not");
|
||
}
|
||
|
||
InvokeRepeating("ainstart", 0f, (Aintime / 1000));
|
||
}
|
||
|
||
|
||
public void SetAni(int Index)
|
||
{
|
||
//Debug.Log("SetAni"+ Index);
|
||
myspritesAni = sprites[Index];
|
||
index = 0;
|
||
}
|
||
|
||
void ainstart()
|
||
{
|
||
image.sprite = myspritesAni.mysprites[index];
|
||
index++;
|
||
if (index > myspritesAni.mysprites.Count - 1)
|
||
{
|
||
if (_stop)
|
||
{
|
||
return;
|
||
}
|
||
index = 0;
|
||
}
|
||
}
|
||
|
||
|
||
public void changeAni(bool TorF)
|
||
{
|
||
if (TorF)
|
||
{
|
||
_stop = false;
|
||
index = 0;
|
||
ainstart();
|
||
}
|
||
else
|
||
{
|
||
_stop = true;
|
||
}
|
||
}
|
||
|
||
private void OnDestroy()
|
||
{
|
||
sprites = null;
|
||
myspritesAni = null;
|
||
}
|
||
}
|