public static void UploadFile(LuaTable info, LuaFunction call, float timeoutSec = 3f, int retry = 3) { var www = WWWTO.DownloadFiles(WWWInfo.GetListByLua(info), null, call); www.TimeoutSec = timeoutSec; www.Retry = retry; www.Start(); }
void _download() { if (mTotalSize == 0 || mIsDownloading) { LogFile.Log(mPkgName + " 正在下载,不用重复下载。"); return; } string srcUrl = _getServUrl(); float last = Time.time; long lastSize = 0L; if (null != mNewFiles && mNewFiles.Count > 0) { List <WWWInfo> infos = new List <WWWInfo>(); for (int i = 0; i < mNewFiles.Count; ++i) { ResInfo ri = mNewFiles[i]; string url = Tools.PathCombine(srcUrl, ri.path); string savePath = Tools.GetWriteableDataPath(GameConfig.STR_ASB_MANIFIST + "/" + ri.path); infos.Add(new WWWInfo(url, savePath, ri.size)); } //需要拷贝资源到可读写文件夹 mDownloader = WWWTO.DownloadFiles( infos, (double progress, int index, string msg) => { if (Tools.Equals(progress, 1d)) { if (msg.Equals(WWWTO.STR_SUCCEEDED)) { mCurConf.version = mServConf.version; //保存新的资源版本号 saveVersionCode(); _callbackDownload(1d, 0, msg); } else { _callbackDownload(1d, -1, msg); } mCurConf.SaveToFile(_confPathWrite()); mIsDownloading = false; } else { string filePath = mNewFiles[index - 1].path; if (Tools.Equals(progress, -1d)) { //有文件下载失败 LogFile.Warn("[" + filePath + "]下载失败,url:" + infos[index - 1].Url); } else { if (msg.Equals(WWWTO.STR_DONE)) { //有文件下载成功 mCurConf.files[filePath] = mServConf.files[filePath]; } float now = Time.time; float dt = now - last; long doneSize = (long)(mTotalSize * progress); long sizePerSec = (long)((doneSize - lastSize) / dt); if (sizePerSec >= 0) { _callbackDownload(progress, sizePerSec, filePath); } last = now; lastSize = doneSize; } } }, null ); mDownloader.Start(); mIsDownloading = true; } }