IEnumerator LoadResFromServerVersion(ResFinishDownload func) { var enumerator = downloadFileList.GetEnumerator(); while (enumerator.MoveNext()) { var element = enumerator.Current; yield return(StartCoroutine(DownLoad(SERVER_IP_URL + element, delegate(WWW www) { ReplaceLocalRes(element, www.bytes); }))); } var enumerator1 = deleteFileList.GetEnumerator(); while (enumerator1.MoveNext()) { var element1 = enumerator1.Current; DeleteRes(element1); } func(); Debug.LogError("download complete"); }
//基本测试代码,资源加载 public void LoadRes(ResFinishDownload func) { StartCoroutine(DownLoad(SERVER_RES_URL + VERSION_FILE, delegate(WWW www) { //是否需要使用XmlDocument?? 待考虑 XmlDocument XmlDoc = new XmlDocument(); XmlDoc.LoadXml(www.text); XmlElement XmlRoot = XmlDoc.DocumentElement; foreach (XmlNode node in XmlRoot.ChildNodes) { if ((node is XmlElement) == false) { continue; } string file = (node as XmlElement).GetAttribute("FileName"); string md5 = (node as XmlElement).GetAttribute("MD5"); if (ServerResVersion.ContainsKey(file) == false) { ServerResVersion.Add(file, md5); } } XmlDocument localResXMl = new XmlDocument(); Debug.LogError("Path" + ResourceLoader.relativePath); localResXMl.Load(ResourceLoader.relativePath + "/AssetBundles/Windows/" + VERSION_FILE); XmlElement localXmlRoot = localResXMl.DocumentElement; foreach (XmlNode lNode in localXmlRoot.ChildNodes) { if ((lNode is XmlElement) == false) { continue; } string file = (lNode as XmlElement).GetAttribute("FileName"); string md5 = (lNode as XmlElement).GetAttribute("MD5"); if (LocalResVersion.ContainsKey(file) == false) { LocalResVersion.Add(file, md5); } } foreach (var it in ServerResVersion) { if (!LocalResVersion.ContainsKey(it.Key)) { downloadFileList.Add(it.Key); } else { if (!it.Value.Equals(LocalResVersion[it.Key])) { downloadFileList.Add(it.Key); } } } foreach (var it in LocalResVersion) { if (!ServerResVersion.ContainsKey(it.Key)) { deleteFileList.Add(it.Key); } } XmlRoot = null; XmlDoc = null; //保存xml文件 ReplaceLocalRes("AssetBundles/" + VERSION_FILE, www.bytes); StartCoroutine(LoadResFromServerVersion(func)); } )); }