diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildMapContext.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildMapContext.cs index f05ee17..98e992f 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildMapContext.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildMapContext.cs @@ -8,6 +8,8 @@ namespace YooAsset.Editor { public class BuildMapContext : IContextObject { + private readonly Dictionary _bundleInfoDic = new Dictionary(10000); + /// /// 参与构建的资源总数 /// 说明:包括主动收集的资源以及其依赖的所有资源 @@ -32,7 +34,7 @@ namespace YooAsset.Editor /// /// 资源包列表 /// - public readonly List BundleInfos = new List(1000); + public readonly List BundleInfos = new List(10000); /// @@ -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 /// 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 /// public bool IsContainsBundle(string bundleName) { - return TryGetBundleInfo(bundleName, out BuildBundleInfo bundleInfo); + return _bundleInfoDic.ContainsKey(bundleName); } - public bool TryGetBundleInfo(string bundleName, out BuildBundleInfo result) + /// + /// 获取资源包信息,如果没找到返回NULL + /// + 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}"); } } } \ No newline at end of file diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreateReport.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreateReport.cs index 3df3427..4f4e5eb 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreateReport.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreateReport.cs @@ -127,7 +127,7 @@ namespace YooAsset.Editor private List GetDependAssets(BuildMapContext buildMapContext, string bundleName, string assetPath) { List result = new List(); - 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; } diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskVerifyBuildResult.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskVerifyBuildResult.cs index 9baa5fc..fc20458 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskVerifyBuildResult.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskVerifyBuildResult.cs @@ -34,13 +34,13 @@ namespace YooAsset.Editor { var buildParametersContext = context.GetContextObject(); var buildMapContext = context.GetContextObject(); - 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 exceptBundleList1 = buildedBundles.Except(mapBundles).ToList(); + List exceptBundleList1 = unityCreateBundles.Except(mapBundles).ToList(); if (exceptBundleList1.Count > 0) { foreach (var exceptBundle in exceptBundleList1) @@ -51,7 +51,7 @@ namespace YooAsset.Editor } // 3. 验证Bundle - List exceptBundleList2 = mapBundles.Except(buildedBundles).ToList(); + List exceptBundleList2 = mapBundles.Except(unityCreateBundles).ToList(); if (exceptBundleList2.Count > 0) { foreach (var exceptBundle in exceptBundleList2) diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskVerifyBuildResult_SBP.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskVerifyBuildResult_SBP.cs index 12ddf89..70e8ad6 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskVerifyBuildResult_SBP.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskVerifyBuildResult_SBP.cs @@ -35,13 +35,13 @@ namespace YooAsset.Editor { var buildParameters = context.GetContextObject(); var buildMapContext = context.GetContextObject(); - List buildedBundles = buildResults.BundleInfos.Keys.ToList(); + List unityCreateBundles = buildResults.BundleInfos.Keys.ToList(); // 1. 过滤掉原生Bundle List expectBundles = buildMapContext.BundleInfos.Where(t => t.IsRawFile == false).Select(t => t.BundleName).ToList(); // 2. 验证Bundle - List exceptBundleList1 = buildedBundles.Except(expectBundles).ToList(); + List exceptBundleList1 = unityCreateBundles.Except(expectBundles).ToList(); if (exceptBundleList1.Count > 0) { foreach (var exceptBundle in exceptBundleList1) @@ -52,7 +52,7 @@ namespace YooAsset.Editor } // 3. 验证Bundle - List exceptBundleList2 = expectBundles.Except(buildedBundles).ToList(); + List exceptBundleList2 = expectBundles.Except(unityCreateBundles).ToList(); if (exceptBundleList2.Count > 0) { foreach (var exceptBundle in exceptBundleList2)