IEnumerator InitAssetList() { string url = AssetManagerSetting.FilesCsvForStreaming; WWW www = new WWW(url); yield return(www); assetList = AssetFileList.Read(AssetManagerSetting.AssetFileListPath); if (string.IsNullOrEmpty(www.error)) { string path, md5; using (StringReader stringReader = new StringReader(www.text)) { while (stringReader.Peek() >= 0) { string line = stringReader.ReadLine(); if (!string.IsNullOrEmpty(line)) { string[] seg = line.Split(';'); path = seg[0]; md5 = seg[1]; assetList.Add(path, md5); AssetManagerSetting.persistentAssetFileList.Remove(AssetManagerSetting.GetPlatformPath(path)); } } } } assetList.Save(AssetManagerSetting.AssetFileListPath); }
public static void GeneratorUpdateList(Version appVer) { string path = AssetManagerSetting.EditorUpdateAssetListPath; Debug.Log(path); PathUtil.CheckPath(path); if (appVer == null) { if (File.Exists(path)) { File.Delete(path); } File.Copy(AssetManagerSetting.EditorFileCsvForStreaming, path); return; } Debug.Log(appVer); AssetFileList app = AssetFileList.Read(AssetManagerSetting.EditorGetVersionFileListPath(appVer.ToString())); AssetFileList curr = AssetFileList.Read(AssetManagerSetting.EditorFileCsvForStreaming); AssetFileList diff = AssetFileList.DiffAssetFileList(app, curr); diff.Save(path); }
public static AssetFileList Deserialize(string txt) { AssetFileList list = new AssetFileList(); using (StringReader stringReader = new StringReader(txt)) { while (stringReader.Peek() >= 0) { string line = stringReader.ReadLine(); if (!string.IsNullOrEmpty(line)) { string[] seg = line.Split(';'); list.Add(seg[0], seg[1]); } } } return(list); }
public static void CopyUpdateAsset(string serverRoot) { PathUtil.CheckPath(serverRoot, false); string updateAssetListPath = null; if (File.Exists(AssetManagerSetting.EditorUpdateAssetListPath)) { updateAssetListPath = AssetManagerSetting.EditorUpdateAssetListPath; } else if (File.Exists(AssetManagerSetting.EditorFileCsvForStreaming)) { updateAssetListPath = AssetManagerSetting.EditorFileCsvForStreaming; } if (!string.IsNullOrEmpty(updateAssetListPath)) { AssetFileList assetFileList = AssetFileList.Read(updateAssetListPath); assetFileList.Add(new AssetFile("{0}/" + AssetManagerSetting.UpdateAssetListName, "")); int count = assetFileList.list.Count; for (int i = 0; i < count; i++) { AssetFile item = assetFileList.list[i]; string path = AssetManagerSetting.GetPlatformPath(item.path); string fromPath = AssetManagerSetting.EditorRootStream + "/" + path; string toPath = serverRoot + "/" + path; PathUtil.CheckPath(toPath); File.Copy(fromPath, toPath, true); if (i % 10 == 0) { UnityEditor.EditorUtility.DisplayProgressBar("拷贝目录", path, 1f * i / count); } } } else { CopyAlleAsset(serverRoot); } UnityEditor.EditorUtility.ClearProgressBar(); }
private IEnumerator ReadFiles() { string path = AssetManagerSetting.LoadAssetListURL; WWW www = new WWW(path); yield return(www); if (string.IsNullOrEmpty(www.error)) { ParseInfo(www.text); } path = AssetManagerSetting.DontUnloadAssetListURL; www = new WWW(path); yield return(www); if (string.IsNullOrEmpty(www.error)) { AssetManagerSetting.dontUnloadAssetFileList = AssetFileList.Deserialize(www.text); } }
public static AssetFileList DiffAssetFileList(AssetFileList current, AssetFileList update) { AssetFileList diffs = new AssetFileList(); AssetFile gameConstItem = null; int count = update.list.Count; for (int i = 0; i < count; i++) { AssetFile item = update.list[i]; if (item.path == AssetManagerSetting.GameConstName) { gameConstItem = item; continue; } if (!current.Has(item.path)) { diffs.Add(item); } else if (item.md5 != current.Get(item.path).md5) { diffs.Add(item); } } if (gameConstItem != null) { diffs.Add(gameConstItem); } else { diffs.Add(new AssetFile(AssetManagerSetting.GameConstName, "md5")); } return(diffs); }
IEnumerator UpdateResource(string rootUrl) { // rootUrl = "http://www.ihaiu.com/StreamingAssets/" OnUpdateEnter(); //获取服务器端的file.csv OnState("获取服务器端的file.csv"); string updateAssetListUrl = AssetManagerSetting.GetServerFilesCsvURL(rootUrl); Debug.Log("UpdateAssetList URL: " + updateAssetListUrl); WWW www = new WWW(updateAssetListUrl); yield return(www); if (!string.IsNullOrEmpty(www.error)) { OnError("更新资源读取资源列表失败"); Debug.LogErrorFormat("更新资源读取资源列表失败 updateAssetListUrl={0}, www.error={1}", updateAssetListUrl, www.error); www.Dispose(); www = null; yield break; } AssetFileList updateAssetList = AssetFileList.Deserialize(www.text); www.Dispose(); www = null; //Debug.Log("count: " + files.Length + " text: " + filesText); OnState("读取" + AssetManagerSetting.AssetFileListPath); if (assetList == null) { assetList = AssetFileList.Read(AssetManagerSetting.AssetFileListPath); } List <AssetFile> diffs = AssetFileList.Diff(assetList, updateAssetList); AssetManagerSetting.persistentAssetFileList = AssetFileList.Read(AssetManagerSetting.PersistentAssetFileListPath); string path; //更新 int count = diffs.Count; for (int i = 0; i < count; i++) { AssetFile item = diffs[i]; path = AssetManagerSetting.GetPlatformPath(item.path); OnState("更新" + path); OnUpdateProgress((float)(i + 1) / (float)count); string url = rootUrl + path; www = new WWW(url); yield return(www); if (!string.IsNullOrEmpty(www.error)) { OnUpdateFailed(url); www.Dispose(); www = null; continue; } string localPath = AssetManagerSetting.RootPathPersistent + path; PathUtil.CheckPath(localPath, true); File.WriteAllBytes(localPath, www.bytes); www.Dispose(); www = null; assetList.Add(item); AssetManagerSetting.persistentAssetFileList.Add(path, item.md5); } yield return(new WaitForEndOfFrame()); assetList.Save(AssetManagerSetting.AssetFileListPath); AssetManagerSetting.persistentAssetFileList.Save(AssetManagerSetting.PersistentAssetFileListPath); // 更新完成 OnUpdateEnd(); }
public IEnumerator CheckVersion() { yield return(StartCoroutine(ReadGameConst_Streaming())); #if UNITY_EDITOR appGameConstConfig.Set(); if (appGameConstConfig.DevelopMode) { OnFinal(); yield break; } if (!AssetManagerSetting.TestVersionMode) { appGameConstConfig.Set(); OnFinal(); yield break; } #endif yield return(StartCoroutine(ReadGameConst_Persistent())); appVer.Parse(appGameConstConfig.Version); bool needInitData = false; if (curGameConstConfig == null) { appGameConstConfig.Set(); needInitData = true; } else { curGameConstConfig.Set(); curVer.Parse(curGameConstConfig.Version); needInitData = VersionCheck.CheckNeedCopy(curVer, appVer); } AssetManagerSetting.persistentAssetFileList = AssetFileList.Read(AssetManagerSetting.PersistentAssetFileListPath); if (needInitData) { yield return(StartCoroutine(InitData())); curVer.Copy(appVer); } yield return(ReadServerVersionInfo()); Debug.Log("serverVersionInfo=" + serverVersionInfo); if (serverVersionInfo != null) { if (serverVersionInfo.isClose > 0) { OnServerClose(); yieldbreak = true; } else { serverVer.Parse(serverVersionInfo.version); VersionCheckState state = VersionCheck.CheckState(curVer, serverVer); switch (state) { case VersionCheckState.DownApp: OnNeedDownApp(serverVersionInfo.downLoadUrl); yieldbreak = true; break; case VersionCheckState.HotUpdate: IsContinueHostUpdate = false; OnNeedHostUpdate(); while (!IsContinueHostUpdate) { yield return(new WaitForSeconds(0.25f)); } yield return(StartCoroutine(UpdateResource(serverVersionInfo.updateLoadUrl))); yield return(StartCoroutine(ReadGameConst_Persistent())); curGameConstConfig.Set(); OnFinal(); break; default: OnFinal(); break; } } } else { Debug.Log("zj OnFinal"); OnFinal(); } }