为了优化unity序列帧动画调用,此处不使用unity自带animation调用动画,自己编写了一个类似animation动画的可以插入事件的序列帧动画脚本,可以是image或者是spriterender
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;
/****************************************************
作者:cg
功能:图片序列帧动画
*****************************************************/
public class SpriteImgAnm : MonoBehaviour
{
[Header("自动播放")]
public bool PlayAwake;
[Header("循环播放")]
public bool Loop = false;
[Tooltip("序列帧的图片")]
[SerializeField]
private Sprite[] m_frames;
[Header("播放速度")]
public float Speed = 0.05f;
[Header("插入事件位置")]
public int ActionFrame = -1;
[SerializeField]
private UnityEvent m_frameEvent;
private SpriteRenderer _container;
private Image _containerImg;
private int _ticked;
private float _time;
private bool _doAnim;
public bool DoAnim { get { return _doAnim; } set { _doAnim = value; } }
private void Awake()
{
_container = GetComponent<Spri

本文介绍了一种在Unity中自定义实现序列帧动画的方法,通过编写类似Unity Animation的脚本,可以实现在Image或SpriteRenderer上的动画播放,并支持事件插入,提供自动播放、循环播放等特性。
最低0.47元/天 解锁文章
3743

被折叠的 条评论
为什么被折叠?



