Unity添加GIF动画
2014-07-20 16:06
316 查看
国外网站上看到的一篇帖子
http://wiki.unity3d.com/index.php/AnimatedGifDrawer
它使用“图像”和“图形”类的系统。图的命名空间,所以需要“system.Drawing.dll“要导入的文件/添加到项目中。
使用前准备:
1)复制”"System.Drawing.dll"
file in the "C:\Program Files (x86)\Unity\Editor\Data\Mono\lib\mono\2.0"文件到"Assets" 文件夹下面。
2)创建一个新的脚本命名为“animatedgifdrawer”,与下面的内容。
3)将这个脚本场景中的任何对象。
4)更改脚本”loadinggifpath”字段,你的GIF文件的路径。(这可以从根项目文件夹是相对的也可以是绝对的。
下面给出C#代码:
http://wiki.unity3d.com/index.php/AnimatedGifDrawer
它使用“图像”和“图形”类的系统。图的命名空间,所以需要“system.Drawing.dll“要导入的文件/添加到项目中。
使用前准备:
1)复制”"System.Drawing.dll"
file in the "C:\Program Files (x86)\Unity\Editor\Data\Mono\lib\mono\2.0"文件到"Assets" 文件夹下面。
2)创建一个新的脚本命名为“animatedgifdrawer”,与下面的内容。
3)将这个脚本场景中的任何对象。
4)更改脚本”loadinggifpath”字段,你的GIF文件的路径。(这可以从根项目文件夹是相对的也可以是绝对的。
下面给出C#代码:
using System.Collections.Generic; using System.Drawing; using System.Drawing.Imaging; using UnityEngine; public class AnimatedGifDrawer : MonoBehaviour { public string loadingGifPath; public float speed = 1; public Vector2 drawPosition; List<Texture2D> gifFrames = new List<Texture2D>(); void Awake() { var gifImage = Image.FromFile(loadingGifPath); var dimension = new FrameDimension(gifImage.FrameDimensionsList[0]); int frameCount = gifImage.GetFrameCount(dimension); for (int i = 0; i < frameCount; i++) { gifImage.SelectActiveFrame(dimension, i); var frame = new Bitmap(gifImage.Width, gifImage.Height); System.Drawing.Graphics.FromImage(frame).DrawImage(gifImage, Point.Empty); var frameTexture = new Texture2D(frame.Width, frame.Height); for (int x = 0; x < frame.Width; x++) for (int y = 0; y < frame.Height; y++) { System.Drawing.Color sourceColor = frame.GetPixel(x, y); frameTexture.SetPixel(frame.Width - 1 - x, y, new Color32(sourceColor.R, sourceColor.G, sourceColor.B, sourceColor.A)); // for some reason, x is flipped } frameTexture.Apply(); gifFrames.Add(frameTexture); } } void OnGUI() { GUI.DrawTexture(new Rect(drawPosition.x, drawPosition.y, gifFrames[0].width, gifFrames[0].height), gifFrames[(int)(Time.frameCount * speed) % gifFrames.Count]); } }
相关文章推荐
- latex beamer 添加gif动画
- AS3添加gif动画以及设置大小
- 评论添加表情gif小动画js特效
- Unity动画系统 动态添加动画事件
- 改善了性能的gif动画添加水印
- Unity/Animation -- 添加动画事件(Animation Events)
- .net c# gif动画如何添加图片水印
- .net c# gif动画如何添加图片水印实现思路及代码
- Unity游戏开发——自动为动画剪辑添加事件 之 最后几帧的事件不能被调用的问题
- [Unity动画]给人物模型添加简单的动画
- android中gif动画的解析-添加表情
- Unity之添加动画,冷却效果
- Unity动画系统-给人物添加动画
- 为gif动画添加水印-有具体实现[2008-02-15日更新]
- unity代码添加动画,并传参数
- unity gif动画按钮js和c#脚本
- Unity动画帧添加事件
- unity 关于添加自动导航NavMeshAgent后模型动画的抖动问题
- 给gif动画添加水印的初步实现
- Unity之一天一个技术点(十五)---给unity3d的老版动画中,添加事件的方法