예제 #1
0
 private void DownloadRootModule()
 {
     Module        module = ModuleMgr.Instance.GetModule(moduleName);
     DownloadTable table  = new DownloadTable()
     {
         Befor       = DownloadBefor,
         Progress    = DownloadProgress,
         OneComplete = DownloadOneComplete,
         AllComplete = DownloadAllComplete,
         Error       = DownloadError
     };
 }
예제 #2
0
        public void CheckAndDownload(DownloadTable table)
        {
            CheckUpdateTable checkUpdateTable = new CheckUpdateTable()
            {
                Complete = (string moduleName, int downloadCount, string sizeStr) =>
                {
                    //2.下载模块
                    Download(table);
                },
                Error = (string moduleName) =>
                {
                    Debug.LogError("下载失败");
                }
            };

            //1.检查更新
            CheckUpdate(checkUpdateTable, false);
        }
예제 #3
0
        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);
            }
        }