/** 生成依赖 */ private void createDepends() { EditorUtility.DisplayProgressBar("请耐心等待", "正在检测bundle依赖...", 0.0f); int progressNum = _bundleInfoExDataList.length(); int curNum = 0; foreach (BundleInfoExData bundleInfoExData in _bundleInfoExDataList) { string[] dependencies = AssetDatabase.GetAssetBundleDependencies(bundleInfoExData.name, true); string[] depends = new string[dependencies.Length]; for (int i = 0; i < dependencies.Length; i++) { string name = dependencies[i]; bundleInfoExData.depends.add(_resourceInfoExDataCache[name].id); } EditorUtility.DisplayProgressBar("请耐心等待", "正在检测bundle依赖...", (float)++curNum / progressNum); _bundleInfoDataList[bundleInfoExData.name].depends = bundleInfoExData.depends.toArray(); } EditorUtility.ClearProgressBar(); EditorUtility.DisplayProgressBar("请耐心等待", "正在检测bundle循环依赖...", 0.0f); chechResourceLoopDepend(); }
/** 生成打包信息文件并复制打包文件到发布目录 */ private void copyFilesAndInfo() { //复制bundle文件 string buildPath = ShineToolGlobal.bundleTempPath + "/" + _targetName; string releasePath = getTargetSourcePath() + "/" + ShineToolGlobal.bundleDirName; if (!Directory.Exists(releasePath)) { Directory.CreateDirectory(releasePath); } FileUtils.clearDir(releasePath); SList <string> delBundleList = new SList <string>(); string[] files = Directory.GetFiles(buildPath, "*.bundle"); for (int i = 0; i < files.Length; i++) { string fromFileName = files[i]; string fileName = Path.GetFileName(fromFileName); //如果是无效bundle if (!_bundleInfoDataList.contains(fileName)) { delBundleList.add(fromFileName); delBundleList.add(fromFileName + ".manifest"); continue; } string toFileName = Path.Combine(releasePath, fileName); File.Copy(fromFileName, toFileName); } //删除无效bundle以及对应manifest foreach (string filePath in delBundleList) { Ctrl.print("删除无效文件", filePath); File.Delete(filePath); } //生成打包信息文件 string infoPath = getTargetSourcePath() + "/" + ShineGlobal.bundleInfoPath; BytesWriteStream buffer = new BytesWriteStream(); buffer.writeVersion(ShineGlobal.bundleInfoVersion); buffer.writeInt(_bundleInfoDataList.length()); foreach (BundleInfoData info in _bundleInfoDataList) { info.writeBytes(buffer); } buffer.writeInt(_resourceInfoDataList.length()); foreach (ResourceInfoData info in _resourceInfoDataList) { info.writeBytes(buffer); } FileUtils.writeFileForBytes(infoPath, buffer); }
/// <summary> /// 生成UI预制 /// </summary> /// <param name="force">是否强制全部生成(如果否,则增量生成,只生成改变量)</param> public static void make(bool force = false) { EditorUtility.DisplayProgressBar("请耐心等待", "正在抽离UI预制体...", 0.0f); /** 需要处理的预制体列表 */ SMap <string, long> generateList = new SMap <string, long>(); /** 全部预处理列表(包含当前所有的预制体修改记录,用于生成记录文件) */ SMap <string, long> allGenerateList = new SMap <string, long>(); if (!Directory.Exists(ShineToolGlobal.uiModelsPath)) { Directory.CreateDirectory(ShineToolGlobal.uiModelsPath); } if (!Directory.Exists(ShineToolGlobal.uiGenerateModelsPath)) { Directory.CreateDirectory(ShineToolGlobal.uiGenerateModelsPath); force = true; } //生成新预处理列表 string[] files = FileUtils.getDeepFileList(ShineToolGlobal.uiModelsPath, "prefab"); int pathLen = ShineToolGlobal.gamePath.Length + 1; for (int i = 0; i < files.Length; i++) { string file = files[i]; long time = File.GetLastWriteTime(file).Ticks; file = file.Substring(pathLen); generateList.put(file, time); allGenerateList.put(file, time); } //读取旧预处理列表 BytesReadStream stream = FileUtils.readFileForBytesReadStream(ShineToolGlobal.uiRecordPath); //读取旧预处理列表 if (force || stream == null || !stream.checkVersion(ShineToolGlobal.uiRecordVersion)) { FileUtils.clearDir(ShineToolGlobal.uiGenerateModelsPath); } else { /** 旧预处理列表 */ SMap <string, long> oldGenerateList = new SMap <string, long>(); int len = stream.readInt(); for (int i = 0; i < len; ++i) { oldGenerateList[stream.readUTF()] = stream.readLong(); } //比较新旧预制列表,并删除无效预制 oldGenerateList.forEach((k, v) => { long newTime; string genPath = ShineToolGlobal.uiGenerateModelsPath + "/"; if (generateList.tryGetValue(k, out newTime)) //如果新列表里有 { if (newTime == oldGenerateList[k]) //如果未修改,则不用抽离 { generateList.remove(k); } else //如果已修改 { File.Delete(genPath + Path.GetFileName(k)); } } else //新列表里没有,说明已删除 { File.Delete(genPath + Path.GetFileName(k)); } }); } //生成UI预制 int progressNum = generateList.length() + 1; int curNum = 0; generateList.forEach((k, v) => { generateUIPrefab(k); ++curNum; EditorUtility.DisplayProgressBar("请耐心等待", "正在抽离UI预制体...", (float)curNum / progressNum); }); //写入记录 BytesWriteStream buffer = new BytesWriteStream(); buffer.writeVersion(ShineToolGlobal.uiRecordVersion); buffer.writeInt(allGenerateList.Count); allGenerateList.forEach((k, v) => { buffer.writeUTF(k); buffer.writeLong(allGenerateList[k]); }); FileUtils.writeFileForBytes(ShineToolGlobal.uiRecordPath, buffer); EditorUtility.ClearProgressBar(); }