public static void Compressions() { if (Directory.Exists(AssetDefine.UpkOutPant)) { Directory.Delete(AssetDefine.UpkOutPant, true); } Directory.CreateDirectory(AssetDefine.UpkOutPant); Debug.Log("Upk/Compressions()/ upkOutPath:" + AssetDefine.UpkOutPant); string androidFileListPath = AssetDefine.GetBuildAssetOutPath() + "/" + GetPlatformName(BuildTarget.Android) + "/files.txt"; string iosFileListPath = AssetDefine.GetBuildAssetOutPath() + "/" + GetPlatformName(BuildTarget.iOS) + "/files.txt"; string windowsFileListPath = AssetDefine.GetBuildAssetOutPath() + "/" + GetPlatformName(BuildTarget.StandaloneWindows64) + "/files.txt"; string OSXFileListPath = AssetDefine.GetBuildAssetOutPath() + "/" + GetPlatformName(BuildTarget.StandaloneOSX) + "/files.txt"; Filter(androidFileListPath, GetPlatformName(BuildTarget.Android)); Filter(iosFileListPath, GetPlatformName(BuildTarget.iOS)); Filter(windowsFileListPath, GetPlatformName(BuildTarget.StandaloneWindows64)); Filter(OSXFileListPath, GetPlatformName(BuildTarget.StandaloneOSX)); if (Directory.Exists(AssetDefine.UpkTempCompressionPath)) { Directory.Delete(AssetDefine.UpkTempCompressionPath, true); } DelAssetsBundle(); AssetDatabase.Refresh(); //刷新 }
/// <summary> /// 根据选择平台进行打包 /// </summary> /// <param name="buildTarget">打包平台的名称</param> private static void BuildPlatformDirectory(BuildTarget buildTarget) { string targetName = string.Empty; switch (buildTarget) { case BuildTarget.Android: targetName = "Android"; break; case BuildTarget.iOS: targetName = "iOS"; break; case BuildTarget.StandaloneWindows64: case BuildTarget.StandaloneWindows: targetName = "Windows"; break; case BuildTarget.StandaloneOSX: targetName = "OSX"; break; default: Debug.LogError("打包的平台不存在! buildTarget=" + buildTarget); break; } string outPath = AssetDefine.GetBuildAssetOutPath() + "/" + targetName; AutoSetLabels.SetAbLabel();//设置标签 if (!Directory.Exists(outPath)) { Directory.CreateDirectory(outPath); } BuildPipeline.BuildAssetBundles(outPath, 0, buildTarget); AssetDatabase.Refresh();//刷新 Debug.Log("打包资源成功! outPath: " + outPath); GenerateAssetList.CreateFiles(outPath);//生成资源清单 }
/// <summary>清理本地的资源</summary> private static void DelAssetsBundle() { string strNeedDeleteDIR = string.Empty; strNeedDeleteDIR = AssetDefine.GetBuildAssetOutPath(); //目录信息(场景中的目录信息数组) DirectoryInfo[] dirScenesDIRArr = null; DirectoryInfo dirTempInfo = new DirectoryInfo(strNeedDeleteDIR); dirScenesDIRArr = dirTempInfo.GetDirectories(); foreach (DirectoryInfo currentDIR in dirScenesDIRArr) { JudgeDIRorFileBuyRecursive(currentDIR); } }
private static void DelAssetsBundle() { string strNeedDeleteDIR = string.Empty; strNeedDeleteDIR = AssetDefine.GetBuildAssetOutPath(); if (!string.IsNullOrEmpty(strNeedDeleteDIR)) { if (Directory.Exists(strNeedDeleteDIR)) { Directory.Delete(strNeedDeleteDIR, true); if (File.Exists(strNeedDeleteDIR + ".meta")) { File.Delete(strNeedDeleteDIR + ".meta"); } AssetDatabase.Refresh(); } Debug.Log("删除所有 AssetsBundle 完成!"); } }
/// <summary> /// 压缩资源 /// </summary> /// <param name="filePath">需要压缩资源路径</param> /// <param name="outFolder">压缩完成后,压缩包输出路径</param> private static void Compression(string filePath, string outFolder) { string inPath = AssetDefine.GetBuildAssetOutPath() + "/" + outFolder; string[] fileNameArr = filePath.Split('/'); string fileDir = filePath.Replace('/' + fileNameArr[fileNameArr.Length - 1], null); fileNameArr = fileNameArr[fileNameArr.Length - 1].Split('.'); string fileName = fileNameArr[0]; string[] inPathArr = new string[2]; inPathArr[0] = inPath + "/" + filePath; inPathArr[1] = inPath + "/" + filePath + ".manifest"; string outDir = AssetDefine.UpkOutPant + "/" + outFolder + "/" + fileDir + '/'; if (!Directory.Exists(outDir)) { Directory.CreateDirectory(outDir); } string outPath = outDir + fileName + "." + AssetDefine.UPK_EXTENSIONS; PackFolder(fileDir, fileName, inPathArr, outPath); }