//OperationType 0 解压,1压缩,2不处理 public static void CreateConfig(string stream, BundleManager.StreamConfig copyStream, int OperationType) { long fileSize = 0; string streamTempPath = stream + "/"; string streamingPath = streamTempPath + ResConfig.STREAMINGASSETSCONFIG; EditorUtility.DisplayCancelableProgressBar("打包资源", "正在处理 " + stream, 0.3f); string unKey = ".meta"; if (OperationType == 2) { if (EditorUserBuildSettings.activeBuildTarget != BuildTarget.iOS) { OperationType = 1; unKey = ".meta.delete.unity3d.manifest"; } } if (OperationType != 2) { //插入压缩,解压流程 for (int i = 0; i < mZipFilesName.Count; i++) { string pathFile = streamTempPath + mZipFilesName[i]; string zipDir = FEPath.GetDirectoryName(pathFile) + "/"; if (OperationType == 1) { if (FEPath.Exists(pathFile)) { //string unKey = ".meta";//: ".meta.delete.unity3d.manifest"; string outPath = FZipTool.ZipDirectory(pathFile, zipDir, unKey); //删除压缩前的文件夹 if (unKey == ".meta") { MyEdior.DeletFile(pathFile); } fileSize += new System.IO.FileInfo(outPath).Length / 1024; } } else { pathFile += ResConfig.FZIPNAMEEX; if (File.Exists(pathFile)) { FZipTool.UnZip(pathFile, zipDir, ResConfig.FZIPPASS); //删除解压前的文件夹 File.Delete(pathFile); } } } } AssetDatabase.Refresh(); BundleManager.StreamConfig streamConfig = new BundleManager.StreamConfig(); List <string> fileList = new List <string>(); string keyStream = "/" + FEPath.GetFileNameWithoutExtension(FEPath.GetDirectoryName(streamTempPath)) + "/"; SelectPrefabEditor spe = new SelectPrefabEditor("", keyStream, "", true); for (int i = 0; i < spe.tempAllStrs.Length; i++) { string path = spe.tempAllStrs[i]; if (File.Exists(path) && path.IndexOf(F_NOCOPYSTREAM) == -1 && (path.IndexOf("Assembly-CSharp") == -1)) { int pos = path.IndexOf(keyStream); fileList.Add(path.Substring(pos + keyStream.Length)); } } if (fileList.Count != 0) { for (int index = 0; index < fileList.Count; index++) { string fileName = fileList[index]; var normaFile = new BundleManager.StreamConfig.NormalFile(); int pathPos = fileName.LastIndexOf("/"); string pathFile = ""; if (pathPos != -1) { pathFile = fileName.Substring(0, pathPos); } normaFile.path = pathFile; normaFile.fileName = fileName; normaFile.md5 = FEngineManager.GetMD5HashFromFile(streamTempPath + fileName); normaFile.resType = FEPath.GetExtension(fileName); normaFile.FileType = GetResType(normaFile);// (normaFile.resType == ResConfig.FZIPNAMEEX); streamConfig.fileDatas.Add(normaFile); } } ScriptsTime.Debug("创建StreamingConfig完成"); streamConfig.IsBackDownMicro = copyStream.IsBackDownMicro; streamConfig.versionId = copyStream.versionId; streamConfig.CustomConfig = copyStream.CustomConfig; streamConfig.zipSize = fileSize; FSaveHandle sd = FSaveHandle.Create(streamingPath, FFilePath.FP_Abs, FOpenType.OT_Write); sd.PushObject(streamConfig); sd.Save(); EditorUtility.ClearProgressBar(); }
public static void CretatePartPack(bool isMain) { string copyPath = FEPath.GetDirectoryName(SceneManager.STREAMINGPATH.Replace("file://", "")); string newPath = copyPath.Replace("StreamingAssets", "_TempStreamingAssets"); FSaveHandle firstData = FSaveHandle.Create(copyPath + "/" + ResConfig.STREAMINGASSETSCONFIG, FFilePath.FP_Abs); if (!firstData.IsLoad) { Debug.LogError("没找到新配置文件:" + copyPath + "/" + ResConfig.STREAMINGASSETSCONFIG + "操作失败"); return; } BundleManager.StreamConfig firstStreamConfi = new BundleManager.StreamConfig(); firstData.FromObject(firstStreamConfi); MyEdior.DeletFile(newPath); MyEdior.CopyDirectory(copyPath, newPath); AssetDatabase.Refresh(); CreateConfig(newPath, firstStreamConfi, 0); string playFile = ""; string mainPack = copyPath.Replace("Assets/StreamingAssets", "FPartPack/MainPack"); if (isMain) { string copyPack = copyPath.Replace("Assets/StreamingAssets", "FTempCopyPack/Pack_" + DateTime.Now.ToString("MM_dd--HH_mm")); MyEdior.DeletFile(mainPack); FEPath.CreateDirectory(mainPack); EditorUtility.DisplayCancelableProgressBar("备份资源", "正在处理 ", 0.5f); File.Copy(newPath + "/" + ResConfig.STREAMINGASSETSCONFIG, mainPack + "/" + ResConfig.STREAMINGASSETSCONFIG, true); MyEdior.CopyDirectory(copyPath, copyPack + "/StreamingAssets"); File.Copy(newPath + "/" + ResConfig.STREAMINGASSETSCONFIG, copyPack + "/" + ResConfig.STREAMINGASSETSCONFIG, true); FZipTool.ZipDirectory(copyPack, FEPath.GetDirectoryName(copyPack) + "/"); MyEdior.DeletFile(copyPack); EditorUtility.ClearProgressBar(); playFile = mainPack; } else { //加载新配置 string newstreamingPath = newPath + "/" + ResConfig.STREAMINGASSETSCONFIG; FSaveHandle sd = FSaveHandle.Create(newstreamingPath, FFilePath.FP_Abs); if (sd == null) { Debug.LogError("没找到新配置文件:" + ResConfig.STREAMINGASSETSCONFIG + "对比文件失败"); } else { BundleManager.StreamConfig NewStreamConif = new BundleManager.StreamConfig(); sd.FromObject(NewStreamConif); //加载旧配置 string lastStremingPath = copyPath.Replace("Assets/StreamingAssets", "FPartPack/MainPack") + "/" + ResConfig.STREAMINGASSETSCONFIG; sd = FSaveHandle.Create(lastStremingPath, FFilePath.FP_Abs); if (sd == null) { Debug.LogError(lastStremingPath + "文件夹下,没有找到旧的配置文件" + ResConfig.STREAMINGASSETSCONFIG + "对比文件失败"); } else { //曾经变化文件 string changeFile = mainPack + "/" + ResConfig.FCACHEFILE; BundleManager.LegacyPackFile cfiles = new BundleManager.LegacyPackFile(); FSaveHandle cSave = FSaveHandle.Create(changeFile, FFilePath.FP_Abs); if (cSave != null) { cSave.FromObject(cfiles); } BundleManager.StreamConfig LastStreamConif = new BundleManager.StreamConfig(); sd.FromObject(LastStreamConif); if (NewStreamConif.versionId <= LastStreamConif.versionId) { Debug.LogError(ResConfig.STREAMINGASSETSCONFIG + ":新的配置文件versionId比旧配置文件要低,对比文件失败"); } else { //精简文件 for (int i = 0; i < NewStreamConif.fileDatas.Count; i++) { var newData = NewStreamConif.fileDatas[i]; string tempBundleName = newData.fileName; string newMd5 = NewStreamConif.GetMd5(tempBundleName); string lastMd5 = LastStreamConif.GetMd5(tempBundleName); if (cfiles.Files.ContainsKey(newData.fileName))//&& newData.path.Contains("fxlua")) { ScriptsTime.Debug("以前版本有变动的文件:" + newData.path + "==" + tempBundleName); } else if ((newMd5 != lastMd5 || lastMd5 == "")) //&& newData.path.Contains("fxlua")) { //文件有更新 ScriptsTime.Debug("产生新的文件:" + newData.path + "==" + tempBundleName); cfiles.Files[newData.fileName] = 0; string exten = FEPath.GetExtension(newData.fileName); if (exten == ResConfig.ASSETBUNDLESUFFIXES) { cfiles.Bundles[newData.fileName.Replace(ResConfig.FDESASSETBUNDLE + "/", "")] = 1; } } else { string spePath = newPath + "/" + newData.fileName; File.Delete(spePath); } } string cachefile = newPath + "/" + ResConfig.FDESASSETBUNDLE + "/" + ResConfig.FCACHEFILE; cSave = FSaveHandle.Create(cachefile, FFilePath.FP_Abs, FOpenType.OT_Write); cSave.PushObject(cfiles); cSave.Save(); File.Copy(cachefile, changeFile, true); //重新生成压缩文件 int versioin = firstStreamConfi.versionId; CreateConfig(newPath, firstStreamConfi, 1); string partversionFile = ""; if (EditorUserBuildSettings.activeBuildTarget == BuildTarget.iOS) { partversionFile = copyPath.Replace("Assets/StreamingAssets", "FPartPack/" + versioin + "/ios1"); } else { partversionFile = copyPath.Replace("Assets/StreamingAssets", "FPartPack/" + versioin + "/az1"); } MyEdior.DeletFile(partversionFile); MyEdior.CopyDirectory(newPath, partversionFile); var t = FSaveHandle.Create(partversionFile + "/version", FFilePath.FP_Abs, FOpenType.OT_Write | FOpenType.OT_Txt); string md5 = FCommonFunction.GetMD5HashFromFile(partversionFile + "/FAssetbundle.zip"); int type = EditorUserBuildSettings.activeBuildTarget != BuildTarget.iOS ? 0:1; t.SetContext("{\"version\":" + versioin.ToString() + ",\"md5\":\"" + md5 + ",\"type\":\"" + type.ToString() + "\"}"); t.Save(); File.Delete(partversionFile + "/FAssetbundle.zip.meta"); File.Delete(partversionFile + "/FStreamingAssets"); File.Delete(partversionFile + "/FStreamingAssets.meta"); playFile = partversionFile; } } } } MyEdior.DeletFile(newPath); AssetDatabase.Refresh(); if (playFile != "") { System.Diagnostics.Process.Start(playFile); Debug.Log(isMain ? "主包生成完成" : "分包生成完成"); } }