[UGUI]帧动画
ImageFrameAnimation.cs
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI; [RequireComponent(typeof(Image))]
public class ImageFrameAnimation : MonoBehaviour { private Image image;
private int nowFrame = ;
private float timer = ; private List<Sprite> spriteList;
private bool isPlay = false;
private bool isForward = true;
private bool isLoop = true;
private float interval = 0.1f; void Update ()
{
if (!isPlay || (spriteList.Count == ))
{
return;
} timer += Time.deltaTime;
if (timer > interval)
{
timer = ;
if (isForward)
{
nowFrame++;
}
else
{
nowFrame--;
} if (nowFrame >= spriteList.Count)
{
if (isLoop)
{
nowFrame = ;
}
else
{
isPlay = false;
return;
}
}
else if(nowFrame < )
{
if (isLoop)
{
nowFrame = spriteList.Count - ;
}
else
{
isPlay = false;
return;
}
} UpdateSprite();
}
} private void UpdateSprite()
{
UpdateSprite(nowFrame);
} private void UpdateSprite(int index)
{
image.sprite = spriteList[index];
} public void Init(Sprite[] spriteArray, bool isPlay = true, bool isForward = true, bool isLoop = true, float interval = 0.1f)
{
List<Sprite> spriteList = new List<Sprite>();
spriteList.AddRange(spriteArray);
Init(spriteList, isPlay, isForward, isLoop, interval);
} public void Init(List<Sprite> spriteList, bool isPlay = true, bool isForward = true, bool isLoop = true, float interval = 0.1f)
{
this.spriteList = spriteList;
this.isPlay = isPlay;
this.isForward = isForward;
this.isLoop = isLoop;
this.interval = interval; if (image == null)
{
image = GetComponent<Image>();
}
if (isForward)
{
nowFrame = ;
}
else
{
nowFrame = spriteList.Count - ;
}
timer = ; UpdateSprite();
} public void Play()
{
isPlay = true;
isForward = true;
} public void PlayReverse()
{
isPlay = true;
isForward = false;
} public void Pause()
{
isPlay = false;
}
}
测试:
using UnityEngine;
using System.Collections.Generic;
using UnityEngine.UI; public class TestImageFrameAnimation : MonoBehaviour { public Image image;
private ImageFrameAnimation ani; void Start ()
{
ani = image.gameObject.AddComponent<ImageFrameAnimation>();
Sprite[] sprites = Resources.LoadAll<Sprite>("Num");
ani.Init(sprites, true, true, true, );
} private void Update()
{
if (Input.GetKeyDown(KeyCode.Q))
{
ani.Pause();
} if (Input.GetKeyDown(KeyCode.W))
{
ani.PlayReverse();
}
}
}
效果:

[UGUI]帧动画的更多相关文章
- UGUI 帧动画插件
最近在开发一款功夫猫游戏,本来使用Unity Sprite制作,但是发现Sprite对各种分辨率不支持. 看着游戏很简单就使用UGUI制作,在中途发现有很多帧动画播放,使用了Animation调整使用 ...
- 深入理解CSS3 Animation 帧动画
CSS3我在5年之前就有用了,包括公司项目都一直在很前沿的技术. 最近在写慕课网的七夕主题,用了大量的CSS3动画,但是真的沉淀下来仔细的去深入CSS3动画的各个属性发现还是很深的,这里就写下关于帧动 ...
- Android动画效果之Frame Animation(逐帧动画)
前言: 上一篇介绍了Android的Tween Animation(补间动画) Android动画效果之Tween Animation(补间动画),今天来总结下Android的另外一种动画Frame ...
- android 帧动画,补间动画,属性动画的简单总结
帧动画——FrameAnimation 将一系列图片有序播放,形成动画的效果.其本质是一个Drawable,是一系列图片的集合,本身可以当做一个图片一样使用 在Drawable文件夹下,创建ani ...
- android 帧动画
首先在res/drawable/name1.xml/定义一组图片集合: <?xml version="1.0" encoding="utf-8"?> ...
- 3d图片切换(css3帧动画)
效果带抖动翻转隐藏,使用帧动画 <!DOCTYPE html> <html> <head> <meta charset="UTF-8"&g ...
- CoolPlist 帧动画自动生成工具
工具英文名称:CoolPlist作者: 陈前帆 thinkingMan | sonny 邮箱: 625936034@qq.com | chenqianfan1@163.com电话: 136704713 ...
- uwp 图片切换动画 使用帧动画
上一篇博客使用了Timer来实现图片的切换,@lindexi_gd讨论了一下性能,我本人其实对性能这一方面不太熟,但我觉得还是有必要考虑一下,那么今天我们使用帧动画开实现以下 新建项目,添加一个But ...
- android帧动画,移动位置,缩放,改变透明度等动画讲解
1.苦逼的需求又来了,需要实现一些动画效果,第一个想到的是播放gif图片,但是这样会占包的资源,并且清晰度不高,于是想着程序实现,自己用帧动画+缩放+移动+透明度 实现了一些想要的效果,这里跟大家分享 ...
随机推荐
- Tensorflow安装环境更新
本博文是对前面两篇tensorflow的博文的一个继续,对环境的更新. 基于tensorflow的MNIST手写识别 安装tensorflow,那叫一个坑啊 主要出发点: 上述两篇博文的程序运行的环境 ...
- centos下redis的导出和导入(限set命令)
#!/bin/bash REDIS_HOST=127.0.0.1 REDIS_PORT=6379 REDIS_DB=10 KEYNAME="*" KEYFILE=redis_key ...
- ubuntu 阿里云 常出问题 运维工作日志
一.2015-8.26(数据库 error—28) tmp文件临时数据写入不了----解决办法 1.查看临时文件 ls -l 找到了 2.由此可以查看得出来tmp文件有的权限是有的 3.查看tmp 存 ...
- 黄聪:php7配置php.ini使其支持<? ?>
<? ?>这种写在php配置文件里php.ini法叫short_tags,默认是不打开的,也就是,在默认配置的php里,这样写法不被认为是php脚本的,除非设置 short_open_ta ...
- 【redis】之centos6.x安装redis3.0.x
centos6.9_x86_64 1.下载redis安装包 http://download.redis.io/releases/redis-3.2.9.tar.gz 2.解压 编译到指定得目录 mak ...
- ssh config配置
使用ssh config文件可以简化ssh连接输入参数,直接从config读取 (1)建立config文件 config文件位置在~/.ssh/config 如果不存在,可以创建一个 (2)confi ...
- 数据库SQL语言学习--上机练习3(插入 更新 删除)
上机练习3 . 将一个新学生记录(学号::姓名:陈冬:性别:男:所在系:信息系:年龄:20岁)插入到Student表中: ALTER TABLE Student ,); UPDATE Student ...
- keystone认证服务
实验操作平台:OpenStack单节点操作 一.相关概念 1.认证(authentication) 认证是确认允许一个用户访问的进程 2.证书(credentials) 用于确认用户身份的数据 3.令 ...
- 桥接、仅主机和NAT图解
- [UE4]在AI Character中要获得AI的controller,需要使用Get AIController