unity-序列帧动画
来源:互联网 发布:系统表的定义sql语句 编辑:程序博客网 时间:2024/06/06 12:43
序列帧动画作为一种2D游戏中经常采用的动画技术,使用unity也是很好实现的。只要在场景中新建一个Quad,然后在添加上如下脚本即可:
using UnityEngine;using System.Collections;public class AnimateTest : MonoBehaviour { private int startIndex = 266; private int lastIndex = 331; private string path = "dance/dance_"; private int currentIndex; Texture frameAniTex; public float framesPerSecond; // Use this for initialization void Start () { currentIndex = startIndex; } void Update() { AnimaAlways(); } // Update is called once per frame void AnimaAlways() { int nowIndex = (int)(Time.time * framesPerSecond) % (lastIndex - startIndex+1); if (currentIndex != startIndex + nowIndex) { currentIndex = startIndex + nowIndex; frameAniTex = (Texture)Resources.Load(path + currentIndex.ToString("D5")); if (frameAniTex == null) { Debug.Log("error:currentIndex:" + currentIndex); } GetComponent<Renderer>().material.mainTexture = frameAniTex; } } }
注意:需要在quad上添加一个材质,后将材质的shader设置为standard,且设置rendering mode为cutout,这样主要是为了实现背景的透明,大致样子如下图,
demo下载地址如下:
http://download.csdn.net/detail/xunni_5241/9620979
还有就是序列帧动画比较占用内存,在实际项目使用过程中,主要找到合适的实际进行内存资源的释放,还有就是unity经过自己的图片处理后会将图片大小放大很多,我们最终采用压缩型的assetbundle来进行资源的载入,在播放完成一个动画后将资源进行释放来缓解内存,要不在移动平台(安卓、ios)就会出现内存报警崩溃的问题。
本人文章纯属个人总结,且某些demo在项目采用前可能来自互联网,最终实验验证后实际项目中采用,若发现来自贵方,谅解;若发现,纰漏错误妄指正。
0 0
- Unity 序列帧动画
- unity-序列帧动画
- 【Unity】Unity制作序列帧动画
- Unity Shader UV动画(序列帧动画)
- unity中制作序列帧动画
- unity序列帧小动画实现笔记
- Unity中实现UI序列帧动画
- unity序列帧动画的粒子特效
- unity UV 序列动画 shader
- Unity-基于NGUI下的序列帧动画代码实现
- Unity中基于NGUI插件制作序列帧动画
- Unity 动画帧
- Unity Sharder帧动画
- Unity 代码帧动画
- Unity帧动画
- 自己写的UnitY实用小工具或脚本——读取Texture序列帧动画
- 制作动画序列帧
- 序列帧动画
- 关于VS2013序列号
- Vasiliy's Multiset
- Android 属性动画使用(一)
- Linux中安装jdk
- vue组件简单介绍与使用
- unity-序列帧动画
- MyBatis学习总结(二)表的关联以及动态SQL
- Android--ListView中item中实现跑马灯效果
- swift 8. 函数
- Codeforces 595 B. Pasha and Phone【数学】
- Swift常用正则表达式
- Linux中安装tomcat
- 树 2017.2.15
- 在Windows上玩TensorFlow(一)——安装Docker