Exemplo n.º 1
0
        IEnumerator DownloadTextureAsync(string downloadUrl, string saveFilePath, delegateOnDownTextureFinsh callback)
        {
            WWW www = new WWW(downloadUrl);//UnityWebRequestTexture.GetTexture

            yield return(www);

            if (!string.IsNullOrEmpty(www.error))
            {
                www.Dispose();
                yield return(new WaitForSeconds(0.3f));

                www = new WWW(downloadUrl);
                yield return(www);
            }
            if (!string.IsNullOrEmpty(www.error))
            {
                www.Dispose();
                yield return(new WaitForSeconds(0.3f));

                www = new WWW(downloadUrl);
                yield return(www);
            }
            if (www.isDone)
            {
                if (string.IsNullOrEmpty(www.error))
                {
                    Texture2D tex2d = www.texture;
                    byte[]    bys   = tex2d.EncodeToPNG();//转换图片资源
                    SaveSoundFile(saveFilePath, bys);
                    yield return(new WaitForEndOfFrame());

                    if (callback != null)
                    {
                        callback(0, tex2d);
                    }
                }
                else
                {
                    if (callback != null)
                    {
                        callback(1, null);
                    }
                }
                www.Dispose();
            }
        }
Exemplo n.º 2
0
 //下载图片
 public void DownloadTexture(string downloadUrl, string saveFilePath, delegateOnDownTextureFinsh callback)
 {
     StartCoroutine(DownloadTextureAsync(downloadUrl, saveFilePath, callback));
 }