diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildBundleInfo.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildBundleInfo.cs index 5926547..177a708 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildBundleInfo.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildBundleInfo.cs @@ -8,39 +8,54 @@ namespace YooAsset.Editor { public class BuildBundleInfo { - public class InfoWrapper - { - /// - /// 构建内容的哈希值 - /// - public string ContentHash { set; get; } + #region 补丁文件的关键信息 + /// + /// Unity引擎生成的哈希值(构建内容的哈希值) + /// + public string PackageUnityHash { set; get; } - /// - /// 文件哈希值 - /// - public string FileHash { set; get; } + /// + /// Unity引擎生成的CRC + /// + public uint PackageUnityCRC { set; get; } - /// - /// 文件哈希值 - /// - public string FileCRC { set; get; } + /// + /// 文件哈希值 + /// + public string PackageFileHash { set; get; } - /// - /// 文件哈希值 - /// - public long FileSize { set; get; } + /// + /// 文件哈希值 + /// + public string PackageFileCRC { set; get; } + /// + /// 文件哈希值 + /// + public long PackageFileSize { set; get; } - /// - /// 构建输出的文件路径 - /// - public string BuildOutputFilePath { set; get; } + /// + /// 构建输出的文件路径 + /// + public string BuildOutputFilePath { set; get; } + + /// + /// 补丁包的源文件路径 + /// + public string PackageSourceFilePath { set; get; } + + /// + /// 补丁包的目标文件路径 + /// + public string PackageDestFilePath { set; get; } + + /// + /// 加密生成文件的路径 + /// 注意:如果未加密该路径为空 + /// + public string EncryptedFilePath { set; get; } + #endregion - /// - /// 补丁包输出文件路径 - /// - public string PackageOutputFilePath { set; get; } - } /// /// 资源包名称 @@ -53,22 +68,11 @@ namespace YooAsset.Editor /// public readonly List AllMainAssets = new List(); - /// - /// 补丁文件信息 - /// - public readonly InfoWrapper BundleInfo = new InfoWrapper(); - /// /// Bundle文件的加载方法 /// public EBundleLoadMethod LoadMethod { set; get; } - /// - /// 加密生成文件的路径 - /// 注意:如果未加密该路径为空 - /// - public string EncryptedFilePath { set; get; } - /// /// 是否为原生文件 /// @@ -208,9 +212,10 @@ namespace YooAsset.Editor { PackageBundle packageBundle = new PackageBundle(); packageBundle.BundleName = BundleName; - packageBundle.FileHash = BundleInfo.FileHash; - packageBundle.FileCRC = BundleInfo.FileCRC; - packageBundle.FileSize = BundleInfo.FileSize; + packageBundle.FileHash = PackageFileHash; + packageBundle.FileCRC = PackageFileCRC; + packageBundle.FileSize = PackageFileSize; + packageBundle.UnityCRC = PackageUnityCRC; packageBundle.IsRawFile = IsRawFile; packageBundle.LoadMethod = (byte)LoadMethod; packageBundle.Tags = GetBundleTags(); diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreatePackage.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreatePackage.cs index 4f891bb..cf91af4 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreatePackage.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreatePackage.cs @@ -70,7 +70,7 @@ namespace YooAsset.Editor int fileTotalCount = buildMapContext.Collection.Count; foreach (var bundleInfo in buildMapContext.Collection) { - EditorTools.CopyFile(bundleInfo.BundleInfo.BuildOutputFilePath, bundleInfo.BundleInfo.PackageOutputFilePath, true); + EditorTools.CopyFile(bundleInfo.PackageSourceFilePath, bundleInfo.PackageDestFilePath, true); EditorTools.DisplayProgressBar("拷贝补丁文件", ++progressValue, fileTotalCount); } EditorTools.ClearProgressBar(); diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskUpdateBundleInfo.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskUpdateBundleInfo.cs index 4881a51..ab7e63f 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskUpdateBundleInfo.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskUpdateBundleInfo.cs @@ -29,32 +29,35 @@ namespace YooAsset.Editor // 2.更新构建输出的文件路径 foreach (var bundleInfo in buildMapContext.Collection) { + bundleInfo.BuildOutputFilePath = $"{pipelineOutputDirectory}/{bundleInfo.BundleName}"; if (bundleInfo.IsEncryptedFile) - bundleInfo.BundleInfo.BuildOutputFilePath = bundleInfo.EncryptedFilePath; + bundleInfo.PackageSourceFilePath = bundleInfo.EncryptedFilePath; else - bundleInfo.BundleInfo.BuildOutputFilePath = $"{pipelineOutputDirectory}/{bundleInfo.BundleName}"; + bundleInfo.PackageSourceFilePath = bundleInfo.BuildOutputFilePath; } // 3.更新文件其它信息 foreach (var bundleInfo in buildMapContext.Collection) { - string buildOutputFilePath = bundleInfo.BundleInfo.BuildOutputFilePath; - bundleInfo.BundleInfo.ContentHash = GetBundleContentHash(bundleInfo, context); - bundleInfo.BundleInfo.FileHash = GetBundleFileHash(buildOutputFilePath, buildParametersContext); - bundleInfo.BundleInfo.FileCRC = GetBundleFileCRC(buildOutputFilePath, buildParametersContext); - bundleInfo.BundleInfo.FileSize = GetBundleFileSize(buildOutputFilePath, buildParametersContext); + 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); } // 4.更新补丁包输出的文件路径 foreach (var bundleInfo in buildMapContext.Collection) { - string fileExtension = ManifestTools.GetRemoteBundleFileExtension(bundleInfo.BundleName); - string fileName = ManifestTools.GetRemoteBundleFileName(outputNameStyle, bundleInfo.BundleName, fileExtension, bundleInfo.BundleInfo.FileHash); - bundleInfo.BundleInfo.PackageOutputFilePath = $"{packageOutputDirectory}/{fileName}"; + string bundleName = bundleInfo.BundleName; + string fileHash = bundleInfo.PackageFileHash; + string fileExtension = ManifestTools.GetRemoteBundleFileExtension(bundleName); + string fileName = ManifestTools.GetRemoteBundleFileName(outputNameStyle, bundleName, fileExtension, fileHash); + bundleInfo.PackageDestFilePath = $"{packageOutputDirectory}/{fileName}"; } } - private string GetBundleContentHash(BuildBundleInfo bundleInfo, BuildContext context) + private string GetUnityHash(BuildBundleInfo bundleInfo, BuildContext context) { var buildParametersContext = context.GetContextObject(); var parameters = buildParametersContext.Parameters; @@ -64,7 +67,7 @@ namespace YooAsset.Editor if (bundleInfo.IsRawFile) { - string filePath = bundleInfo.BundleInfo.BuildOutputFilePath; + string filePath = bundleInfo.PackageSourceFilePath; return HashUtility.FileMD5(filePath); } @@ -75,7 +78,7 @@ namespace YooAsset.Editor if (hash.isValid) return hash.ToString(); else - throw new Exception($"Not found bundle in build result : {bundleInfo.BundleName}"); + throw new Exception($"Not found bundle hash in build result : {bundleInfo.BundleName}"); } else if (parameters.BuildPipeline == EBuildPipeline.ScriptableBuildPipeline) { @@ -84,7 +87,39 @@ namespace YooAsset.Editor if (buildResult.Results.BundleInfos.TryGetValue(bundleInfo.BundleName, out var value)) return value.Hash.ToString(); else - throw new Exception($"Not found bundle in build result : {bundleInfo.BundleName}"); + throw new Exception($"Not found bundle hash in build result : {bundleInfo.BundleName}"); + } + else + { + throw new System.NotImplementedException(); + } + } + private uint GetUnityCRC(BuildBundleInfo bundleInfo, BuildContext context) + { + var buildParametersContext = context.GetContextObject(); + var parameters = buildParametersContext.Parameters; + var buildMode = parameters.BuildMode; + if (buildMode == EBuildMode.DryRunBuild || buildMode == EBuildMode.SimulateBuild) + return 0; + + if (bundleInfo.IsRawFile) + return 0; + + if (parameters.BuildPipeline == EBuildPipeline.BuiltinBuildPipeline) + { + string filePath = bundleInfo.BuildOutputFilePath; + if (BuildPipeline.GetCRCForAssetBundle(filePath, out uint crc)) + return crc; + else + throw new Exception($"Not found bundle crc in build result : {bundleInfo.BundleName}"); + } + else if (parameters.BuildPipeline == EBuildPipeline.ScriptableBuildPipeline) + { + var buildResult = context.GetContextObject(); + if (buildResult.Results.BundleInfos.TryGetValue(bundleInfo.BundleName, out var value)) + return value.Crc; + else + throw new Exception($"Not found bundle crc in build result : {bundleInfo.BundleName}"); } else {