本文實例為大家分享了unity3d實現批量下載圖片功能的具體代碼,供大家參考,具體內容如下
下一篇文章試試用線程下載
代碼如下
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
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