//-------------------------------------------------------------------------------------------- // 下载资源列表文件 IEnumerator DownLoadResList(string szUrl, string szLcl) { mMsg = "Download file " + szUrl; WWW wDwn = new WWW(szUrl); while (!wDwn.isDone) { yield return(wDwn); } if (wDwn.isDone && (null == wDwn.error)) { mResDic = ResUtil.ReadResTable(wDwn.bytes); if ((mResDic != null) && (mResDic.Count > 0)) { ResPath.SaveToLocal(szLcl, wDwn.bytes); } } else if (null != wDwn.error) { mMsg = "DownResList ERROR, Msg = " + wDwn.error; Debug.LogWarning("DownResList ERROR, Url = " + szUrl + ", Msg = " + wDwn.error); } if ((mResDic == null) || (mResDic.Count <= 0)) { Debug.LogWarning("Try local1, File = " + szLcl); mResDic = ResUtil.ReadResTable(szLcl); } BuildPackListAndDownLoad(); // 构建资源与数据包的对应关系并下载 }
//-------------------------------------------------------------------------------------------- public IEnumerator NtfDownOrLoad(bool bLocal) { GameResMng.SetLoading(); string sf = ResPath.GetLocal(mFile); if (bLocal) // 从本地读取的话要确保资源存在 { try { if (!File.Exists(sf)) // 本地不存在依然从网上下载 { bLocal = false; } } catch (Exception exp) { Debug.LogWarning("Call File.Exists() Er, file = " + sf + ", Msg = " + exp.Message); } } string sUrl = ""; if (bLocal) { sUrl = ResPath.WLocalUrl(mFile); } else // 从网上下载 { sUrl = ResPath.GetUrl(mFile); } Debug.Log("Download, URL = " + sUrl); GameResMng.DebugMsg = "Download, URL = " + sUrl; //WWW.LoadFromCacheOrDownload(sUrl,1);// mWLoad = new WWW(sUrl); yield return(mWLoad); if ((!bLocal) && mWLoad.isDone) { ResPath.SaveToLocal(sf, mWLoad.bytes); Clean(); } if (null != mWLoad.error) { Debug.LogError(mWLoad.error); } ApplyPackge(); }
public IEnumerator TryDownload(bool isClean, bool forceDownload) { if (mWLoad != null) { yield break; } GameResMng.SetLoading(); string sf = ResPath.GetLocal(mFile); bool isNeedDownload = forceDownload; try { if (!File.Exists(sf)) // 本地不存在依然从网上下载 { isNeedDownload = true; m_state = State.Downloading; } else if (isClean) { m_state = State.LocalReady; } } catch (Exception exp) { Debug.LogWarning("Call File.Exists() Er, file = " + sf + ", Msg = " + exp.Message); } string sUrl = ""; if (isNeedDownload || !isClean) { if (isNeedDownload) { sUrl = ResPath.GetUrl(mFile); } else { sUrl = ResPath.WLocalUrl(mFile); } Debug.Log("BeginDownload, URL = " + sUrl); GameResMng.DebugMsg = "Download, URL = " + sUrl; m_state = State.Downloading; mWLoad = new WWW(sUrl); yield return(mWLoad); if (null != mWLoad.error) { m_state = State.Failed; Debug.LogError("Error, URL = " + sUrl + " " + mWLoad.error); GameResMng.GetResMng().OnPackageDownloadFailed(mFile); } else if (IsDone()) { m_state = State.LocalReady; if (isNeedDownload) { ResPath.SaveToLocal(sf, mWLoad.bytes); } GameResMng.GetResMng().OnPackageDownload(mFile, mWLoad.bytes.Length); } if (isClean) { Clean(); Resources.UnloadUnusedAssets(); GC.Collect(); } string msg = "EndDownload, URL = " + sUrl; if (isClean) { msg += "[Clean]"; } Debug.Log(msg); // } ApplyPackge(); }
//-------------------------------------------------------------------------------------------- // 首先下载游戏版本 IEnumerator NtfDownLoadVer() { if (!mbLocal) { string szfNm = ResPath.GetVersionTxt(); string szUrl = ResPath.GetUrl(szfNm); string szLcl = ResPath.GetLocal(szfNm); mMsg = "Download ver file = " + szUrl; Debug.Log("StartDownload VerFile:" + szUrl); WWW wDwn = new WWW(szUrl); while (!wDwn.isDone) { yield return(wDwn); } if (wDwn.isDone && (null == wDwn.error)) { byte[] localVersionBuffer = ResPath.GetFileData(szLcl); if (localVersionBuffer != null) { ResUtil.GetVersion(localVersionBuffer, ref mGmVer, ref mReVer); } string sGmV = "", sReV = ""; if (ResUtil.GetVersion(wDwn.bytes, ref sGmV, ref sReV)) { mGmVer = sGmV; if (mReVer != sReV) { mReVer = sReV; mbLocal = false; ResPath.SaveToLocal(szLcl, wDwn.bytes); } } } else if (null != wDwn.error) { mMsg = "DownVer ERROR, Msg = " + wDwn.error; Debug.LogWarning("DownVer ERROR, Url = " + szUrl + ", Msg = " + wDwn.error); IsCheckPackage = true; mbLocal = true; } } m_versionPackage.LoadPackagesVersion(ResPath.GetLocal(ResPath.GetPackageVersionTxt())); if (!mbLocal) {//版本已经更新,需要重新下载包列表 string pckVersionFileName = ResPath.GetPackageVersionTxt(); string pckVersionFileUrl = ResPath.GetUrl(pckVersionFileName); string pckVersionFileLocal = ResPath.GetLocal(ResPath.GetRemotePackageVersionTxt()); Debug.Log("StartDownload File Package Version List:" + pckVersionFileUrl); WWW wDownloadPckVersionFilr = new WWW(pckVersionFileUrl); while (!wDownloadPckVersionFilr.isDone) { yield return(wDownloadPckVersionFilr); } if (wDownloadPckVersionFilr.isDone && (null == wDownloadPckVersionFilr.error)) { } else { IsCheckPackage = true; } if (wDownloadPckVersionFilr.isDone && (null == wDownloadPckVersionFilr.error)) { ResPath.SaveToLocal(pckVersionFileLocal, wDownloadPckVersionFilr.bytes); } else if (null != wDownloadPckVersionFilr.error) { mMsg = "DownPkgVer ERROR, Msg = " + wDownloadPckVersionFilr.error; Debug.LogWarning("DownPkgVer ERROR, Url = " + pckVersionFileUrl + ", Msg = " + wDownloadPckVersionFilr.error); } m_remotePackage.LoadPackagesVersion(pckVersionFileLocal); } NtfDownLoadResList(mbLocal); }