Unity下载文件一(www协程下载)

下载功能,是大多数游戏或者软件都需具备的一个基础模块,但是很多人却没有机会去写这个完整功能。

那么我就分享下我写该功能时的随笔整理

本文只说www协程下载,http的同步和异步下载放到下篇

这个简单:

WWW wwwServer = new WWW("http://192.168.1.1:8080/Files/ab.assetBundle");
yield return wwwServer;
if (string.IsNullOrEmpty(wwwServer.error))
{
      AssetBundle ab= wwwServer.assetBundle;//获取AB包资源
    } //如果是mp3,就用music相关的接收, //如果是图片,就是Texture相关的接收。
//如果是文本,则可以为string str = wwwServer.text; //同时你也可以采取流的方式来获取并存储, //以下在www下载用流的方式存储我并没有实际测试过,其他均是亲自测试。 Stream outStream; FileInfo fi= new FileInfo(Application.persistentDataPath + "/file.xx"); if (!fi.Exists ) { outStream = fi.Create(); outStream.Write(wwwServer.bytes, 0, wwwServer.bytes.Length); } outStream.Close();

  下一篇:http同步下载和http异步下载

 

posted @ 2016-04-09 22:13  威少小二orz  阅读(1993)  评论(0编辑  收藏  举报