This commit is contained in:
何冠峰
2025-11-13 11:51:28 +08:00
parent 75881b55f6
commit 079ef75605
6 changed files with 54 additions and 22 deletions

View File

@@ -44,9 +44,9 @@ namespace YooAsset.Editor
{ {
bundleInfo.PackageUnityHash = GetUnityHash(bundleInfo, context); bundleInfo.PackageUnityHash = GetUnityHash(bundleInfo, context);
bundleInfo.PackageUnityCRC = GetUnityCRC(bundleInfo, context); bundleInfo.PackageUnityCRC = GetUnityCRC(bundleInfo, context);
bundleInfo.PackageFileHash = GetBundleFileHash(bundleInfo, buildParametersContext); bundleInfo.PackageFileHash = GetBundleFileHash(bundleInfo, context);
bundleInfo.PackageFileCRC = GetBundleFileCRC(bundleInfo, buildParametersContext); bundleInfo.PackageFileCRC = GetBundleFileCRC(bundleInfo, context);
bundleInfo.PackageFileSize = GetBundleFileSize(bundleInfo, buildParametersContext); bundleInfo.PackageFileSize = GetBundleFileSize(bundleInfo, context);
} }
// 4.更新补丁包输出的文件路径 // 4.更新补丁包输出的文件路径
@@ -62,8 +62,8 @@ namespace YooAsset.Editor
protected abstract string GetUnityHash(BuildBundleInfo bundleInfo, BuildContext context); protected abstract string GetUnityHash(BuildBundleInfo bundleInfo, BuildContext context);
protected abstract uint GetUnityCRC(BuildBundleInfo bundleInfo, BuildContext context); protected abstract uint GetUnityCRC(BuildBundleInfo bundleInfo, BuildContext context);
protected abstract string GetBundleFileHash(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext); protected abstract string GetBundleFileHash(BuildBundleInfo bundleInfo, BuildContext context);
protected abstract uint GetBundleFileCRC(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext); protected abstract uint GetBundleFileCRC(BuildBundleInfo bundleInfo, BuildContext context);
protected abstract long GetBundleFileSize(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext); protected abstract long GetBundleFileSize(BuildBundleInfo bundleInfo, BuildContext context);
} }
} }

View File

@@ -40,17 +40,17 @@ namespace YooAsset.Editor
throw new Exception(message); throw new Exception(message);
} }
} }
protected override string GetBundleFileHash(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext) protected override string GetBundleFileHash(BuildBundleInfo bundleInfo, BuildContext context)
{ {
string filePath = bundleInfo.PackageSourceFilePath; string filePath = bundleInfo.PackageSourceFilePath;
return HashUtility.FileMD5(filePath); return HashUtility.FileMD5(filePath);
} }
protected override uint GetBundleFileCRC(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext) protected override uint GetBundleFileCRC(BuildBundleInfo bundleInfo, BuildContext context)
{ {
string filePath = bundleInfo.PackageSourceFilePath; string filePath = bundleInfo.PackageSourceFilePath;
return HashUtility.FileCRC32Value(filePath); return HashUtility.FileCRC32Value(filePath);
} }
protected override long GetBundleFileSize(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext) protected override long GetBundleFileSize(BuildBundleInfo bundleInfo, BuildContext context)
{ {
string filePath = bundleInfo.PackageSourceFilePath; string filePath = bundleInfo.PackageSourceFilePath;
return FileUtility.GetFileSize(filePath); return FileUtility.GetFileSize(filePath);

View File

@@ -19,16 +19,16 @@ namespace YooAsset.Editor
{ {
return 0; return 0;
} }
protected override string GetBundleFileHash(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext) protected override string GetBundleFileHash(BuildBundleInfo bundleInfo, BuildContext context)
{ {
string filePath = bundleInfo.PackageSourceFilePath; string filePath = bundleInfo.PackageSourceFilePath;
return GetFilePathTempHash(filePath); return GetFilePathTempHash(filePath);
} }
protected override uint GetBundleFileCRC(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext) protected override uint GetBundleFileCRC(BuildBundleInfo bundleInfo, BuildContext context)
{ {
return 0; return 0;
} }
protected override long GetBundleFileSize(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext) protected override long GetBundleFileSize(BuildBundleInfo bundleInfo, BuildContext context)
{ {
return GetBundleTempSize(bundleInfo); return GetBundleTempSize(bundleInfo);
} }

View File

@@ -15,27 +15,55 @@ namespace YooAsset.Editor
protected override string GetUnityHash(BuildBundleInfo bundleInfo, BuildContext context) protected override string GetUnityHash(BuildBundleInfo bundleInfo, BuildContext context)
{ {
string filePath = bundleInfo.PackageSourceFilePath; var buildParametersContext = context.GetContextObject<BuildParametersContext>();
return HashUtility.FileMD5(filePath); 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) protected override uint GetUnityCRC(BuildBundleInfo bundleInfo, BuildContext context)
{ {
return 0; return 0;
} }
protected override string GetBundleFileHash(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext) protected override string GetBundleFileHash(BuildBundleInfo bundleInfo, BuildContext context)
{ {
string filePath = bundleInfo.PackageSourceFilePath; var buildParametersContext = context.GetContextObject<BuildParametersContext>();
return HashUtility.FileMD5(filePath); 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; string filePath = bundleInfo.PackageSourceFilePath;
return HashUtility.FileCRC32Value(filePath); return HashUtility.FileCRC32Value(filePath);
} }
protected override long GetBundleFileSize(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext) protected override long GetBundleFileSize(BuildBundleInfo bundleInfo, BuildContext context)
{ {
string filePath = bundleInfo.PackageSourceFilePath; string filePath = bundleInfo.PackageSourceFilePath;
return FileUtility.GetFileSize(filePath); 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);
}
} }
} }

View File

@@ -6,5 +6,9 @@ namespace YooAsset.Editor
{ {
public class RawFileBuildParameters : BuildParameters public class RawFileBuildParameters : BuildParameters
{ {
/// <summary>
/// 文件哈希值计算包含路径信息
/// </summary>
public bool IncludePathInHash = false;
} }
} }

View File

@@ -40,17 +40,17 @@ namespace YooAsset.Editor
throw new Exception(message); throw new Exception(message);
} }
} }
protected override string GetBundleFileHash(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext) protected override string GetBundleFileHash(BuildBundleInfo bundleInfo, BuildContext context)
{ {
string filePath = bundleInfo.PackageSourceFilePath; string filePath = bundleInfo.PackageSourceFilePath;
return HashUtility.FileMD5(filePath); return HashUtility.FileMD5(filePath);
} }
protected override uint GetBundleFileCRC(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext) protected override uint GetBundleFileCRC(BuildBundleInfo bundleInfo, BuildContext context)
{ {
string filePath = bundleInfo.PackageSourceFilePath; string filePath = bundleInfo.PackageSourceFilePath;
return HashUtility.FileCRC32Value(filePath); return HashUtility.FileCRC32Value(filePath);
} }
protected override long GetBundleFileSize(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext) protected override long GetBundleFileSize(BuildBundleInfo bundleInfo, BuildContext context)
{ {
string filePath = bundleInfo.PackageSourceFilePath; string filePath = bundleInfo.PackageSourceFilePath;
return FileUtility.GetFileSize(filePath); return FileUtility.GetFileSize(filePath);