protected void Download(string url, string name, string cachePath, Action onSuccess) { var request = new DownloadRequest { Name = name, Url = url, CachePath = cachePath, OnSuccess = onSuccess, OnFail = Fail, }; request.DoStart(); }
DownloadRequest DownloadRequest(string url, string name, string hash, Action onSuccess, Action <Exception> onFail) { DownloadRequest req = null; if (m_Downloader.TryGetRequset(name, out req)) { req.OnSuccess += onSuccess; req.OnFail += onFail; return(req); } //古いキャッシュを削除 var ex = Cache.TryDelete(name); if (ex != null) { Log.Warning("[ilib-abloader] cache delete error name {0}, {1}", name, ex); onFail?.Invoke(ex); return(req); } Log.Trace("[ilib-abloader] start download request. name {0}, hash {1}, url {2}", name, hash, url); //リクエストを作成 req = new DownloadRequest { Name = name, Url = url, CachePath = Cache.GetLoadPath(name, hash), OnSuccess = onSuccess, OnFail = onFail, }; m_Downloader.Request(req); return(req); }
public Func <float> Download(string[] names, Action <bool> onComplete, Action <Exception> onFail = null) { names = GetDownloadList(names); //すでに依存関係を考慮している long size = GetSize(names, ignoreDpend: true); int successCount = 0; int completeCount = 0; Log.Debug("[ilib-abloader] start download. size {0}", size); DownloadRequest[] requests = new DownloadRequest[names.Length]; Func <float> onProgress = () => { int count = requests.Length; double sum = 0; for (int i = 0; i < count; i++) { var req = requests[i]; if (req != null) { sum += req.GetProgress() * m_BundleData.GetSize(req.Name); } } return((float)(sum / size)); }; Action onSuccessOnce = () => { completeCount++; successCount++; if (names.Length == completeCount) { onComplete?.Invoke(completeCount == successCount); } }; Action <Exception> onFailOnce = (ex) => { completeCount++; if (names.Length == completeCount) { onComplete?.Invoke(false); } onFail?.Invoke(ex); }; for (int i = 0; i < names.Length; i++) { var name = names[i]; var hash = m_BundleData.GetHash(name); var url = m_LoadOperator.RequestUrl(name, hash); requests[i] = DownloadRequest(url, name, hash, onSuccessOnce, onFailOnce); } if (names.Length == 0) { onComplete?.Invoke(true); } return(onProgress); }