//暂停下载 public void StopDownload() { if (db == null) { return; } Destroy(db.gameObject); db = null; }
public void Download(DownloadTable table) { if (GameConfig.gameModel == GameModel.Editor) { if (table != null && table.AllComplete != null) { table.AllComplete(Name); } return; } if (_downloadQueue == null || _downloadQueue.Count == 0) { if (table != null && table.AllComplete != null) { table.AllComplete(Name); } return; } int downloadedCount = 0; int downloadTotal = _downloadQueue.Count; if (db == null) { db = new GameObject(Name + "_DownloadBehaviour").AddComponent <DownloadBehaviour>(); db.transform.SetParent(transform); //下载进度 db.Progress = (SDownloadEventResult result) => { //Debug.Log("----" + (float)result.FileResult.downloadedLength / (float)result.FileResult.contentLength); if (table != null && table.Progress != null) { table.Progress(Name, result.FileResult); } }; db.OneComplete = (SDownloadEventResult result) => { downloadedCount++; //下载一个完成 if (table != null && table.OneComplete != null) { table.OneComplete(Name, downloadedCount, downloadTotal); } }; db.AllComplete = (SDownloadEventResult e) => { if (table != null && table.AllComplete != null) { table.AllComplete(Name); } Destroy(db.gameObject); db = null; }; //下载失败 db.Error = (SDownloadEventResult e) => { if (table != null && table.Error != null) { table.Error(Name); } Destroy(db.gameObject); db = null; }; if (table != null && table.Befor != null) { table.Befor(Name, _downloadQueue.Count); } db.Download(Name, _md5File); } }