当前位置:   article > 正文

【Unity3D】Unity工程加载Gif图片发布为WEBGL版本_unity webgl播放gif

unity webgl播放gif

文章目录


前言

在unity工程中实现组态图,其中有些组态图(平面图)中的设备需要将运行状态动态展示(也可也做成动画,但是对动画的编辑还在学习中就没有实施)。百度了一些文章和资料,主要是思路:将Gif动画中的序列帧转换成Texture2D列表,然后通过通过控制Texture2D列表的索引进行播放和启停。查询的资料以System.Drawing.Image进行加载的居多,但是发布成WEBGL后不显示,后来查询到使用UniGif第三方脚本进行加载,可以显示出来。


提示:以下是本篇文章正文内容,下面案例可供参考

一、System.Drawing.dll如何引入?

来源:D:\Program Files\Unity\Editor\Data\MonoBleedingEdge\lib\mono\unityjit文件夹下的System.Drawing.dll。

也就是Unity安装目录下的Unity\Editor\Data\MonoBleedingEdge\lib\mono\unityjit;其他文件夹也会存在System.Drawing.dll,但是引入后会有错误。

放置到:工程下的\Assets\内;具体的路径可根据个人喜好进行设置;

二、使用步骤

1.代码示例

代码如下(示例):具体可参考Unity项目中加载Gif图片的Demo工程

其中主要代码:

  1.  void Start()
  2.     {
  3.         // 如果控件上不设置路径,则不需要先加载gif
  4.         if (string.IsNullOrEmpty(runImagePath)) return;
  5.         string runImageFullPath = Application.streamingAssetsPath + "/" + runImagePath;
  6.         Debug.Log("Start runImageFullPath ="+ runImageFullPath);
  7.         SetRunGif(runImageFullPath);
  8.        
  9.     }
  10.   private void SetRunGif(string path)
  11.     {
  12.         if (string.IsNullOrEmpty(path)) return;
  13.         Debug.LogFormat("SetRunGif path = {0},File.Exists = {1}",path, File.Exists(path));
  14.         StartCoroutine(LoadWordPic(path));
  15.     }
  16.   IEnumerator LoadWordPic(string path)
  17.     {
  18.         string url = "";
  19.         if (Application.isEditor)
  20.         {
  21.             url = "file:///" + path;
  22.         }
  23.         else
  24.         {
  25.             url = path;
  26.         }
  27.         Debug.Log("LoadWordPic url ="+ url);
  28.         UnityWebRequest request = UnityWebRequest.Get(url);
  29.         yield return request.SendWebRequest();
  30.         if (!(request.isHttpError || request.isNetworkError))
  31.         {
  32.             byte[] bytes = request.downloadHandler.data;
  33.             System.IO.MemoryStream ms = new System.IO.MemoryStream(bytes);
  34.             var image = System.Drawing.Image.FromStream(ms,false);
  35.             _runTex2DList = GifImageUtils.GifToTexture2D(image);
  36.             _framCount = _runTex2DList.Count;
  37.             Debug.Log("SetRunGif _framCount =" + _framCount);
  38.         }
  39.       
  40.     }

2.读入数据

代码如下(示例):

data = pd.read_csv( 'https://labfile.oss.aliyuncs.com/courses/1283/adult.data.csv') print(data.head()) 

该处使用的url网络请求的数据。


总结

提示:这里对文章进行总结:
例如:以上就是今天要讲的内容,本文仅仅简单介绍了pandas的使用,而pandas提供了大量能使我们快速便捷地处理数据的函数和方法。

System.Drawing.Image加载GIF图片

System.Drawing.dll来源

Player Setting

发布WEBGL失败

UniGif加载GIF图片

UniGif核心代码来源

使用核心代码

发布webgl成功

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/菜鸟追梦旅行/article/detail/91995
推荐阅读
相关标签
  

闽ICP备14008679号