Skip to content

Commit

Permalink
[feat][editor]:增加移除补丁资源依赖列表中的非补丁资源,防止资源在内存中冗余
Browse files Browse the repository at this point in the history
  • Loading branch information
CatImmortal committed Jun 15, 2023
1 parent ffe7159 commit 020bd28
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 2 deletions.
1 change: 1 addition & 0 deletions Assets/CatAsset/Editor/BuildPipeline/BuildPipeline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public static ReturnCode BuildBundles(BuildTarget targetPlatform,bool isBuildPat
if (isBuildPatch)
{
//补丁包需要合并资源清单
taskList.Add(new RemoveNonPatchDependency());
taskList.Add(new MergePatchManifest());
}
taskList.Add(new WriteManifestFile());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@ public ReturnCode Run()
{
//构建补丁资源包
Stopwatch sw = Stopwatch.StartNew();



var clonedConfig = new PatchAssetCalculateHelper().Calculate(config, configParam.TargetPlatform);

sw.Stop();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
using System.Collections.Generic;
using CatAsset.Runtime;
using UnityEditor.Build.Pipeline;
using UnityEditor.Build.Pipeline.Injector;
using UnityEditor.Build.Pipeline.Interfaces;
using UnityEngine;

namespace CatAsset.Editor
{
/// <summary>
/// 移除非补丁资源的依赖,以防止资源内存冗余
/// </summary>
public class RemoveNonPatchDependency : IBuildTask
{
public int Version { get; }

[InjectContext(ContextUsage.In)]
private IManifestParam manifestParam;

public ReturnCode Run()
{
HashSet<string> patchAssets = new HashSet<string>();
foreach (BundleManifestInfo bundleManifestInfo in manifestParam.Manifest.Bundles)
{
foreach (AssetManifestInfo assetManifestInfo in bundleManifestInfo.Assets)
{
patchAssets.Add(assetManifestInfo.Name);
}
}

foreach (BundleManifestInfo bundleManifestInfo in manifestParam.Manifest.Bundles)
{
foreach (AssetManifestInfo assetManifestInfo in bundleManifestInfo.Assets)
{
for (int i = assetManifestInfo.Dependencies.Count - 1; i >= 0; i--)
{
string dependency = assetManifestInfo.Dependencies[i];
if (!patchAssets.Contains(dependency))
{
assetManifestInfo.Dependencies.RemoveAt(i);
Debug.Log($"移除{assetManifestInfo}的依赖列表中的非补丁资源{dependency}");
}
}
}
}

return ReturnCode.Success;
}
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 020bd28

Please sign in to comment.