Пример #1
0
    IEnumerator DownloadFileIEnumerator(string url, string savePath, string method, RequestFileEvent action)
    {
        if (!File.Exists(savePath))
        {
            var request = new UnityWebRequest(url, method);
            request.downloadHandler = new DownloadHandlerFile(savePath);
            if (action.downloadProgress != null)
            {
                StartCoroutine(DownloadProgress(request, action.downloadProgress));
            }
            yield return(request.SendWebRequest());

            Dispose(request, () =>
            {
                Debug.Log("File successfully downloaded and saved to " + savePath);
                if (action != null)
                {
                    action.action();
                }
            }, action.error, action.error404, action.error500);
        }
        else
        {
            action.failedCreateFile();
        }
    }
Пример #2
0
 /// <summary>
 /// 下载文件[文件存放位置不能重复]
 /// </summary>
 /// <param name="url">请求的链接</param>
 /// <param name="savePath">保存的路径</param>
 /// <param name="action">发生的事件</param>
 /// <param name="method">请求的方式</param>
 /// <returns></returns>
 public static bool DownloadFile(string url, string savePath, RequestFileEvent action, string method = UnityWebRequest.kHttpVerbGET)
 {
     if (string.IsNullOrEmpty(url) || action == null)
     {
         return(true);
     }
     Instance.StartCoroutine(Instance.DownloadFileIEnumerator(url, savePath, method, action));
     return(false);
 }