Пример #1
0
        IEnumerator DownloadFileHandler()
        {
            UnityDownloadFileHandler handler = new UnityDownloadFileHandler(mDownloadObj);
            UnityWebRequest          request = UnityWebRequest.Get(mDownloadObj.url);

            requestDict.Add(mDownloadObj.url, new RequestHandler(request, handler));

            int rangeFrom = handler.GetDownloadObj().sDownloadFileResult.downloadedLength;
            int rangeTo   = handler.GetDownloadObj().sDownloadFileResult.contentLength;

            if (rangeFrom >= rangeTo)
            {
                Debug.Log("设置Range超出! rangeFrom:" + rangeFrom + " rangeTo:" + rangeTo);
                OnResponse(200);//防止range太大 出现416报错
                yield break;
            }

            request.SetRequestHeader("Range", string.Format("bytes={0}-", rangeFrom)); //成功返回206
            request.downloadHandler = handler;
            request.timeout         = UnityDownloadManager.TIMEOUT;
            request.chunkedTransfer = true;
            request.disposeDownloadHandlerOnDispose = true;

            yield return(request.SendWebRequest());

            int code = (int)request.responseCode;

            OnResponse(code);
        }
Пример #2
0
        IEnumerator DownloadFileHandler(string download_url, string localPath_url, int timeout, Action <SDownloadFileResult> progress, Action <int> complete)
        {
            UnityDownloadFileHandler handler = new UnityDownloadFileHandler(download_url, localPath_url);

            handler.Progress = progress;
            UnityWebRequest request = UnityWebRequest.Get(download_url);

            request.SetRequestHeader("Range", string.Format("bytes={0}-", handler.DownloadedLength)); //成功返回206
            request.downloadHandler = handler;
            request.timeout         = timeout;
            request.chunkedTransfer = true;
            request.disposeDownloadHandlerOnDispose = true;
            requestDict.Add(download_url, new RequestHandler(request, handler));
            yield return(request.Send());

            int code = (int)request.responseCode;

            Dispose(download_url);
            if (complete != null)
            {
                complete(code);
            }
        }
Пример #3
0
 public RequestHandler(UnityWebRequest request, UnityDownloadFileHandler handler)
 {
     this.request = request;
     this.handler = handler;
 }