diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/BaseTasks/TaskUpdateBundleInfo.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/BaseTasks/TaskUpdateBundleInfo.cs index e95b0c5..df4379e 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/BaseTasks/TaskUpdateBundleInfo.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/BaseTasks/TaskUpdateBundleInfo.cs @@ -44,9 +44,9 @@ namespace YooAsset.Editor { bundleInfo.PackageUnityHash = GetUnityHash(bundleInfo, context); bundleInfo.PackageUnityCRC = GetUnityCRC(bundleInfo, context); - bundleInfo.PackageFileHash = GetBundleFileHash(bundleInfo.PackageSourceFilePath, buildParametersContext); - bundleInfo.PackageFileCRC = GetBundleFileCRC(bundleInfo.PackageSourceFilePath, buildParametersContext); - bundleInfo.PackageFileSize = GetBundleFileSize(bundleInfo.PackageSourceFilePath, buildParametersContext); + bundleInfo.PackageFileHash = GetBundleFileHash(bundleInfo, buildParametersContext); + bundleInfo.PackageFileCRC = GetBundleFileCRC(bundleInfo, buildParametersContext); + bundleInfo.PackageFileSize = GetBundleFileSize(bundleInfo, buildParametersContext); } // 4.更新补丁包输出的文件路径 @@ -62,9 +62,9 @@ namespace YooAsset.Editor protected abstract string GetUnityHash(BuildBundleInfo bundleInfo, BuildContext context); protected abstract uint GetUnityCRC(BuildBundleInfo bundleInfo, BuildContext context); - protected abstract string GetBundleFileHash(string filePath, BuildParametersContext buildParametersContext); - protected abstract string GetBundleFileCRC(string filePath, BuildParametersContext buildParametersContext); - protected abstract long GetBundleFileSize(string filePath, BuildParametersContext buildParametersContext); + protected abstract string GetBundleFileHash(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext); + protected abstract string GetBundleFileCRC(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext); + protected abstract long GetBundleFileSize(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext); protected string GetFilePathTempHash(string filePath) { @@ -74,5 +74,23 @@ namespace YooAsset.Editor // 注意:在文件路径的哈希值冲突的情况下,可以使用下面的方法 //return $"{HashUtility.BytesMD5(bytes)}-{Guid.NewGuid():N}"; } + protected long GetBundleTempSize(BuildBundleInfo bundleInfo) + { + long tempSize = 0; + + var assetPaths = bundleInfo.GetAllMainAssetPaths(); + foreach (var assetPath in assetPaths) + { + long size = FileUtility.GetFileSize(assetPath); + tempSize += size; + } + + if (tempSize == 0) + { + string message = BuildLogger.GetErrorMessage(ErrorCode.BundleTempSizeIsZero, $"Bundle temp size is zero, check bundle main asset list : {bundleInfo.BundleName}"); + throw new Exception(message); + } + return tempSize; + } } } \ No newline at end of file diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/BuiltinBuildPipeline/BuildTasks/TaskUpdateBundleInfo_BBP.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/BuiltinBuildPipeline/BuildTasks/TaskUpdateBundleInfo_BBP.cs index 35a354c..d4a5b68 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/BuiltinBuildPipeline/BuildTasks/TaskUpdateBundleInfo_BBP.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/BuiltinBuildPipeline/BuildTasks/TaskUpdateBundleInfo_BBP.cs @@ -29,7 +29,7 @@ namespace YooAsset.Editor if (hash.isValid) { return hash.ToString(); - } + } else { string message = BuildLogger.GetErrorMessage(ErrorCode.NotFoundUnityBundleHash, $"Not found unity bundle hash : {bundleInfo.BundleName}"); @@ -57,30 +57,33 @@ namespace YooAsset.Editor { string message = BuildLogger.GetErrorMessage(ErrorCode.NotFoundUnityBundleCRC, $"Not found unity bundle crc : {bundleInfo.BundleName}"); throw new Exception(message); - } + } } } - protected override string GetBundleFileHash(string filePath, BuildParametersContext buildParametersContext) + protected override string GetBundleFileHash(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext) { + string filePath = bundleInfo.PackageSourceFilePath; var buildMode = buildParametersContext.Parameters.BuildMode; if (buildMode == EBuildMode.DryRunBuild || buildMode == EBuildMode.SimulateBuild) return GetFilePathTempHash(filePath); else return HashUtility.FileMD5(filePath); } - protected override string GetBundleFileCRC(string filePath, BuildParametersContext buildParametersContext) + protected override string GetBundleFileCRC(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext) { + string filePath = bundleInfo.PackageSourceFilePath; var buildMode = buildParametersContext.Parameters.BuildMode; if (buildMode == EBuildMode.DryRunBuild || buildMode == EBuildMode.SimulateBuild) return "00000000"; //8位 else return HashUtility.FileCRC32(filePath); } - protected override long GetBundleFileSize(string filePath, BuildParametersContext buildParametersContext) + protected override long GetBundleFileSize(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext) { + string filePath = bundleInfo.PackageSourceFilePath; var buildMode = buildParametersContext.Parameters.BuildMode; if (buildMode == EBuildMode.DryRunBuild || buildMode == EBuildMode.SimulateBuild) - return 0; + return GetBundleTempSize(bundleInfo); else return FileUtility.GetFileSize(filePath); } diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/RawFileBuildPipeline/BuildTasks/TaskUpdateBundleInfo_RFBP.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/RawFileBuildPipeline/BuildTasks/TaskUpdateBundleInfo_RFBP.cs index adddcd2..e9e7899 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/RawFileBuildPipeline/BuildTasks/TaskUpdateBundleInfo_RFBP.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/RawFileBuildPipeline/BuildTasks/TaskUpdateBundleInfo_RFBP.cs @@ -32,27 +32,30 @@ namespace YooAsset.Editor { return 0; } - protected override string GetBundleFileHash(string filePath, BuildParametersContext buildParametersContext) + protected override string GetBundleFileHash(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext) { + string filePath = bundleInfo.PackageSourceFilePath; var buildMode = buildParametersContext.Parameters.BuildMode; if (buildMode == EBuildMode.SimulateBuild) return GetFilePathTempHash(filePath); else return HashUtility.FileMD5(filePath); } - protected override string GetBundleFileCRC(string filePath, BuildParametersContext buildParametersContext) + protected override string GetBundleFileCRC(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext) { + string filePath = bundleInfo.PackageSourceFilePath; var buildMode = buildParametersContext.Parameters.BuildMode; if (buildMode == EBuildMode.SimulateBuild) return "00000000"; //8位 else return HashUtility.FileCRC32(filePath); } - protected override long GetBundleFileSize(string filePath, BuildParametersContext buildParametersContext) + protected override long GetBundleFileSize(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext) { + string filePath = bundleInfo.PackageSourceFilePath; var buildMode = buildParametersContext.Parameters.BuildMode; if (buildMode == EBuildMode.SimulateBuild) - return 0; + return GetBundleTempSize(bundleInfo); else return FileUtility.GetFileSize(filePath); } diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/ScriptableBuildPipeline/BuildTasks/TaskUpdateBundleInfo_SBP.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/ScriptableBuildPipeline/BuildTasks/TaskUpdateBundleInfo_SBP.cs index 81d258d..ec07041 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/ScriptableBuildPipeline/BuildTasks/TaskUpdateBundleInfo_SBP.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/ScriptableBuildPipeline/BuildTasks/TaskUpdateBundleInfo_SBP.cs @@ -60,27 +60,30 @@ namespace YooAsset.Editor } } } - protected override string GetBundleFileHash(string filePath, BuildParametersContext buildParametersContext) + protected override string GetBundleFileHash(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext) { + string filePath = bundleInfo.PackageSourceFilePath; var buildMode = buildParametersContext.Parameters.BuildMode; if (buildMode == EBuildMode.SimulateBuild) return GetFilePathTempHash(filePath); else return HashUtility.FileMD5(filePath); } - protected override string GetBundleFileCRC(string filePath, BuildParametersContext buildParametersContext) + protected override string GetBundleFileCRC(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext) { + string filePath = bundleInfo.PackageSourceFilePath; var buildMode = buildParametersContext.Parameters.BuildMode; if (buildMode == EBuildMode.SimulateBuild) return "00000000"; //8位 else return HashUtility.FileCRC32(filePath); } - protected override long GetBundleFileSize(string filePath, BuildParametersContext buildParametersContext) + protected override long GetBundleFileSize(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext) { + string filePath = bundleInfo.PackageSourceFilePath; var buildMode = buildParametersContext.Parameters.BuildMode; if (buildMode == EBuildMode.SimulateBuild) - return 0; + return GetBundleTempSize(bundleInfo); else return FileUtility.GetFileSize(filePath); } diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildSystem/ErrorCode.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildSystem/ErrorCode.cs index e16b00c..1c7c7a2 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildSystem/ErrorCode.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildSystem/ErrorCode.cs @@ -29,7 +29,8 @@ namespace YooAsset.Editor CharactersOverTheLimit = 400, NotFoundUnityBundleHash = 401, NotFoundUnityBundleCRC = 402, - + BundleTempSizeIsZero = 403, + // TaskVerifyBuildResult UnintendedBuildBundle = 500, UnintendedBuildResult = 501,