//NOTE: 调用此接口时已经确认 StreamingAssets 以及本地包文件均无效 private DownloadWorker.JobInfo _DownloadBundleFile(Manifest.BundleInfo bundleInfo, Action callback, bool emergency) { var bytesPerSecond = emergency ? _bytesPerSecond : _bytesPerSecondIdle; var oldJob = _FindDownloadJob(bundleInfo.name); if (oldJob != null) { if (oldJob.bytesPerSecond < bytesPerSecond) { oldJob.bytesPerSecond = bytesPerSecond; } if (callback != null) { oldJob.callback += callback; } return(oldJob); } // 无法打开现有文件, 下载新文件 var bundlePath = Path.Combine(_localPathRoot, bundleInfo.name); var newJob = new DownloadWorker.JobInfo(bundleInfo.name, bundleInfo.checksum, bundleInfo.comment, bundleInfo.priority, bundleInfo.size, bundlePath) { emergency = emergency, bytesPerSecond = bytesPerSecond, callback = callback }; AddDownloadTask(newJob); Schedule(); return(newJob); }
private void onDownloadJobDone(DownloadWorker.JobInfo jobInfo) { if (_jobs.Remove(jobInfo)) { _activeJobs--; } try { jobInfo.callback?.Invoke(); ResourceManager.GetListener().OnTaskComplete(jobInfo); } catch (Exception exception) { Debug.LogWarningFormat("下载完成任务回调通知异常 {0}", exception); } var bundle = TryGetBundle(jobInfo.name); if (bundle != null) { if (!LoadBundleFile(bundle)) { Debug.LogErrorFormat("下载完成但文件载入失败 {0}", bundle.name); bundle.Load(null); } } Schedule(); }
private DownloadWorker.JobInfo AddDownloadTask(DownloadWorker.JobInfo newJob) { for (var it = _jobs.First; it != null; it = it.Next) { var task = it.Value; if (newJob.priority > task.priority) { _jobs.AddBefore(it, newJob); return(newJob); } } _jobs.AddLast(newJob); return(newJob); }
private void onDownloadJobDone(DownloadWorker.JobInfo jobInfo) { if (_jobs.Remove(jobInfo)) { _activeJobs--; } jobInfo.callback?.Invoke(); ResourceManager.GetListener().OnTaskComplete(jobInfo); var bundle = TryGetBundle(jobInfo.name); if (bundle != null) { if (!LoadBundleFile(bundle)) { bundle.Load(null); } } Schedule(); }