//从服务器下载IMG资源
private IEnumerator DownLoadToLocalIMG(string url, string strname)
{
Debug.Log("从服务器下载资源img:" + strname);
//url编码
WWW.EscapeURL(url);
//访问url
WWW www = new WWW(url);
//url解码
WWW.UnEscapeURL(url);
//根据URL获取文件的名字。
string filename = url.Substring(url.LastIndexOf(‘/‘) + 1);
Debug.Log("filename++++++++++++++++++++++" + filename);
//等待下载
yield return www;
//Instantiate(www.assetBundle.mainAsset);
if (www.error == null)
{
Debug.Log(www);
//path为你想保存文件的路径。
FileStream fs = File.Create(Application.persistentDataPath + "/" + filename);
DownPath = Application.persistentDataPath + "/" + filename;
//把下载的数据写到文件
fs.Write(www.bytes, 0, www.bytes.Length);
fs.Close();
Debug.Log(filename + "下载完成");
////加载img
//rawImage.GetComponent<RawImage>().texture = LoadIMG(strname + ".jpg");
}
else
{
Debug.Log(www.error);
}
}