diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderSetting.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderSetting.cs index c179c05..8b0c8fd 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderSetting.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderSetting.cs @@ -20,6 +20,11 @@ namespace YooAsset.Editor /// public EBuildMode BuildMode = EBuildMode.ForceRebuild; + /// + /// 构建的包裹名称 + /// + public string BuildPackage = string.Empty; + /// /// 内置资源标签(首包资源标签) /// diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderWindow.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderWindow.cs index 3b29c54..48bd8ac 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderWindow.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderWindow.cs @@ -21,6 +21,7 @@ namespace YooAsset.Editor private BuildTarget _buildTarget; private List _encryptionServicesClassTypes; private List _encryptionServicesClassNames; + private List _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 _buildPackageField; private PopupField _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(_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(); + _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(_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; @@ -235,7 +264,7 @@ namespace YooAsset.Editor buildParameters.SBPParameters = new BuildParameters.SBPBuildParameters(); buildParameters.SBPParameters.WriteLinkXML = true; } - + var builder = new AssetBundleBuilder(); var buildResult = builder.Run(buildParameters); if (buildResult.Success) @@ -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 GetBuildPackageNames() + { + List result = new List(); + 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 GetEncryptionServicesClassTypes() diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderWindow.uxml b/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderWindow.uxml index 81e2c2b..67006da 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderWindow.uxml +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleBuilderWindow.uxml @@ -7,6 +7,7 @@ + diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleSimulateBuilder.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleSimulateBuilder.cs index ca027d2..b9a556f 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleSimulateBuilder.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/AssetBundleSimulateBuilder.cs @@ -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(); diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildMapCreater.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildMapCreater.cs index 4a1ac2b..0624bd1 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildMapCreater.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildMapCreater.cs @@ -10,7 +10,7 @@ namespace YooAsset.Editor /// /// 执行资源构建上下文 /// - public static BuildMapContext CreateBuildMap(EBuildMode buildMode) + public static BuildMapContext CreateBuildMap(EBuildMode buildMode, string packageName) { BuildMapContext context = new BuildMapContext(); Dictionary buildAssetDic = new Dictionary(1000); @@ -19,7 +19,7 @@ namespace YooAsset.Editor AssetBundleCollectorSettingData.Setting.CheckConfigError(); // 2. 获取所有收集器收集的资源 - List allCollectAssets = AssetBundleCollectorSettingData.Setting.GetAllCollectAssets(buildMode); + List allCollectAssets = AssetBundleCollectorSettingData.Setting.GetPackageAssets(buildMode, packageName); // 3. 剔除未被引用的依赖资源 List removeDependList = new List(); diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildParameters.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildParameters.cs index bcaa536..1cad106 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildParameters.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildParameters.cs @@ -56,6 +56,11 @@ namespace YooAsset.Editor /// public EBuildMode BuildMode; + /// + /// 构建的Package名称 + /// + public string BuildPackage; + /// /// 构建的版本(资源版本号) /// diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskGetBuildMap.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskGetBuildMap.cs index b334606..da19d6a 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskGetBuildMap.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskGetBuildMap.cs @@ -13,7 +13,7 @@ namespace YooAsset.Editor void IBuildTask.Run(BuildContext context) { var buildParametersContext = context.GetContextObject(); - var buildMapContext = BuildMapCreater.CreateBuildMap(buildParametersContext.Parameters.BuildMode); + var buildMapContext = BuildMapCreater.CreateBuildMap(buildParametersContext.Parameters.BuildMode, buildParametersContext.Parameters.BuildPackage); context.SetContextObject(buildMapContext); BuildRunner.Log("构建内容准备完毕!");