diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/BaseTasks/TaskUpdateBundleInfo.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/BaseTasks/TaskUpdateBundleInfo.cs index ffcd2979..e9654680 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, buildParametersContext); - bundleInfo.PackageFileCRC = GetBundleFileCRC(bundleInfo, buildParametersContext); - bundleInfo.PackageFileSize = GetBundleFileSize(bundleInfo, buildParametersContext); + bundleInfo.PackageFileHash = GetBundleFileHash(bundleInfo, context); + bundleInfo.PackageFileCRC = GetBundleFileCRC(bundleInfo, context); + bundleInfo.PackageFileSize = GetBundleFileSize(bundleInfo, context); } // 4.更新补丁包输出的文件路径 @@ -62,8 +62,8 @@ namespace YooAsset.Editor protected abstract string GetUnityHash(BuildBundleInfo bundleInfo, BuildContext context); protected abstract uint GetUnityCRC(BuildBundleInfo bundleInfo, BuildContext context); - protected abstract string GetBundleFileHash(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext); - protected abstract uint GetBundleFileCRC(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext); - protected abstract long GetBundleFileSize(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext); + protected abstract string GetBundleFileHash(BuildBundleInfo bundleInfo, BuildContext context); + protected abstract uint GetBundleFileCRC(BuildBundleInfo bundleInfo, BuildContext context); + protected abstract long GetBundleFileSize(BuildBundleInfo bundleInfo, BuildContext context); } } \ 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 f6bbfff7..0603cdc4 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/BuiltinBuildPipeline/BuildTasks/TaskUpdateBundleInfo_BBP.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/BuiltinBuildPipeline/BuildTasks/TaskUpdateBundleInfo_BBP.cs @@ -40,17 +40,17 @@ namespace YooAsset.Editor throw new Exception(message); } } - protected override string GetBundleFileHash(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext) + protected override string GetBundleFileHash(BuildBundleInfo bundleInfo, BuildContext context) { string filePath = bundleInfo.PackageSourceFilePath; return HashUtility.FileMD5(filePath); } - protected override uint GetBundleFileCRC(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext) + protected override uint GetBundleFileCRC(BuildBundleInfo bundleInfo, BuildContext context) { string filePath = bundleInfo.PackageSourceFilePath; return HashUtility.FileCRC32Value(filePath); } - protected override long GetBundleFileSize(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext) + protected override long GetBundleFileSize(BuildBundleInfo bundleInfo, BuildContext context) { string filePath = bundleInfo.PackageSourceFilePath; return FileUtility.GetFileSize(filePath); diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/EditorSimulateBuildPipeline/BuildTasks/TaskUpdateBundleInfo_ESBP.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/EditorSimulateBuildPipeline/BuildTasks/TaskUpdateBundleInfo_ESBP.cs index 7bb7bbfd..f56a7cb4 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/EditorSimulateBuildPipeline/BuildTasks/TaskUpdateBundleInfo_ESBP.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/EditorSimulateBuildPipeline/BuildTasks/TaskUpdateBundleInfo_ESBP.cs @@ -19,16 +19,16 @@ namespace YooAsset.Editor { return 0; } - protected override string GetBundleFileHash(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext) + protected override string GetBundleFileHash(BuildBundleInfo bundleInfo, BuildContext context) { string filePath = bundleInfo.PackageSourceFilePath; return GetFilePathTempHash(filePath); } - protected override uint GetBundleFileCRC(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext) + protected override uint GetBundleFileCRC(BuildBundleInfo bundleInfo, BuildContext context) { return 0; } - protected override long GetBundleFileSize(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext) + protected override long GetBundleFileSize(BuildBundleInfo bundleInfo, BuildContext context) { return GetBundleTempSize(bundleInfo); } 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 367662ad..ee267f57 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/RawFileBuildPipeline/BuildTasks/TaskUpdateBundleInfo_RFBP.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/RawFileBuildPipeline/BuildTasks/TaskUpdateBundleInfo_RFBP.cs @@ -15,27 +15,55 @@ namespace YooAsset.Editor protected override string GetUnityHash(BuildBundleInfo bundleInfo, BuildContext context) { - string filePath = bundleInfo.PackageSourceFilePath; - return HashUtility.FileMD5(filePath); + var buildParametersContext = context.GetContextObject(); + var rawFileBuildParameters = buildParametersContext.Parameters as RawFileBuildParameters; + if (rawFileBuildParameters.IncludePathInHash) + { + string filePath = bundleInfo.PackageSourceFilePath; + return GetFileMD5IncludePath(filePath); + } + else + { + string filePath = bundleInfo.PackageSourceFilePath; + return HashUtility.FileMD5(filePath); + } } protected override uint GetUnityCRC(BuildBundleInfo bundleInfo, BuildContext context) { return 0; } - protected override string GetBundleFileHash(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext) + protected override string GetBundleFileHash(BuildBundleInfo bundleInfo, BuildContext context) { - string filePath = bundleInfo.PackageSourceFilePath; - return HashUtility.FileMD5(filePath); + var buildParametersContext = context.GetContextObject(); + var rawFileBuildParameters = buildParametersContext.Parameters as RawFileBuildParameters; + if (rawFileBuildParameters.IncludePathInHash) + { + string filePath = bundleInfo.PackageSourceFilePath; + return GetFileMD5IncludePath(filePath); + } + else + { + string filePath = bundleInfo.PackageSourceFilePath; + return HashUtility.FileMD5(filePath); + } } - protected override uint GetBundleFileCRC(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext) + protected override uint GetBundleFileCRC(BuildBundleInfo bundleInfo, BuildContext context) { string filePath = bundleInfo.PackageSourceFilePath; return HashUtility.FileCRC32Value(filePath); } - protected override long GetBundleFileSize(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext) + protected override long GetBundleFileSize(BuildBundleInfo bundleInfo, BuildContext context) { string filePath = bundleInfo.PackageSourceFilePath; return FileUtility.GetFileSize(filePath); } + + private string GetFileMD5IncludePath(string filePath) + { + string pathHash = HashUtility.StringMD5(filePath.ToLowerInvariant()); + string contentHash = HashUtility.FileMD5(filePath); + string combined = pathHash + contentHash; + return HashUtility.StringMD5(combined); + } } } \ No newline at end of file diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/RawFileBuildPipeline/RawFileBuildParameters.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/RawFileBuildPipeline/RawFileBuildParameters.cs index eedb8d5f..2a3416bc 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/RawFileBuildPipeline/RawFileBuildParameters.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/RawFileBuildPipeline/RawFileBuildParameters.cs @@ -6,5 +6,9 @@ namespace YooAsset.Editor { public class RawFileBuildParameters : BuildParameters { + /// + /// 文件哈希值计算包含路径信息 + /// + public bool IncludePathInHash = false; } } \ No newline at end of file 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 15af935a..84a39a4a 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/ScriptableBuildPipeline/BuildTasks/TaskUpdateBundleInfo_SBP.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildPipeline/ScriptableBuildPipeline/BuildTasks/TaskUpdateBundleInfo_SBP.cs @@ -40,17 +40,17 @@ namespace YooAsset.Editor throw new Exception(message); } } - protected override string GetBundleFileHash(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext) + protected override string GetBundleFileHash(BuildBundleInfo bundleInfo, BuildContext context) { string filePath = bundleInfo.PackageSourceFilePath; return HashUtility.FileMD5(filePath); } - protected override uint GetBundleFileCRC(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext) + protected override uint GetBundleFileCRC(BuildBundleInfo bundleInfo, BuildContext context) { string filePath = bundleInfo.PackageSourceFilePath; return HashUtility.FileCRC32Value(filePath); } - protected override long GetBundleFileSize(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext) + protected override long GetBundleFileSize(BuildBundleInfo bundleInfo, BuildContext context) { string filePath = bundleInfo.PackageSourceFilePath; return FileUtility.GetFileSize(filePath);