diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderHelper.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderHelper.cs
index a416c30..142d2dc 100644
--- a/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderHelper.cs
+++ b/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderHelper.cs
@@ -25,19 +25,6 @@ namespace YooAsset.Editor
return $"{outputRoot}/{buildTarget}/{YooAssetSettingsData.Setting.UnityManifestFileName}";
}
- ///
- /// 制作AssetBundle的完整名称
- /// 注意:名称为全部小写并且包含后缀名
- ///
- public static string MakeBundleName(string bundleLabel, string bundleVariant)
- {
- if (string.IsNullOrEmpty(bundleVariant))
- return bundleLabel.ToLower();
- else
- return $"{bundleLabel}.{bundleVariant}".ToLower();
- }
-
-
///
/// 清空流文件夹
///
diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildAssetInfo.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildAssetInfo.cs
index a84caf7..057a1ed 100644
--- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildAssetInfo.cs
+++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildAssetInfo.cs
@@ -6,25 +6,30 @@ namespace YooAsset.Editor
{
public class BuildAssetInfo
{
+ ///
+ /// 资源包名称
+ ///
+ public string BundleName { private set; get; }
+
///
/// 资源路径
///
public string AssetPath { private set; get; }
- ///
- /// 资源包完整名称
- ///
- public string BundleName { private set; get; }
-
///
/// 是否为原生资源
///
- public bool IsRawAsset = false;
+ public bool IsRawAsset { private set; get; }
+
+ ///
+ /// 不写入资源列表
+ ///
+ public bool NotWriteToAssetList { private set; get; }
///
/// 是否为主动收集资源
///
- public bool IsCollectAsset = false;
+ public bool IsCollectAsset { private set; get; }
///
/// 被依赖次数
@@ -32,7 +37,7 @@ namespace YooAsset.Editor
public int DependCount = 0;
///
- /// 资源标记列表
+ /// 资源分类标签列表
///
public readonly List AssetTags = new List();
@@ -43,9 +48,19 @@ namespace YooAsset.Editor
public List AllDependAssetInfos { private set; get; }
+ public BuildAssetInfo(string assetPath, bool isRawAsset, bool notWriteToAssetList)
+ {
+ AssetPath = assetPath;
+ IsRawAsset = isRawAsset;
+ NotWriteToAssetList = notWriteToAssetList;
+ IsCollectAsset = true;
+ }
public BuildAssetInfo(string assetPath)
{
AssetPath = assetPath;
+ IsRawAsset = false;
+ NotWriteToAssetList = true;
+ IsCollectAsset = false;
}
///
@@ -60,18 +75,18 @@ namespace YooAsset.Editor
}
///
- /// 设置资源包的标签和文件格式
+ /// 设置资源包名称
///
- public void SetBundleLabelAndVariant(string bundleLabel, string bundleVariant)
+ public void SetBundleName(string bundleName)
{
if (string.IsNullOrEmpty(BundleName) == false)
throw new System.Exception("Should never get here !");
- BundleName = AssetBundleBuilderHelper.MakeBundleName(bundleLabel, bundleVariant);
+ BundleName = bundleName;
}
///
- /// 添加资源标记
+ /// 添加资源分类标签
///
public void AddAssetTags(List tags)
{
@@ -82,7 +97,7 @@ namespace YooAsset.Editor
}
///
- /// 添加资源标记
+ /// 添加资源分类标签
///
public void AddAssetTag(string tag)
{
@@ -93,7 +108,7 @@ namespace YooAsset.Editor
}
///
- /// 资源包名是否有效
+ /// 资源包名称是否有效
///
public bool BundleNameIsValid()
{
diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildBundleInfo.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildBundleInfo.cs
index 8fb91c8..4e92e01 100644
--- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildBundleInfo.cs
+++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildBundleInfo.cs
@@ -9,13 +9,13 @@ namespace YooAsset.Editor
public class BuildBundleInfo
{
///
- /// 资源包完整名称
+ /// 资源包名称
///
public string BundleName { private set; get; }
///
/// 参与构建的资源列表
- /// 注意:不包含冗余资源或零依赖资源
+ /// 注意:不包含零依赖资源
///
public readonly List BuildinAssets = new List();
@@ -41,6 +41,17 @@ namespace YooAsset.Editor
BundleName = bundleName;
}
+ ///
+ /// 添加一个打包资源
+ ///
+ public void PackAsset(BuildAssetInfo assetInfo)
+ {
+ if (IsContainsAsset(assetInfo.AssetPath))
+ throw new System.Exception($"Asset is existed : {assetInfo.AssetPath}");
+
+ BuildinAssets.Add(assetInfo);
+ }
+
///
/// 是否包含指定资源
///
@@ -57,29 +68,7 @@ namespace YooAsset.Editor
}
///
- /// 添加一个打包资源
- ///
- public void PackAsset(BuildAssetInfo assetInfo)
- {
- if (IsContainsAsset(assetInfo.AssetPath))
- throw new System.Exception($"Asset is existed : {assetInfo.AssetPath}");
-
- BuildinAssets.Add(assetInfo);
- }
-
- ///
- /// 获取文件的扩展名
- ///
- public string GetAppendExtension()
- {
- if (IsRawFile)
- return $".{YooAssetSettingsData.Setting.RawFileVariant}";
- else
- return $".{YooAssetSettingsData.Setting.AssetBundleFileVariant}";
- }
-
- ///
- /// 获取资源标记列表
+ /// 获取资源标签列表
///
public string[] GetAssetTags()
{
@@ -95,6 +84,17 @@ namespace YooAsset.Editor
return result.ToArray();
}
+ ///
+ /// 获取文件的扩展名
+ ///
+ public string GetAppendExtension()
+ {
+ if (IsRawFile)
+ return $".{YooAssetSettingsData.Setting.RawFileVariant}";
+ else
+ return $".{YooAssetSettingsData.Setting.AssetBundleFileVariant}";
+ }
+
///
/// 获取构建的资源路径列表
///
@@ -104,11 +104,11 @@ namespace YooAsset.Editor
}
///
- /// 获取主动收集的资源信息列表
+ /// 获取所有写入补丁清单的资源
///
- public BuildAssetInfo[] GetCollectAssetInfos()
+ public BuildAssetInfo[] GetAllPatchAssetInfos()
{
- return BuildinAssets.Where(t => t.IsCollectAsset).ToArray();
+ return BuildinAssets.Where(t => t.IsCollectAsset && t.NotWriteToAssetList == false).ToArray();
}
///
diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildMapContext.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildMapContext.cs
new file mode 100644
index 0000000..ea1363f
--- /dev/null
+++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildMapContext.cs
@@ -0,0 +1,113 @@
+using System;
+using System.Linq;
+using System.Collections;
+using System.Collections.Generic;
+using UnityEditor;
+
+namespace YooAsset.Editor
+{
+ public class BuildMapContext : IContextObject
+ {
+ ///
+ /// 参与构建的资源总数
+ /// 说明:包括主动收集的资源以及其依赖的所有资源
+ ///
+ public int AssetFileCount;
+
+ ///
+ /// 资源包列表
+ ///
+ public readonly List BundleInfos = new List(1000);
+
+
+ ///
+ /// 添加一个打包资源
+ ///
+ public void PackAsset(BuildAssetInfo assetInfo)
+ {
+ if (TryGetBundleInfo(assetInfo.BundleName, out BuildBundleInfo bundleInfo))
+ {
+ bundleInfo.PackAsset(assetInfo);
+ }
+ else
+ {
+ BuildBundleInfo newBundleInfo = new BuildBundleInfo(assetInfo.BundleName);
+ newBundleInfo.PackAsset(assetInfo);
+ BundleInfos.Add(newBundleInfo);
+ }
+ }
+
+ ///
+ /// 获取所有的打包资源
+ ///
+ public List GetAllAssets()
+ {
+ List result = new List(BundleInfos.Count);
+ foreach (var bundleInfo in BundleInfos)
+ {
+ result.AddRange(bundleInfo.BuildinAssets);
+ }
+ return result;
+ }
+
+ ///
+ /// 获取AssetBundle内包含的标记列表
+ ///
+ public string[] GetAssetTags(string bundleName)
+ {
+ if (TryGetBundleInfo(bundleName, out BuildBundleInfo bundleInfo))
+ {
+ return bundleInfo.GetAssetTags();
+ }
+ throw new Exception($"Not found {nameof(BuildBundleInfo)} : {bundleName}");
+ }
+
+ ///
+ /// 获取AssetBundle内构建的资源路径列表
+ ///
+ public string[] GetBuildinAssetPaths(string bundleName)
+ {
+ if (TryGetBundleInfo(bundleName, out BuildBundleInfo bundleInfo))
+ {
+ return bundleInfo.GetBuildinAssetPaths();
+ }
+ throw new Exception($"Not found {nameof(BuildBundleInfo)} : {bundleName}");
+ }
+
+ ///
+ /// 获取构建管线里需要的数据
+ ///
+ public UnityEditor.AssetBundleBuild[] GetPipelineBuilds()
+ {
+ List builds = new List(BundleInfos.Count);
+ foreach (var bundleInfo in BundleInfos)
+ {
+ if (bundleInfo.IsRawFile == false)
+ builds.Add(bundleInfo.CreatePipelineBuild());
+ }
+ return builds.ToArray();
+ }
+
+ ///
+ /// 是否包含资源包
+ ///
+ public bool IsContainsBundle(string bundleName)
+ {
+ return TryGetBundleInfo(bundleName, out BuildBundleInfo bundleInfo);
+ }
+
+ public bool TryGetBundleInfo(string bundleName, out BuildBundleInfo result)
+ {
+ foreach (var bundleInfo in BundleInfos)
+ {
+ if (bundleInfo.BundleName == bundleName)
+ {
+ result = bundleInfo;
+ return true;
+ }
+ }
+ result = null;
+ return false;
+ }
+ }
+}
\ No newline at end of file
diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildMapContext.cs.meta b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildMapContext.cs.meta
new file mode 100644
index 0000000..f70ef27
--- /dev/null
+++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildMapContext.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 8229aa3f8a369204db5c368715191e2f
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildMapHelper.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildMapHelper.cs
new file mode 100644
index 0000000..ff8e9a6
--- /dev/null
+++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildMapHelper.cs
@@ -0,0 +1,110 @@
+using System;
+using System.Linq;
+using System.Collections;
+using System.Collections.Generic;
+
+namespace YooAsset.Editor
+{
+ public static class BuildMapHelper
+ {
+ ///
+ /// 执行资源构建上下文
+ ///
+ public static BuildMapContext SetupBuildMap()
+ {
+ BuildMapContext context = new BuildMapContext();
+ Dictionary buildAssetDic = new Dictionary();
+
+ // 1. 获取主动收集的资源
+ List collectAssetInfos = AssetBundleGrouperSettingData.Setting.GetAllCollectAssets();
+
+ // 2. 录入主动收集的资源
+ foreach (var collectAssetInfo in collectAssetInfos)
+ {
+ if (buildAssetDic.ContainsKey(collectAssetInfo.AssetPath) == false)
+ {
+ var buildAssetInfo = new BuildAssetInfo(collectAssetInfo.AssetPath, collectAssetInfo.IsRawAsset, collectAssetInfo.NotWriteToAssetList);
+ buildAssetInfo.SetBundleName(collectAssetInfo.BundleName);
+ buildAssetInfo.AddAssetTags(collectAssetInfo.AssetTags);
+ buildAssetDic.Add(collectAssetInfo.AssetPath, buildAssetInfo);
+ }
+ else
+ {
+ throw new Exception($"Should never get here !");
+ }
+ }
+
+ // 3. 录入并分析依赖资源
+ foreach (var collectAssetInfo in collectAssetInfos)
+ {
+ foreach (var dependAssetPath in collectAssetInfo.DependAssets)
+ {
+ if (buildAssetDic.ContainsKey(dependAssetPath))
+ {
+ buildAssetDic[dependAssetPath].DependCount++;
+ buildAssetDic[dependAssetPath].AddAssetTags(collectAssetInfo.AssetTags);
+ }
+ else
+ {
+ var buildAssetInfo = new BuildAssetInfo(dependAssetPath);
+ buildAssetInfo.AddAssetTags(collectAssetInfo.AssetTags);
+ buildAssetDic.Add(dependAssetPath, buildAssetInfo);
+ }
+ }
+ }
+ context.AssetFileCount = buildAssetDic.Count;
+
+ // 4. 设置主动收集资源的依赖列表
+ foreach (var collectAssetInfo in collectAssetInfos)
+ {
+ var dependAssetInfos = new List(collectAssetInfo.DependAssets.Count);
+ foreach (var dependAssetPath in collectAssetInfo.DependAssets)
+ {
+ if (buildAssetDic.TryGetValue(dependAssetPath, out BuildAssetInfo value))
+ dependAssetInfos.Add(value);
+ else
+ throw new Exception("Should never get here !");
+ }
+ buildAssetDic[collectAssetInfo.AssetPath].SetAllDependAssetInfos(dependAssetInfos);
+ }
+
+ // 5. 移除零依赖的资源
+ List removeList = new List();
+ foreach (KeyValuePair pair in buildAssetDic)
+ {
+ var buildAssetInfo = pair.Value;
+ if (buildAssetInfo.IsCollectAsset)
+ continue;
+ if (buildAssetInfo.DependCount == 0)
+ removeList.Add(buildAssetInfo);
+ }
+ foreach (var removeValue in removeList)
+ {
+ buildAssetDic.Remove(removeValue.AssetPath);
+ }
+
+ // 6. 设置未命名的资源包
+ IPackRule defaultPackRule = new PackDirectory();
+ foreach (KeyValuePair pair in buildAssetDic)
+ {
+ var buildAssetInfo = pair.Value;
+ if (buildAssetInfo.BundleNameIsValid() == false)
+ {
+ string bundleName = defaultPackRule.GetBundleName(new PackRuleData(buildAssetInfo.AssetPath));
+ bundleName = AssetBundleCollector.RevisedBundleName(bundleName);
+ buildAssetInfo.SetBundleName(bundleName);
+ }
+ }
+
+ // 7. 构建资源包
+ var allBuildAssets = buildAssetDic.Values.ToList();
+ if (allBuildAssets.Count == 0)
+ throw new Exception("构建的资源列表不能为空");
+ foreach (var assetInfo in allBuildAssets)
+ {
+ context.PackAsset(assetInfo);
+ }
+ return context;
+ }
+ }
+}
\ No newline at end of file
diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildMapHelper.cs.meta b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildMapHelper.cs.meta
new file mode 100644
index 0000000..8827383
--- /dev/null
+++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildMapHelper.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: e9274735f1f14af4b893c21a4240b816
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildReport/BuildReport.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildReport/BuildReport.cs
index ef2d4c3..1f9feab 100644
--- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildReport/BuildReport.cs
+++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildReport/BuildReport.cs
@@ -26,16 +26,6 @@ namespace YooAsset.Editor
///
public List BundleInfos = new List();
- ///
- /// 收集器信息列表
- ///
- public List CollectorInfoList = new List();
-
- ///
- /// 冗余的资源列表
- ///
- public List RedundancyAssetList = new List();
-
///
/// 获取资源包信息类
diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildReport/ReportBundleInfo.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildReport/ReportBundleInfo.cs
index 06627c6..2fba0c0 100644
--- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildReport/ReportBundleInfo.cs
+++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildReport/ReportBundleInfo.cs
@@ -8,7 +8,7 @@ namespace YooAsset.Editor
public class ReportBundleInfo
{
///
- /// 资源包完整名称
+ /// 资源包名称
///
public string BundleName;
diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildReport/ReportSummary.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildReport/ReportSummary.cs
index ccd704f..92af5f4 100644
--- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildReport/ReportSummary.cs
+++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildReport/ReportSummary.cs
@@ -49,7 +49,7 @@ namespace YooAsset.Editor
public bool AutoCollectShaders;
///
- /// 自动收集的着色器资源包名
+ /// 自动收集的着色器资源包名称
///
public string ShadersBundleName;
@@ -74,7 +74,6 @@ namespace YooAsset.Editor
// 构建结果
public int AssetFileTotalCount;
- public int RedundancyAssetFileCount;
public int AllBundleTotalCount;
public long AllBundleTotalSize;
public int BuildinBundleTotalCount;
diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskBuilding.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskBuilding.cs
index fef5142..4de9dad 100644
--- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskBuilding.cs
+++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskBuilding.cs
@@ -18,7 +18,7 @@ namespace YooAsset.Editor
void IBuildTask.Run(BuildContext context)
{
var buildParametersContext = context.GetContextObject();
- var buildMapContext = context.GetContextObject();
+ var buildMapContext = context.GetContextObject();
Debug.Log($"开始构建......");
BuildAssetBundleOptions opt = buildParametersContext.GetPipelineBuildOptions();
@@ -57,7 +57,7 @@ namespace YooAsset.Editor
private void VerifyingBuildingResult(BuildContext context, AssetBundleManifest unityManifest)
{
var buildParameters = context.GetContextObject();
- var buildMapContext = context.GetContextObject();
+ var buildMapContext = context.GetContextObject();
string[] buildedBundles = unityManifest.GetAllAssetBundles();
// 1. 过滤掉原生Bundle
diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreatePatchManifest.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreatePatchManifest.cs
index 51e4266..d074821 100644
--- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreatePatchManifest.cs
+++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreatePatchManifest.cs
@@ -14,7 +14,7 @@ namespace YooAsset.Editor
{
var buildParameters = context.GetContextObject();
var encryptionContext = context.GetContextObject();
- var buildMapContext = context.GetContextObject();
+ var buildMapContext = context.GetContextObject();
CreatePatchManifestFile(buildParameters, buildMapContext, encryptionContext);
}
@@ -22,7 +22,7 @@ namespace YooAsset.Editor
/// 创建补丁清单文件到输出目录
///
private void CreatePatchManifestFile(AssetBundleBuilder.BuildParametersContext buildParameters,
- TaskGetBuildMap.BuildMapContext buildMapContext, TaskEncryption.EncryptionContext encryptionContext)
+ BuildMapContext buildMapContext, TaskEncryption.EncryptionContext encryptionContext)
{
// 创建新补丁清单
PatchManifest patchManifest = new PatchManifest();
@@ -47,7 +47,7 @@ namespace YooAsset.Editor
/// 获取资源包列表
///
private List GetAllPatchBundle(AssetBundleBuilder.BuildParametersContext buildParameters,
- TaskGetBuildMap.BuildMapContext buildMapContext, TaskEncryption.EncryptionContext encryptionContext)
+ BuildMapContext buildMapContext, TaskEncryption.EncryptionContext encryptionContext)
{
List result = new List(1000);
@@ -111,12 +111,12 @@ namespace YooAsset.Editor
///
/// 获取资源列表
///
- private List GetAllPatchAsset(TaskGetBuildMap.BuildMapContext buildMapContext, PatchManifest patchManifest)
+ private List GetAllPatchAsset(BuildMapContext buildMapContext, PatchManifest patchManifest)
{
List result = new List(1000);
foreach (var bundleInfo in buildMapContext.BundleInfos)
{
- var assetInfos = bundleInfo.GetCollectAssetInfos();
+ var assetInfos = bundleInfo.GetAllPatchAssetInfos();
foreach (var assetInfo in assetInfos)
{
PatchAsset patchAsset = new PatchAsset();
diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreateReport.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreateReport.cs
index 5919f2e..a5f9f1d 100644
--- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreateReport.cs
+++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreateReport.cs
@@ -12,11 +12,11 @@ namespace YooAsset.Editor
void IBuildTask.Run(BuildContext context)
{
var buildParameters = context.GetContextObject();
- var buildMapContext = context.GetContextObject();
+ var buildMapContext = context.GetContextObject();
CreateReportFile(buildParameters, buildMapContext);
}
- private void CreateReportFile(AssetBundleBuilder.BuildParametersContext buildParameters, TaskGetBuildMap.BuildMapContext buildMapContext)
+ private void CreateReportFile(AssetBundleBuilder.BuildParametersContext buildParameters, BuildMapContext buildMapContext)
{
PatchManifest patchManifest = AssetBundleBuilderHelper.LoadPatchManifestFile(buildParameters.PipelineOutputDirectory);
BuildReport buildReport = new BuildReport();
@@ -31,8 +31,8 @@ namespace YooAsset.Editor
buildReport.Summary.BuildVersion = buildParameters.Parameters.BuildVersion;
buildReport.Summary.EnableAutoCollect = buildParameters.Parameters.EnableAutoCollect;
buildReport.Summary.AppendFileExtension = buildParameters.Parameters.AppendFileExtension;
- buildReport.Summary.AutoCollectShaders = AssetBundleCollectorSettingData.Setting.AutoCollectShaders;
- buildReport.Summary.ShadersBundleName = AssetBundleCollectorSettingData.Setting.ShadersBundleName;
+ buildReport.Summary.AutoCollectShaders = AssetBundleGrouperSettingData.Setting.AutoCollectShaders;
+ buildReport.Summary.ShadersBundleName = AssetBundleGrouperSettingData.Setting.ShadersBundleName;
buildReport.Summary.EncryptionServicesClassName = buildParameters.Parameters.EncryptionServices == null ?
"null" : buildParameters.Parameters.EncryptionServices.GetType().FullName;
buildReport.Summary.RedundancyServicesClassName = buildParameters.Parameters.RedundancyServices == null ?
@@ -49,7 +49,6 @@ namespace YooAsset.Editor
// 构建结果
buildReport.Summary.AssetFileTotalCount = buildMapContext.AssetFileCount;
- buildReport.Summary.RedundancyAssetFileCount = buildMapContext.RedundancyAssetList.Count;
buildReport.Summary.AllBundleTotalCount = GetAllBundleCount(patchManifest);
buildReport.Summary.AllBundleTotalSize = GetAllBundleSize(patchManifest);
buildReport.Summary.BuildinBundleTotalCount = GetBuildinBundleCount(patchManifest);
@@ -58,8 +57,6 @@ namespace YooAsset.Editor
buildReport.Summary.EncryptedBundleTotalSize = GetEncryptedBundleSize(patchManifest);
buildReport.Summary.RawBundleTotalCount = GetRawBundleCount(patchManifest);
buildReport.Summary.RawBundleTotalSize = GetRawBundleSize(patchManifest);
-
-
}
// 资源对象列表
@@ -90,20 +87,6 @@ namespace YooAsset.Editor
buildReport.BundleInfos.Add(reportBundleInfo);
}
- // 收集器列表
- for (int i = 0; i < AssetBundleCollectorSettingData.Setting.Collectors.Count; i++)
- {
- var wrapper = AssetBundleCollectorSettingData.Setting.Collectors[i];
- buildReport.CollectorInfoList.Add(wrapper.ToString());
- }
-
- // 冗余资源列表
- for (int i = 0; i < buildMapContext.RedundancyAssetList.Count; i++)
- {
- string redundancyAssetPath = buildMapContext.RedundancyAssetList[i];
- buildReport.RedundancyAssetList.Add(redundancyAssetPath);
- }
-
// 删除旧文件
string filePath = $"{buildParameters.PipelineOutputDirectory}/{YooAssetSettings.ReportFileName}";
if (File.Exists(filePath))
@@ -130,7 +113,7 @@ namespace YooAsset.Editor
///
/// 获取资源对象依赖的其它所有资源
///
- private List GetDependAssets(TaskGetBuildMap.BuildMapContext buildMapContext, string bundleName, string assetPath)
+ private List GetDependAssets(BuildMapContext buildMapContext, string bundleName, string assetPath)
{
List result = new List();
if (buildMapContext.TryGetBundleInfo(bundleName, out BuildBundleInfo bundleInfo))
diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskEncryption.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskEncryption.cs
index 0dd04c3..e4e77ad 100644
--- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskEncryption.cs
+++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskEncryption.cs
@@ -24,7 +24,7 @@ namespace YooAsset.Editor
void IBuildTask.Run(BuildContext context)
{
var buildParameters = context.GetContextObject();
- var buildMapContext = context.GetContextObject();
+ var buildMapContext = context.GetContextObject();
EncryptionContext encryptionContext = new EncryptionContext();
encryptionContext.EncryptList = EncryptFiles(buildParameters, buildMapContext);
@@ -34,7 +34,7 @@ namespace YooAsset.Editor
///
/// 加密文件
///
- private List EncryptFiles(AssetBundleBuilder.BuildParametersContext buildParameters, TaskGetBuildMap.BuildMapContext buildMapContext)
+ private List EncryptFiles(AssetBundleBuilder.BuildParametersContext buildParameters, BuildMapContext buildMapContext)
{
var encryptionServices = buildParameters.Parameters.EncryptionServices;
diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskGetBuildMap.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskGetBuildMap.cs
index df63f23..fb0431b 100644
--- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskGetBuildMap.cs
+++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskGetBuildMap.cs
@@ -9,267 +9,15 @@ namespace YooAsset.Editor
{
public class TaskGetBuildMap : IBuildTask
{
- public class BuildMapContext : IContextObject
- {
- ///
- /// 参与构建的资源总数
- /// 说明:包括主动收集的资源以及其依赖的所有资源
- ///
- public int AssetFileCount;
-
- ///
- /// 资源包列表
- ///
- public readonly List BundleInfos = new List(1000);
-
- ///
- /// 冗余的资源列表
- ///
- public readonly List RedundancyAssetList = new List(1000);
-
-
- ///
- /// 添加一个打包资源
- ///
- public void PackAsset(BuildAssetInfo assetInfo)
- {
- if (TryGetBundleInfo(assetInfo.BundleName, out BuildBundleInfo bundleInfo))
- {
- bundleInfo.PackAsset(assetInfo);
- }
- else
- {
- BuildBundleInfo newBundleInfo = new BuildBundleInfo(assetInfo.BundleName);
- newBundleInfo.PackAsset(assetInfo);
- BundleInfos.Add(newBundleInfo);
- }
- }
-
- ///
- /// 获取所有的打包资源
- ///
- public List GetAllAssets()
- {
- List result = new List(BundleInfos.Count);
- foreach (var bundleInfo in BundleInfos)
- {
- result.AddRange(bundleInfo.BuildinAssets);
- }
- return result;
- }
-
- ///
- /// 获取AssetBundle内包含的标记列表
- ///
- public string[] GetAssetTags(string bundleFullName)
- {
- if (TryGetBundleInfo(bundleFullName, out BuildBundleInfo bundleInfo))
- {
- return bundleInfo.GetAssetTags();
- }
- throw new Exception($"Not found {nameof(BuildBundleInfo)} : {bundleFullName}");
- }
-
- ///
- /// 获取AssetBundle内构建的资源路径列表
- ///
- public string[] GetBuildinAssetPaths(string bundleFullName)
- {
- if (TryGetBundleInfo(bundleFullName, out BuildBundleInfo bundleInfo))
- {
- return bundleInfo.GetBuildinAssetPaths();
- }
- throw new Exception($"Not found {nameof(BuildBundleInfo)} : {bundleFullName}");
- }
-
- ///
- /// 获取构建管线里需要的数据
- ///
- public UnityEditor.AssetBundleBuild[] GetPipelineBuilds()
- {
- List builds = new List(BundleInfos.Count);
- foreach (var bundleInfo in BundleInfos)
- {
- if (bundleInfo.IsRawFile == false)
- builds.Add(bundleInfo.CreatePipelineBuild());
- }
- return builds.ToArray();
- }
-
- ///
- /// 是否包含资源包
- ///
- public bool IsContainsBundle(string bundleFullName)
- {
- return TryGetBundleInfo(bundleFullName, out BuildBundleInfo bundleInfo);
- }
-
- public bool TryGetBundleInfo(string bundleFullName, out BuildBundleInfo result)
- {
- foreach (var bundleInfo in BundleInfos)
- {
- if (bundleInfo.BundleName == bundleFullName)
- {
- result = bundleInfo;
- return true;
- }
- }
- result = null;
- return false;
- }
- }
-
-
void IBuildTask.Run(BuildContext context)
{
- var buildParametersContext = context.GetContextObject();
- BuildMapContext buildMapContext = new BuildMapContext();
+ var buildMapContext = BuildMapHelper.SetupBuildMap();
context.SetContextObject(buildMapContext);
- SetupBuildMap(buildMapContext, buildParametersContext);
// 检测构建结果
CheckBuildMapContent(buildMapContext);
}
- ///
- /// 组织构建的资源包
- ///
- private void SetupBuildMap(BuildMapContext buildMapContext, AssetBundleBuilder.BuildParametersContext buildParameters)
- {
- Dictionary buildAssetDic = new Dictionary();
-
- // 1. 获取主动收集的资源
- List allCollectInfos = AssetBundleCollectorSettingData.GetAllCollectAssets();
-
- // 2. 对收集的资源进行依赖分析
- int progressValue = 0;
- foreach (CollectAssetInfo collectInfo in allCollectInfos)
- {
- string mainAssetPath = collectInfo.AssetPath;
-
- // 获取所有依赖资源
- List depends = GetAllDependencies(mainAssetPath);
- for (int i = 0; i < depends.Count; i++)
- {
- string assetPath = depends[i].AssetPath;
-
- // 如果已经存在,则增加该资源的依赖计数
- if (buildAssetDic.ContainsKey(assetPath))
- buildAssetDic[assetPath].DependCount++;
- else
- buildAssetDic.Add(assetPath, depends[i]);
-
- // 添加资源标记
- buildAssetDic[assetPath].AddAssetTags(collectInfo.AssetTags);
-
- // 注意:检测是否为主动收集资源
- if (assetPath == mainAssetPath)
- {
- buildAssetDic[mainAssetPath].IsCollectAsset = true;
- buildAssetDic[mainAssetPath].IsRawAsset = collectInfo.IsRawAsset;
- }
- }
-
- // 添加所有的依赖资源列表
- // 注意:不包括自己
- var allDependAssetInfos = new List(depends.Count);
- for (int i = 0; i < depends.Count; i++)
- {
- string assetPath = depends[i].AssetPath;
- if (assetPath != mainAssetPath)
- allDependAssetInfos.Add(buildAssetDic[assetPath]);
- }
- buildAssetDic[mainAssetPath].SetAllDependAssetInfos(allDependAssetInfos);
-
- EditorTools.DisplayProgressBar("依赖文件分析", ++progressValue, allCollectInfos.Count);
- }
- EditorTools.ClearProgressBar();
-
- // 3. 记录参与构建的资源总数
- buildMapContext.AssetFileCount = buildAssetDic.Values.Count;
-
- // 4. 移除零依赖的资源
- var redundancyServices = buildParameters.Parameters.RedundancyServices;
- List undependentAssets = new List();
- foreach (KeyValuePair pair in buildAssetDic)
- {
- var buildAssetInfo = pair.Value;
- if (buildAssetInfo.IsCollectAsset)
- continue;
-
- // 零依赖资源
- if (buildAssetInfo.DependCount == 0)
- {
- undependentAssets.Add(buildAssetInfo);
- continue;
- }
-
- // 冗余扩展
- if (redundancyServices != null && redundancyServices.Check(buildAssetInfo.AssetPath))
- {
- undependentAssets.Add(buildAssetInfo);
- buildMapContext.RedundancyAssetList.Add(buildAssetInfo.AssetPath);
- continue;
- }
-
- // 如果没有开启自动分包,没有被收集到的资源会造成冗余
- if (buildParameters.Parameters.EnableAutoCollect == false)
- {
- if (AssetBundleCollectorSettingData.HasCollector(buildAssetInfo.AssetPath) == false)
- {
- undependentAssets.Add(buildAssetInfo);
- buildMapContext.RedundancyAssetList.Add(buildAssetInfo.AssetPath);
- }
- }
- }
- foreach (var assetInfo in undependentAssets)
- {
- buildAssetDic.Remove(assetInfo.AssetPath);
- }
-
- // 5. 设置资源包名
- progressValue = 0;
- foreach (KeyValuePair pair in buildAssetDic)
- {
- var assetInfo = pair.Value;
- var bundleLabel = AssetBundleCollectorSettingData.GetBundleLabel(assetInfo.AssetPath);
- if (assetInfo.IsRawAsset)
- assetInfo.SetBundleLabelAndVariant(bundleLabel, YooAssetSettingsData.Setting.RawFileVariant);
- else
- assetInfo.SetBundleLabelAndVariant(bundleLabel, YooAssetSettingsData.Setting.AssetBundleFileVariant);
- EditorTools.DisplayProgressBar("设置资源包名", ++progressValue, buildAssetDic.Count);
- }
- EditorTools.ClearProgressBar();
-
- // 6. 构建资源包
- var allAssets = buildAssetDic.Values.ToList();
- if (allAssets.Count == 0)
- throw new Exception("构建的资源列表不能为空");
- foreach (var assetInfo in allAssets)
- {
- buildMapContext.PackAsset(assetInfo);
- }
- }
-
- ///
- /// 获取指定资源依赖的所有资源列表
- /// 注意:返回列表里已经包括主资源自己
- ///
- private List GetAllDependencies(string mainAssetPath)
- {
- List result = new List();
- string[] depends = AssetDatabase.GetDependencies(mainAssetPath, true);
- foreach (string assetPath in depends)
- {
- if (AssetBundleCollectorSettingData.IsValidateAsset(assetPath))
- {
- BuildAssetInfo assetInfo = new BuildAssetInfo(assetPath);
- result.Add(assetInfo);
- }
- }
- return result;
- }
-
///
/// 检测构建结果
///
diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskPrepare.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskPrepare.cs
index f8f6c26..94f11e6 100644
--- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskPrepare.cs
+++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskPrepare.cs
@@ -25,10 +25,6 @@ namespace YooAsset.Editor
if (string.IsNullOrEmpty(buildParameters.PipelineOutputDirectory))
throw new Exception("输出目录不能为空");
- // 检测资源收集配置文件
- if (AssetBundleCollectorSettingData.GetCollecterCount() == 0)
- throw new Exception("配置的资源收集路径为空");
-
// 增量更新时候的必要检测
if (buildParameters.Parameters.ForceRebuild == false)
{
@@ -46,10 +42,10 @@ namespace YooAsset.Editor
if (Directory.Exists(packageDirectory))
throw new Exception($"补丁包已经存在:{packageDirectory}");
- // 检测内置资源标记是否一致
+ // 检测内置资源分类标签是否一致
PatchManifest oldPatchManifest = AssetBundleBuilderHelper.LoadPatchManifestFile(buildParameters.PipelineOutputDirectory);
if (buildParameters.Parameters.BuildinTags != oldPatchManifest.BuildinTags)
- throw new Exception($"增量更新时内置资源标记必须一致:{buildParameters.Parameters.BuildinTags} != {oldPatchManifest.BuildinTags}");
+ throw new Exception($"增量更新时内置资源标签必须一致:{buildParameters.Parameters.BuildinTags} != {oldPatchManifest.BuildinTags}");
}
// 如果是强制重建