/// <summary> /// 对比可读写文件夹下资源版本和包内资源版本 /// 加载asb可以从streaming路径加载,不需要将资源拷贝到可读写文件夹 /// 当包体资源有更新时,删除老的已下载资源包 /// </summary> private void _checkLocalRes() { if (GameConfig.UseAsb) { string sUrl = _confUrlStream(); string wUrl = _confUrlWrite(); WWWTO streamWWW = WWWTO.ReadFileStr(sUrl, (rst, msg) => { if (rst) { mStreamConf = new ResConf(msg); EventManager.NotifyMain(STR_EVENT_PKG_VERSION, mStreamConf.version); } else { // 该包没有在游戏包体内 mStreamConf = new ResConf(""); } WWWTO writableWWW = WWWTO.ReadFileStr(wUrl, _onWriteableConf, null); writableWWW.Start(); }, null); streamWWW.Start(); } else { _callbackLocal(true, ""); } }
public void ReadCotainPkgs(Action <bool> callback) { mCotainCall = callback; string url = Tools.GetFileUrl(GameConfig.STR_ASB_MANIFIST + "/version/" + ConfFile); WWWTO www = WWWTO.ReadFileStr(url, _onReadConf, null); www.Start(); }
/// <summary> /// 对比服务器配置文件,记录新的文件 /// </summary> /// <param name="url">服务器地址 URL.</param> /// <param name="callback">Callback.</param> private void _compareNewFiles(string url, Action <long, string> callback) { if (null != callback) { if (GameConfig.UseAsb) { string sUrl = _confUrl(url); string pUrl = _confUrlWrite(); WWWTO streamWWW = WWWTO.ReadFileStr(sUrl, (rst, msg) => { if (rst) { mServConf = new ResConf(msg); WWWTO writableWWW = WWWTO.ReadFileStr(pUrl, (_rst, _msg) => { if (_rst) { //之前已经拷贝过资源 mCurConf = new ResConf(_msg); } else { mCurConf = new ResConf(""); } mTotalSize = 0; if (mServConf.CompareVer(mCurConf) > 0) { mNewFiles = mServConf.GetUpdateFiles(mCurConf); foreach (var f in mNewFiles) { mTotalSize += f.size; } callback(mTotalSize, mServConf.version); } else { LogFile.Log("没有检测到新版本资源,跳过更新步骤"); callback(mTotalSize, "没有检测到新版本资源,跳过更新步骤"); } }, null); writableWWW.Start(); } else { LogFile.Warn("资源配置文件" + sUrl + "丢失"); callback(-1, STR_CONFIG_MISSING); } }, null); streamWWW.Start(); } else { callback(0, "不使用Assetbundle不用拷贝/下载资源"); } } }
public void ReqAllPkgs(Action <bool> callback) { mReqAllCall = callback; List <string> urls = new List <string>(); foreach (var item in UpdateMgr.Instance.ResServList) { urls.Add(Tools.PathCombine(item.path, GameConfig.STR_ASB_MANIFIST + "/version/" + ConfFile)); } WWWTO www = WWWTO.ReadFirstExistsStr(urls, _onAllPkgResp, null); www.Start(); }
/// <summary> /// 获取服务器上相应平台的配置信息 /// </summary> /// <param name="callback">回调.</param> /// <param name="forceLoad">如果设置为 <c>true</c> 强制从服务器获取</param> public void LoadServConf(Action <Dictionary <string, string> > callback, bool forceLoad = false) { mServConfCall = callback; if (null == mServConf || mServConf.Count == 0 || forceLoad) { LoadResServList((ResInfo[] list) => { List <string> files = new List <string>(); for (int i = 0; i < list.Length; i++) { files.Add(Tools.PathCombine(list[i].path, GameConfig.STR_ASB_MANIFIST + "/servConf.bytes")); } WWWTO www = WWWTO.ReadFirstExistsStr(files, _onServConfResp, null); www.TimeoutSec = 1.5f; www.Start(); }); } else { _callbackServConf(); } }
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; } }