/// <summary> /// 更新版本资源 /// </summary> /// <returns></returns> private IEnumerator OnUpdateVersionRes() { if (m_LocalRVLDic == null) { yield return(StartCoroutine(ParserLocalRVL())); } ///>获取服务器资源版本数据 string path = m_ServerResRootPath + "/" + RVL; WWW serverWWW = new WWW(ComTool.FormatTickUrl(path)); yield return(serverWWW); if (serverWWW.error != null) { SendErrorCode(100); } m_ServerRVLDic = ParserResVersionList(serverWWW.text, ref m_ServerVersion); serverWWW.Dispose(); yield return(StartCoroutine(CompareWithRVL())); ///>是否需要更新资源 if (m_UpdateResList != null && m_UpdateResList.Count > 0) { if (CheckUpdateEvent != null) { CheckUpdateEvent(true); } } else { EndUpdate(); } }
/// <summary> /// 下载资源包 /// </summary> /// <param name="data"></param> /// <returns></returns> private IEnumerator DownloadAssetBundle(VersionAssetData data) { string loadPath = GetAssetServerPath(data.path, data.md5); WWW www = new WWW(ComTool.FormatTickUrl(loadPath)); yield return(www); if (www.error != null) { Debug.LogError("DownloadAssetBundle Error:" + data.name); SendErrorCode(404); } else { if (CheckDataValid(data, www.bytes)) { WriteAssetOnLocal(data, www.bytes); } else { Debug.LogError("CheckDataValid false:" + data.name); } } www.Dispose(); }
IEnumerator GetServerConfig() { Debug.Log("start link"); ///开始连接,获取配置表 WWW www = new WWW(ComTool.FormatTickUrl(URL_SERVER_CONFIG)); yield return(www); if (www.error == null) { string content = www.text; XmlDocument xml = new XmlDocument(); try { xml.LoadXml(content); Debug.LogError("get xml succsess"); XmlNode node = null; node = xml.SelectSingleNode("root/ChargeType"); Debug.LogError(" get id : " + node.Attributes.GetNamedItem("id").Value + " desc :" + node.Attributes.GetNamedItem("desc").Value); node = xml.SelectSingleNode("root/AssetUrl"); URL_SERVER_RES = node.Attributes.GetNamedItem("id").Value; } catch (Exception e) { Debug.LogError("xml format error:" + e.ToString());//xml格式错误 } www.Dispose(); } else { Debug.LogError("Config www net error:" + www.error);//网络请求失败 // StartCoroutine(StartCheck()); } //请求非强制资源配置 if (URL_SERVER_RES != "") { //获得资源配置表 WWW wwwXML = new WWW(ComTool.FormatTickUrl(URL_SERVER_RES + URL_SERVER_XML)); if (wwwXML.error == null) { string content = wwwXML.text; XmlDocument xml = new XmlDocument(); try { xml.LoadXml(content); DBVersionManager.SetServerXML(xml); AysnResManager.Instance.SetResUrl(URL_SERVER_RES); } catch (Exception e) { Debug.LogError("unforce xml format error:" + e.ToString());//xml格式错误 } wwwXML.Dispose(); } /// yield return(wwwXML); } }
/// <summary> /// 移动流媒体资源 /// </summary> /// <returns></returns> private IEnumerator MoveStreamingAssets() { if (m_LocalRVLDic == null) { yield return(StartCoroutine(ParserLocalRVL())); } ///>获取流媒体文件夹内的资源列表 string path = m_StreamResRootPath + "/" + RVL; WWW streamWWW = new WWW(ComTool.FormatTickUrl(path)); yield return(streamWWW); if (streamWWW.error == null) { m_ServerRVLDic = ParserResVersionList(streamWWW.text, ref m_ServerVersion); if (CompareVersion(m_LocalVersion, m_ServerVersion)) { MoveResFinished(); } else { string localVersionPath = m_LocalResRootPath + "/" + RVL;//local资源版本列表配置 if (File.Exists(localVersionPath)) { MoveResFinished(); } else { try { FileInfo t = new FileInfo(localVersionPath); if (!t.Exists) { Directory.CreateDirectory(t.DirectoryName); } Debug.LogError("write resversion:" + localVersionPath); File.WriteAllBytes(localVersionPath, streamWWW.bytes); //xml.Save 在实际真机环境中,如果不存在文件,将会报IO错误 /* * XmlDocument xml = new XmlDocument(); * xml.LoadXml(streamWWW.text); * xml.Save(localVersionPath); * */ MoveResFinished(); }catch (Exception e) { LogHelp.LogFile(e.ToString()); } } #region /* * yield return StartCoroutine(CompareWithRVL()); * ///>是否需要移动资源 * if (m_UpdateResList != null && m_UpdateResList.Count > 0) * { * m_IsMovingRes = true; * StartCoroutine(UpdateNewRes(m_UpdateResList)); * } * else * { * MoveResFinished(); * } * */ #endregion } streamWWW.Dispose(); } else { MoveResFinished(); } }