好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

Unity3D实现批量下载图片功能

本文实例为大家分享了unity3d实现批量下载图片功能的具体代码,供大家参考,具体内容如下

下一篇文章试试用线程下载

代码如下

?

using system.io;

using unityengine;

using system.net;

using system.collections;

 

public class test : monobehaviour {

 

   private string [] _urls= new string [10];

   private string [] _localpath = new string [10];

 

  // use this for initialization

  void start ()

   {

     for ( int i = 0; i < _urls.length; i++)

     {

       //所有图片的下载地址

       _urls[i] = "http://192.168.1.41:8080/test/picture/" + (i + 1).tostring() + ".jpg" ;

       //所有图片的保存路径

       _localpath[i] = application.datapath + "/resources/" + (i + 1).tostring() + ".jpg" ;

      

     }

  }

 

   // update is called once per frame

   void update()

   {

 

  }

 

   void ongui()

   {

     if (gui.button( new rect(0, 0, 100, 30), "下载所有图片" ))

     {

       download();

     }

     //判断文件是否已下载

     for ( int i = 0; i < _urls.length; i++)

     {

       if (file.exists(_localpath[i]))

       {

         gui.button( new rect(0, 30 * i+30, 50, 30), (i + 1).tostring());

       }

     }

 

    

   }

 

   //下载所有图片

   private void download()

   {

     for ( int i = 0; i < _urls.length; i++)

     {

       downloadallimages(_urls[i], _localpath[i]);

     }

   }

 

 

   void downloadallimages( string url, string localpath)

   {

     webclient web = new webclient();

     web.downloadfile(url, localpath);

     //以下代码下载完成后执行

   }

}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。

原文链接:https://blog.csdn.net/AWNUXCVBN/article/details/9243151

dy("nrwz");

查看更多关于Unity3D实现批量下载图片功能的详细内容...

  阅读:50次