Update AssetBundleBuilder

pull/51/head
hevinci 2022-10-19 15:54:59 +08:00
parent 2fb77c1bf8
commit 958cdd25a5
9 changed files with 48 additions and 26 deletions

View File

@ -257,7 +257,6 @@ namespace YooAsset.Editor
buildParameters.BuildMode = AssetBundleBuilderSettingData.Setting.BuildMode;
buildParameters.BuildPackage = AssetBundleBuilderSettingData.Setting.BuildPackage;
buildParameters.VerifyBuildingResult = true;
buildParameters.EnableAddressable = AssetBundleCollectorSettingData.Setting.EnableAddressable;
buildParameters.EncryptionServices = CreateEncryptionServicesInstance();
buildParameters.CompressOption = AssetBundleBuilderSettingData.Setting.CompressOption;
buildParameters.OutputNameStyle = AssetBundleBuilderSettingData.Setting.OutputNameStyle;

View File

@ -15,7 +15,6 @@ namespace YooAsset.Editor
buildParameters.BuildTarget = EditorUserBuildSettings.activeBuildTarget;
buildParameters.BuildMode = EBuildMode.SimulateBuild;
buildParameters.BuildPackage = packageName;
buildParameters.EnableAddressable = AssetBundleCollectorSettingData.Setting.EnableAddressable;
AssetBundleBuilder builder = new AssetBundleBuilder();
var buildResult = builder.Run(buildParameters);

View File

@ -166,7 +166,7 @@ namespace YooAsset.Editor
/// <summary>
/// 计算主资源或共享资源的完整包名
/// </summary>
public void CalculateFullBundleName()
public void CalculateFullBundleName(bool uniqueBundleName, string packageName)
{
if (CollectorType == ECollectorType.None)
{
@ -177,15 +177,22 @@ namespace YooAsset.Editor
{
string shareBundleName = YooAssetSettingsData.GetUnityShadersBundleFullName();
_shareBundleName = EditorTools.GetRegularPath(shareBundleName).ToLower();
return;
}
else
{
if (_referenceBundleNames.Count > 1)
{
IPackRule packRule = PackDirectory.StaticPackRule;
var bundleName = packRule.GetBundleName(new PackRuleData(AssetPath));
var shareBundleName = $"share_{bundleName}.{YooAssetSettingsData.Setting.AssetBundleFileVariant}";
_shareBundleName = EditorTools.GetRegularPath(shareBundleName).ToLower();
}
}
if (_referenceBundleNames.Count > 1)
if (uniqueBundleName)
{
IPackRule packRule = PackDirectory.StaticPackRule;
var bundleName = packRule.GetBundleName(new PackRuleData(AssetPath));
var shareBundleName = $"share_{bundleName}.{YooAssetSettingsData.Setting.AssetBundleFileVariant}";
_shareBundleName = EditorTools.GetRegularPath(shareBundleName).ToLower();
if (string.IsNullOrEmpty(_shareBundleName) == false)
_shareBundleName = $"{packageName.ToLower()}_{_shareBundleName}";
}
}
else

View File

@ -14,6 +14,16 @@ namespace YooAsset.Editor
/// </summary>
public int AssetFileCount;
/// <summary>
/// 是否启用可寻址资源定位
/// </summary>
public bool EnableAddressable;
/// <summary>
/// 资源包名唯一化
/// </summary>
public bool UniqueBundleName;
/// <summary>
/// 资源包列表
/// </summary>

View File

@ -19,7 +19,8 @@ namespace YooAsset.Editor
AssetBundleCollectorSettingData.Setting.CheckConfigError();
// 2. 获取所有收集器收集的资源
List<CollectAssetInfo> allCollectAssets = AssetBundleCollectorSettingData.Setting.GetPackageAssets(buildMode, packageName);
var buildResult = AssetBundleCollectorSettingData.Setting.GetPackageAssets(buildMode, packageName);
List<CollectAssetInfo> allCollectAssets = buildResult.CollectAssets;
// 3. 剔除未被引用的依赖资源
List<CollectAssetInfo> removeDependList = new List<CollectAssetInfo>();
@ -72,9 +73,13 @@ namespace YooAsset.Editor
}
}
}
context.AssetFileCount = buildAssetDic.Count;
// 6. 填充主动收集资源的依赖列表
// 6. 记录关键信息
context.AssetFileCount = buildAssetDic.Count;
context.EnableAddressable = buildResult.EnableAddressable;
context.UniqueBundleName = buildResult.UniqueBundleName;
// 7. 填充主动收集资源的依赖列表
foreach (var collectAssetInfo in allCollectAssets)
{
var dependAssetInfos = new List<BuildAssetInfo>(collectAssetInfo.DependAssets.Count);
@ -88,13 +93,13 @@ namespace YooAsset.Editor
buildAssetDic[collectAssetInfo.AssetPath].SetAllDependAssetInfos(dependAssetInfos);
}
// 7. 计算完整的资源包名
// 8. 计算完整的资源包名
foreach (KeyValuePair<string, BuildAssetInfo> pair in buildAssetDic)
{
pair.Value.CalculateFullBundleName();
pair.Value.CalculateFullBundleName(buildResult.UniqueBundleName, buildResult.PackageName);
}
// 8. 移除不参与构建的资源
// 9. 移除不参与构建的资源
List<BuildAssetInfo> removeBuildList = new List<BuildAssetInfo>();
foreach (KeyValuePair<string, BuildAssetInfo> pair in buildAssetDic)
{
@ -107,7 +112,7 @@ namespace YooAsset.Editor
buildAssetDic.Remove(removeValue.AssetPath);
}
// 9. 构建资源包
// 10. 构建资源包
var allBuildinAssets = buildAssetDic.Values.ToList();
if (allBuildinAssets.Count == 0)
throw new Exception("构建的资源列表不能为空");

View File

@ -72,11 +72,6 @@ namespace YooAsset.Editor
/// </summary>
public bool VerifyBuildingResult = false;
/// <summary>
/// 启用可寻址资源定位
/// </summary>
public bool EnableAddressable = false;
/// <summary>
/// 加密类
/// </summary>

View File

@ -53,6 +53,11 @@ namespace YooAsset.Editor
/// </summary>
public bool EnableAddressable;
/// <summary>
/// 资源包名唯一化
/// </summary>
public bool UniqueBundleName;
/// <summary>
/// 加密服务类名称
/// </summary>

View File

@ -21,6 +21,7 @@ namespace YooAsset.Editor
/// </summary>
private void CreatePatchManifestFile(BuildContext context)
{
var buildMapContext = context.GetContextObject<BuildMapContext>();
var buildParametersContext = context.GetContextObject<BuildParametersContext>();
var buildParameters = buildParametersContext.Parameters;
string pipelineOutputDirectory = buildParametersContext.GetPipelineOutputDirectory();
@ -28,7 +29,7 @@ namespace YooAsset.Editor
// 创建新补丁清单
PatchManifest patchManifest = new PatchManifest();
patchManifest.FileVersion = YooAssetSettings.PatchManifestFileVersion;
patchManifest.EnableAddressable = buildParameters.EnableAddressable;
patchManifest.EnableAddressable = buildMapContext.EnableAddressable;
patchManifest.OutputNameStyle = (int)buildParameters.OutputNameStyle;
patchManifest.PackageName = buildParameters.BuildPackage;
patchManifest.HumanReadableVersion = buildParameters.HumanReadableVersion;
@ -125,7 +126,6 @@ namespace YooAsset.Editor
/// </summary>
private List<PatchAsset> GetAllPatchAsset(BuildContext context, PatchManifest patchManifest)
{
var buildParameters = context.GetContextObject<BuildParametersContext>();
var buildMapContext = context.GetContextObject<BuildMapContext>();
List<PatchAsset> result = new List<PatchAsset>(1000);
@ -135,7 +135,7 @@ namespace YooAsset.Editor
foreach (var assetInfo in assetInfos)
{
PatchAsset patchAsset = new PatchAsset();
if (buildParameters.Parameters.EnableAddressable)
if (buildMapContext.EnableAddressable)
patchAsset.Address = assetInfo.Address;
else
patchAsset.Address = string.Empty;

View File

@ -46,7 +46,9 @@ namespace YooAsset.Editor
buildReport.Summary.BuildPipeline = buildParameters.BuildPipeline;
buildReport.Summary.BuildMode = buildParameters.BuildMode;
buildReport.Summary.BuildPackage = buildParameters.BuildPackage;
buildReport.Summary.EnableAddressable = buildParameters.EnableAddressable;
buildReport.Summary.EnableAddressable = buildMapContext.EnableAddressable;
buildReport.Summary.UniqueBundleName = buildMapContext.UniqueBundleName;
buildReport.Summary.EncryptionServicesClassName = buildParameters.EncryptionServices == null ?
"null" : buildParameters.EncryptionServices.GetType().FullName;