当前位置: 移动技术网 > IT编程>开发语言>c# > Unity3D实现批量下载图片功能

Unity3D实现批量下载图片功能

2019年07月18日  | 移动技术网IT编程  | 我要评论

本文实例为大家分享了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);
    //以下代码下载完成后执行
  }
}

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网