private void OnTreadDownloadData(ref DownloadData downloadInfo) { this.m_download_state = true; ProgressEventProxyUpdate pro_event_proxy = new ProgressEventProxyUpdate(); pro_event_proxy.DataCompleteMethod = new Action <MemoryLoadCallbackFunc, DownloadDataCompletedEventArgs>(this.DownloadDataCompleted); pro_event_proxy.CallBack = downloadInfo.callback; using (WebClient client = new WebClient()) { client.DownloadDataCompleted += pro_event_proxy.DownloadDataCompleted; try { client.DownloadDataAsync(new Uri(downloadInfo.memory_quest.RelativePath)); } catch (Exception ex) { Debug.LogError(ex.Message); } LogMgr.Log("Thread Download:{0}", downloadInfo.memory_quest.RelativePath); } }
private IEnumerator LoadToMemoryAsyncImpl(MemoryQuest memory_quest, MemoryLoadCallbackFunc callback) { bool openDownloadLog = AppConst.OpenDownloadLog; if (openDownloadLog) { LogMgr.Log("update file, url:{0},", memory_quest.RelativePath); } bool useUpdateNewMode = AppConst.UseUpdateNewMode; if (useUpdateNewMode) { UnityWebRequest webRequest = UnityWebRequest.Get(memory_quest.RelativePath); memory_quest.request = webRequest; webRequest.timeout = memory_quest.timeout; yield return(webRequest.SendWebRequest()); bool flag = webRequest.isNetworkError || webRequest.isHttpError || webRequest.downloadHandler == null || webRequest.downloadHandler.data == null; if (flag) { LogMgr.Log("res request error occurr, res url:{0}, error:{1}, responseCode:{2}, downloadProgress:{3},isNetworkError:{4}, isHttpError:{5}", memory_quest.RelativePath, webRequest.error, webRequest.responseCode, webRequest.downloadProgress, webRequest.isNetworkError, webRequest.isHttpError ); callback(false, null); } else { callback(true, webRequest.downloadHandler.data); } bool useDeleteRequestMode = AppConst.UseDeleteRequestMode; if (useDeleteRequestMode) { UnityWebRequest.Delete(memory_quest.RelativePath); } webRequest.Dispose(); webRequest = null; webRequest = null; } else { bool useUpdatOriModeReal = AppConst.UseUpdatOriModeReal; if (useUpdatOriModeReal) { ProgressEventProxyUpdate pro_event_proxy = new ProgressEventProxyUpdate(); pro_event_proxy.FileCompleteMethod = new Action <MemoryLoadCallbackFunc, AsyncCompletedEventArgs>(this.DownloadFileCompleted); pro_event_proxy.CallBack = callback; WebClient client = new WebClient(); client.DownloadFileCompleted += pro_event_proxy.DownloadFileCompleted; string save_path = memory_quest.save_path; client.DownloadFileAsync(new Uri(memory_quest.RelativePath), save_path); pro_event_proxy = null; client = null; save_path = null; } else { WWW www = new WWW(memory_quest.RelativePath); memory_quest.Www = www; yield return(www); bool flag3 = !string.IsNullOrEmpty(www.error) || www.bytes == null; if (flag3) { LogMgr.Log("res request error occurr, res url:{0}, error:{1}", memory_quest.RelativePath, www.error); callback(false, null); } else { byte[] bytes = www.bytes; callback(true, bytes); bytes = null; } www.Dispose(); www = null; www = null; } } yield break; }