一、下载图片存放本地文件夹
public void DownloadFile()
{
WebClient webClient = new WebClient();
//将图片下载到文件夹
webClient.DownloadFileAsync(new System.Uri("https://www.baidu.com/img/pc_9c5c85e6b953f1d172e1ed6821618b91.png"), "G:\\桌面\\temp.png");
//显示下载进度
webClient.DownloadProgressChanged += WebClient_DownloadProgressChanged;
}
private void WebClient_DownloadProgressChanged(object sender, DownloadProgressChangedEventArgs e)
{
Debug.LogError(e.ProgressPercentage);
}
二、下载图片,存放Asset文件
public static async Task<byte[]> Loadbyte(string uri)=>await webClient.DownloadDataTaskAsync(uri);
var course = savaData.coursesTree.treeAgg[0].subCategories[0].courses[0];
course.coverbyte = await HttpTool.Loadbyte(course.cover);
Texture2D texture2D = new Texture2D(500, 500);
texture2D.LoadImage(course.coverbyte);
rawImage.texture = texture2D;
|