代码
using System.IO;
using System.Net;
using UnityEngine;
using System.Threading;
using System.Collections;
public class ThreadTest : 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";
MyThread mt = new MyThread(_urls[i], _localPath[i]);
Thread thread = new Thread(new ThreadStart(mt.DownLoadImage));
thread.Start();
}
}
// Update is called once per frame
void Update ()
{
}
void OnGUI()
{
}
}
public class MyThread
{
public string _url;
public string _filePath;
public MyThread(string url, string filePath)
{
_url = url;
_filePath = filePath;
}
public void DownLoadImage()
{
WebClient web = new WebClient();
web.DownloadFile(_url, _filePath);
}
}