Update AssetBundleBuilder

pull/40/head
hevinci 2022-09-27 10:40:29 +08:00
parent f0ac319a73
commit 50bfde6e8e
7 changed files with 79 additions and 10 deletions

View File

@ -20,6 +20,11 @@ namespace YooAsset.Editor
/// </summary>
public EBuildMode BuildMode = EBuildMode.ForceRebuild;
/// <summary>
/// 构建的包裹名称
/// </summary>
public string BuildPackage = string.Empty;
/// <summary>
/// 内置资源标签(首包资源标签)
/// </summary>

View File

@ -21,6 +21,7 @@ namespace YooAsset.Editor
private BuildTarget _buildTarget;
private List<Type> _encryptionServicesClassTypes;
private List<string> _encryptionServicesClassNames;
private List<string> _buildPackageNames;
private Button _saveButton;
private TextField _buildOutputField;
@ -28,6 +29,7 @@ namespace YooAsset.Editor
private EnumField _buildPipelineField;
private EnumField _buildModeField;
private TextField _buildinTagsField;
private PopupField<string> _buildPackageField;
private PopupField<string> _encryptionField;
private EnumField _compressionField;
private EnumField _outputNameStyleField;
@ -52,6 +54,9 @@ namespace YooAsset.Editor
// 构建平台
_buildTarget = EditorUserBuildSettings.activeBuildTarget;
// 包裹名称列表
_buildPackageNames = GetBuildPackageNames();
// 加密服务类
_encryptionServicesClassTypes = GetEncryptionServicesClassTypes();
_encryptionServicesClassNames = _encryptionServicesClassTypes.Select(t => t.FullName).ToList();
@ -105,11 +110,34 @@ namespace YooAsset.Editor
AssetBundleBuilderSettingData.Setting.BuildTags = _buildinTagsField.value;
});
// 构建包裹
var buildPackageContainer = root.Q("BuildPackageContainer");
if (_buildPackageNames.Count > 0)
{
int defaultIndex = GetDefaultPackageIndex(AssetBundleBuilderSettingData.Setting.BuildPackage);
_buildPackageField = new PopupField<string>(_buildPackageNames, defaultIndex);
_buildPackageField.label = "Build Package";
_buildPackageField.style.width = 350;
_buildPackageField.RegisterValueChangedCallback(evt =>
{
AssetBundleBuilderSettingData.IsDirty = true;
AssetBundleBuilderSettingData.Setting.BuildPackage = _buildPackageField.value;
});
buildPackageContainer.Add(_buildPackageField);
}
else
{
_buildPackageField = new PopupField<string>();
_buildPackageField.label = "Build Package";
_buildPackageField.style.width = 350;
buildPackageContainer.Add(_buildPackageField);
}
// 加密方法
var encryptionContainer = root.Q("EncryptionContainer");
if (_encryptionServicesClassNames.Count > 0)
{
int defaultIndex = GetEncryptionDefaultIndex(AssetBundleBuilderSettingData.Setting.EncyptionClassName);
int defaultIndex = GetDefaultEncryptionIndex(AssetBundleBuilderSettingData.Setting.EncyptionClassName);
_encryptionField = new PopupField<string>(_encryptionServicesClassNames, defaultIndex);
_encryptionField.label = "Encryption";
_encryptionField.style.width = 350;
@ -163,21 +191,21 @@ namespace YooAsset.Editor
}
public void OnDestroy()
{
if(AssetBundleBuilderSettingData.IsDirty)
if (AssetBundleBuilderSettingData.IsDirty)
AssetBundleBuilderSettingData.SaveFile();
}
public void Update()
{
if(_saveButton != null)
if (_saveButton != null)
{
if(AssetBundleBuilderSettingData.IsDirty)
if (AssetBundleBuilderSettingData.IsDirty)
{
if (_saveButton.enabledSelf == false)
_saveButton.SetEnabled(true);
}
else
{
if(_saveButton.enabledSelf)
if (_saveButton.enabledSelf)
_saveButton.SetEnabled(false);
}
}
@ -222,6 +250,7 @@ namespace YooAsset.Editor
buildParameters.BuildPipeline = AssetBundleBuilderSettingData.Setting.BuildPipeline;
buildParameters.BuildMode = AssetBundleBuilderSettingData.Setting.BuildMode;
buildParameters.BuildVersion = AssetBundleBuilderSettingData.Setting.BuildVersion;
buildParameters.BuildPackage = AssetBundleBuilderSettingData.Setting.BuildPackage;
buildParameters.BuildinTags = AssetBundleBuilderSettingData.Setting.BuildTags;
buildParameters.VerifyBuildingResult = true;
buildParameters.EnableAddressable = AssetBundleCollectorSettingData.Setting.EnableAddressable;
@ -244,8 +273,33 @@ namespace YooAsset.Editor
}
}
// 构建包裹相关
private int GetDefaultPackageIndex(string packageName)
{
for (int index = 0; index < _buildPackageNames.Count; index++)
{
if (_buildPackageNames[index] == packageName)
{
return index;
}
}
AssetBundleBuilderSettingData.IsDirty = true;
AssetBundleBuilderSettingData.Setting.BuildPackage = _buildPackageNames[0];
return 0;
}
private List<string> GetBuildPackageNames()
{
List<string> result = new List<string>();
foreach (var package in AssetBundleCollectorSettingData.Setting.Packages)
{
result.Add(package.PackageName);
}
return result;
}
// 加密类相关
private int GetEncryptionDefaultIndex(string className)
private int GetDefaultEncryptionIndex(string className)
{
for (int index = 0; index < _encryptionServicesClassNames.Count; index++)
{
@ -254,6 +308,9 @@ namespace YooAsset.Editor
return index;
}
}
AssetBundleBuilderSettingData.IsDirty = true;
AssetBundleBuilderSettingData.Setting.EncyptionClassName = _encryptionServicesClassNames[0];
return 0;
}
private List<Type> GetEncryptionServicesClassTypes()

View File

@ -7,6 +7,7 @@
<uie:IntegerField label="Build Version" value="0" name="BuildVersion" />
<uie:EnumField label="Build Pipeline" name="BuildPipeline" />
<uie:EnumField label="Build Mode" name="BuildMode" />
<ui:VisualElement name="BuildPackageContainer" style="height: 24px;" />
<ui:VisualElement name="EncryptionContainer" style="height: 24px;" />
<uie:EnumField label="Compression" value="Center" name="Compression" />
<uie:EnumField label="Output Name Style" value="Center" name="OutputNameStyle" />

View File

@ -17,6 +17,7 @@ namespace YooAsset.Editor
buildParameters.BuildTarget = EditorUserBuildSettings.activeBuildTarget;
buildParameters.BuildMode = EBuildMode.SimulateBuild;
buildParameters.BuildVersion = 999;
buildParameters.BuildPackage = AssetBundleBuilderSettingData.Setting.BuildPackage;
buildParameters.EnableAddressable = AssetBundleCollectorSettingData.Setting.EnableAddressable;
AssetBundleBuilder builder = new AssetBundleBuilder();

View File

@ -10,7 +10,7 @@ namespace YooAsset.Editor
/// <summary>
/// 执行资源构建上下文
/// </summary>
public static BuildMapContext CreateBuildMap(EBuildMode buildMode)
public static BuildMapContext CreateBuildMap(EBuildMode buildMode, string packageName)
{
BuildMapContext context = new BuildMapContext();
Dictionary<string, BuildAssetInfo> buildAssetDic = new Dictionary<string, BuildAssetInfo>(1000);
@ -19,7 +19,7 @@ namespace YooAsset.Editor
AssetBundleCollectorSettingData.Setting.CheckConfigError();
// 2. 获取所有收集器收集的资源
List<CollectAssetInfo> allCollectAssets = AssetBundleCollectorSettingData.Setting.GetAllCollectAssets(buildMode);
List<CollectAssetInfo> allCollectAssets = AssetBundleCollectorSettingData.Setting.GetPackageAssets(buildMode, packageName);
// 3. 剔除未被引用的依赖资源
List<CollectAssetInfo> removeDependList = new List<CollectAssetInfo>();

View File

@ -56,6 +56,11 @@ namespace YooAsset.Editor
/// </summary>
public EBuildMode BuildMode;
/// <summary>
/// 构建的Package名称
/// </summary>
public string BuildPackage;
/// <summary>
/// 构建的版本(资源版本号)
/// </summary>

View File

@ -13,7 +13,7 @@ namespace YooAsset.Editor
void IBuildTask.Run(BuildContext context)
{
var buildParametersContext = context.GetContextObject<BuildParametersContext>();
var buildMapContext = BuildMapCreater.CreateBuildMap(buildParametersContext.Parameters.BuildMode);
var buildMapContext = BuildMapCreater.CreateBuildMap(buildParametersContext.Parameters.BuildMode, buildParametersContext.Parameters.BuildPackage);
context.SetContextObject(buildMapContext);
BuildRunner.Log("构建内容准备完毕!");