private string url = "http://....";
WWW www;
public Image progressImg;
private void Update()
{
if (www != null)
{
if (!www.isDone)
{
progressImg.fillAmount = www.progress;//www.progress下载进度
}
else
{
progressImg.fillAmount = 1;
}
}
}
/// <summary>
/// 下载文件
/// </summary>
/// <param name="url">下载地址</param>
/// <param name="file">保存路径</param>
/// <returns></returns>
IEnumerator DownLoadTexture(string url, string file)
{
www = new WWW(url);
Texture2D tempImage;
yield return www;
if (www.isDone && www.error == null)
{
tempImage = www.texture;
if (tempImage != null)
{
byte[] data = tempImage.EncodeToJPG();
File.WriteAllBytes(file, data);
isChange = true;
}
}
}
网友评论