update asset bundle builder

优化了打包逻辑,提高构建速度。
pull/82/head
hevinci 2023-03-08 19:27:09 +08:00
parent 5254fb65ef
commit 985b05f29d
4 changed files with 21 additions and 24 deletions

View File

@ -8,6 +8,8 @@ namespace YooAsset.Editor
{
public class BuildMapContext : IContextObject
{
private readonly Dictionary<string, BuildBundleInfo> _bundleInfoDic = new Dictionary<string, BuildBundleInfo>(10000);
/// <summary>
/// 参与构建的资源总数
/// 说明:包括主动收集的资源以及其依赖的所有资源
@ -32,7 +34,7 @@ namespace YooAsset.Editor
/// <summary>
/// 资源包列表
/// </summary>
public readonly List<BuildBundleInfo> BundleInfos = new List<BuildBundleInfo>(1000);
public readonly List<BuildBundleInfo> BundleInfos = new List<BuildBundleInfo>(10000);
/// <summary>
@ -44,7 +46,7 @@ namespace YooAsset.Editor
if (string.IsNullOrEmpty(bundleName))
throw new Exception("Should never get here !");
if (TryGetBundleInfo(bundleName, out BuildBundleInfo bundleInfo))
if (_bundleInfoDic.TryGetValue(bundleName, out BuildBundleInfo bundleInfo))
{
bundleInfo.PackAsset(assetInfo);
}
@ -53,6 +55,7 @@ namespace YooAsset.Editor
BuildBundleInfo newBundleInfo = new BuildBundleInfo(bundleName);
newBundleInfo.PackAsset(assetInfo);
BundleInfos.Add(newBundleInfo);
_bundleInfoDic.Add(bundleName, newBundleInfo);
}
}
@ -74,7 +77,7 @@ namespace YooAsset.Editor
/// </summary>
public string[] GetBuildinAssetPaths(string bundleName)
{
if (TryGetBundleInfo(bundleName, out BuildBundleInfo bundleInfo))
if (_bundleInfoDic.TryGetValue(bundleName, out BuildBundleInfo bundleInfo))
{
return bundleInfo.GetBuildinAssetPaths();
}
@ -100,21 +103,19 @@ namespace YooAsset.Editor
/// </summary>
public bool IsContainsBundle(string bundleName)
{
return TryGetBundleInfo(bundleName, out BuildBundleInfo bundleInfo);
return _bundleInfoDic.ContainsKey(bundleName);
}
public bool TryGetBundleInfo(string bundleName, out BuildBundleInfo result)
/// <summary>
/// 获取资源包信息如果没找到返回NULL
/// </summary>
public BuildBundleInfo GetBundleInfo(string bundleName)
{
foreach (var bundleInfo in BundleInfos)
if (_bundleInfoDic.TryGetValue(bundleName, out BuildBundleInfo result))
{
if (bundleInfo.BundleName == bundleName)
{
result = bundleInfo;
return true;
}
return result;
}
result = null;
return false;
throw new Exception($"Not found bundle : {bundleName}");
}
}
}

View File

@ -127,7 +127,7 @@ namespace YooAsset.Editor
private List<string> GetDependAssets(BuildMapContext buildMapContext, string bundleName, string assetPath)
{
List<string> result = new List<string>();
if (buildMapContext.TryGetBundleInfo(bundleName, out BuildBundleInfo bundleInfo))
var bundleInfo = buildMapContext.GetBundleInfo(bundleName);
{
BuildAssetInfo findAssetInfo = null;
foreach (var buildinAsset in bundleInfo.BuildinAssets)
@ -147,10 +147,6 @@ namespace YooAsset.Editor
result.Add(dependAssetInfo.AssetPath);
}
}
else
{
throw new Exception($"Not found bundle : {bundleName}");
}
return result;
}

View File

@ -34,13 +34,13 @@ namespace YooAsset.Editor
{
var buildParametersContext = context.GetContextObject<BuildParametersContext>();
var buildMapContext = context.GetContextObject<BuildMapContext>();
string[] buildedBundles = unityManifest.GetAllAssetBundles();
string[] unityCreateBundles = unityManifest.GetAllAssetBundles();
// 1. 过滤掉原生Bundle
string[] mapBundles = buildMapContext.BundleInfos.Where(t => t.IsRawFile == false).Select(t => t.BundleName).ToArray();
// 2. 验证Bundle
List<string> exceptBundleList1 = buildedBundles.Except(mapBundles).ToList();
List<string> exceptBundleList1 = unityCreateBundles.Except(mapBundles).ToList();
if (exceptBundleList1.Count > 0)
{
foreach (var exceptBundle in exceptBundleList1)
@ -51,7 +51,7 @@ namespace YooAsset.Editor
}
// 3. 验证Bundle
List<string> exceptBundleList2 = mapBundles.Except(buildedBundles).ToList();
List<string> exceptBundleList2 = mapBundles.Except(unityCreateBundles).ToList();
if (exceptBundleList2.Count > 0)
{
foreach (var exceptBundle in exceptBundleList2)

View File

@ -35,13 +35,13 @@ namespace YooAsset.Editor
{
var buildParameters = context.GetContextObject<BuildParametersContext>();
var buildMapContext = context.GetContextObject<BuildMapContext>();
List<string> buildedBundles = buildResults.BundleInfos.Keys.ToList();
List<string> unityCreateBundles = buildResults.BundleInfos.Keys.ToList();
// 1. 过滤掉原生Bundle
List<string> expectBundles = buildMapContext.BundleInfos.Where(t => t.IsRawFile == false).Select(t => t.BundleName).ToList();
// 2. 验证Bundle
List<string> exceptBundleList1 = buildedBundles.Except(expectBundles).ToList();
List<string> exceptBundleList1 = unityCreateBundles.Except(expectBundles).ToList();
if (exceptBundleList1.Count > 0)
{
foreach (var exceptBundle in exceptBundleList1)
@ -52,7 +52,7 @@ namespace YooAsset.Editor
}
// 3. 验证Bundle
List<string> exceptBundleList2 = expectBundles.Except(buildedBundles).ToList();
List<string> exceptBundleList2 = expectBundles.Except(unityCreateBundles).ToList();
if (exceptBundleList2.Count > 0)
{
foreach (var exceptBundle in exceptBundleList2)