Ejemplo n.º 1
0
        IEnumerator DownloadAsync(string downloadUrl, string saveFilePath, delegateOnDownFinsh callback)
        {
            UnityWebRequest www = UnityWebRequest.Get(downloadUrl);

            yield return(www.Send());

            if (www.isError)
            {
                www.Dispose();
                yield return(new WaitForSeconds(0.3f));

                www = UnityWebRequest.Get(downloadUrl);
                yield return(www.Send());
            }
            if (www.isError)
            {
                www.Dispose();
                yield return(new WaitForSeconds(0.3f));

                www = UnityWebRequest.Get(downloadUrl);
                yield return(www.Send());

                Debug.Log(www.error);
            }
            if (www.isDone)
            {
                if (!www.isError)
                {
                    byte[] results = www.downloadHandler.data;
                    SaveSoundFile(saveFilePath, results);
                    yield return(new WaitForEndOfFrame());

                    if (callback != null)
                    {
                        callback(0, "");
                    }
                }
                else
                {
                    if (callback != null)
                    {
                        callback(1, www.error);
                    }
                }
                www.Dispose();
            }
        }
Ejemplo n.º 2
0
 //下载文件
 public void DownloadFile(string downloadUrl, string saveFilePath, delegateOnDownFinsh callback)
 {
     StartCoroutine(DownloadAsync(downloadUrl, saveFilePath, callback));
 }