diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreatePatchManifest.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreatePatchManifest.cs index 2754b7a..258b64a 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreatePatchManifest.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreatePatchManifest.cs @@ -47,10 +47,27 @@ namespace YooAsset.Editor if (buildParameters.BuildMode == EBuildMode.IncrementalBuild) { var buildResultContext = context.GetContextObject(); - UpdateBuiltInBundleReference(patchManifest, buildResultContext.Results, buildMapContext.ShadersBundleName); + UpdateBuiltInBundleReference(patchManifest, buildResultContext, buildMapContext.ShadersBundleName); } } + // 更新资源包之间的引用关系 + if (buildParameters.BuildPipeline == EBuildPipeline.ScriptableBuildPipeline) + { + if (buildParameters.BuildMode == EBuildMode.IncrementalBuild) + { + var buildResultContext = context.GetContextObject(); + UpdateScriptPipelineReference(patchManifest, buildResultContext); + } + } + + // 更新资源包之间的引用关系 + if (buildParameters.BuildPipeline == EBuildPipeline.BuiltinBuildPipeline) + { + var buildResultContext = context.GetContextObject(); + UpdateBuiltinPipelineReference(patchManifest, buildResultContext, buildMapContext); + } + // 创建补丁清单文本文件 { string fileName = YooAssetSettingsData.GetManifestJsonFileName(buildParameters.PackageName, buildParameters.PackageVersion); @@ -164,11 +181,11 @@ namespace YooAsset.Editor /// /// 更新Unity内置资源包的引用关系 /// - private void UpdateBuiltInBundleReference(PatchManifest patchManifest, IBundleBuildResults buildResults, string shadersBunldeName) + private void UpdateBuiltInBundleReference(PatchManifest patchManifest, TaskBuilding_SBP.BuildResultContext buildResultContext, string shadersBunldeName) { // 获取所有依赖着色器资源包的资源包列表 List shaderBundleReferenceList = new List(); - foreach (var valuePair in buildResults.BundleInfos) + foreach (var valuePair in buildResultContext.Results.BundleInfos) { if (valuePair.Value.Dependencies.Any(t => t == shadersBunldeName)) shaderBundleReferenceList.Add(valuePair.Key); @@ -210,5 +227,79 @@ namespace YooAsset.Editor } return result; } + + /// + /// 更新资源包之间的引用关系 + /// + private void UpdateScriptPipelineReference(PatchManifest patchManifest, TaskBuilding_SBP.BuildResultContext buildResultContext) + { + foreach (var patchBundle in patchManifest.BundleList) + { + patchBundle.ReferenceIDs = GetScriptPipelineRefrenceIDs(patchManifest, patchBundle, buildResultContext); + } + } + private int[] GetScriptPipelineRefrenceIDs(PatchManifest patchManifest, PatchBundle patchBundle, TaskBuilding_SBP.BuildResultContext buildResultContext) + { + if (buildResultContext.Results.BundleInfos.TryGetValue(patchBundle.BundleName, out var details) == false) + { + throw new Exception("Should never get here !"); + } + + List referenceList = new List(); + foreach (var keyValuePair in buildResultContext.Results.BundleInfos) + { + string bundleName = keyValuePair.Key; + if (bundleName == patchBundle.BundleName) + continue; + if (keyValuePair.Value.Dependencies.Contains(patchBundle.BundleName)) + { + referenceList.Add(bundleName); + } + } + + List result = new List(); + foreach (var bundleName in referenceList) + { + int bundleID = GetAssetBundleID(bundleName, patchManifest); + if (result.Contains(bundleID) == false) + result.Add(bundleID); + } + return result.ToArray(); + } + + /// + /// 更新资源包之间的引用关系 + /// + private void UpdateBuiltinPipelineReference(PatchManifest patchManifest, TaskBuilding.BuildResultContext buildResultContext, BuildMapContext buildMapContext) + { + foreach (var patchBundle in patchManifest.BundleList) + { + patchBundle.ReferenceIDs = GetBuiltinPipelineRefrenceIDs(patchManifest, patchBundle, buildResultContext, buildMapContext); + } + } + private int[] GetBuiltinPipelineRefrenceIDs(PatchManifest patchManifest, PatchBundle patchBundle, TaskBuilding.BuildResultContext buildResultContext, BuildMapContext buildMapContext) + { + List referenceList = new List(); + foreach (var bundleInfo in buildMapContext.BundleInfos) + { + string bundleName = bundleInfo.BundleName; + if (bundleName == patchBundle.BundleName) + continue; + string[] dependencies = buildResultContext.UnityManifest.GetAllDependencies(bundleName); + if (dependencies.Contains(patchBundle.BundleName)) + { + referenceList.Add(bundleName); + } + } + + List result = new List(); + foreach (var bundleName in referenceList) + { + int bundleID = GetAssetBundleID(bundleName, patchManifest); + if (result.Contains(bundleID) == false) + result.Add(bundleID); + } + return result.ToArray(); + } } } \ No newline at end of file