From 43db19c257f450cf10daa4380f5c671f35766b99 Mon Sep 17 00:00:00 2001 From: hevinci Date: Mon, 26 Jun 2023 17:40:47 +0800 Subject: [PATCH] update editor code --- .../AssetBundleBuilder/BuildAssetInfo.cs | 7 +++ .../AssetBundleBuilder/BuildMapContext.cs | 14 +----- .../BuildReport/ReportSummary.cs | 10 +++++ .../BuildTasks/TaskBuilding_SBP.cs | 4 +- .../BuildTasks/TaskCreateManifest.cs | 12 ++--- .../BuildTasks/TaskCreateReport.cs | 6 ++- .../BuildTasks/TaskGetBuildMap.cs | 4 +- .../AssetBundleCollectorConfig.cs | 39 +++++++++------- .../AssetBundleCollectorSetting.cs | 22 ++++++++-- .../AssetBundleCollectorSettingData.cs | 10 +++++ .../AssetBundleCollectorWindow.cs | 44 ++++++++++++++++++- .../AssetBundleCollectorWindow.uxml | 19 +++++--- .../AssetBundleCollector/CollectCommand.cs | 16 ++++++- .../VisualViewers/ReporterSummaryViewer.cs | 2 + 14 files changed, 155 insertions(+), 54 deletions(-) diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildAssetInfo.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildAssetInfo.cs index 0547e34..edcd282 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildAssetInfo.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildAssetInfo.cs @@ -30,6 +30,11 @@ namespace YooAsset.Editor /// public string AssetPath { private set; get; } + /// + /// 资源GUID + /// + public string AssetGUID { private set; get; } + /// /// 是否为原生资源 /// @@ -65,6 +70,7 @@ namespace YooAsset.Editor AssetPath = assetPath; IsRawAsset = isRawAsset; + AssetGUID = UnityEditor.AssetDatabase.AssetPathToGUID(assetPath); System.Type assetType = UnityEditor.AssetDatabase.GetMainAssetTypeAtPath(assetPath); if (assetType == typeof(UnityEngine.Shader) || assetType == typeof(UnityEngine.ShaderVariantCollection)) IsShaderAsset = true; @@ -78,6 +84,7 @@ namespace YooAsset.Editor AssetPath = assetPath; IsRawAsset = false; + AssetGUID = UnityEditor.AssetDatabase.AssetPathToGUID(assetPath); System.Type assetType = UnityEditor.AssetDatabase.GetMainAssetTypeAtPath(assetPath); if (assetType == typeof(UnityEngine.Shader) || assetType == typeof(UnityEngine.ShaderVariantCollection)) IsShaderAsset = true; diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildMapContext.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildMapContext.cs index 3c4e592..3cce1be 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildMapContext.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildMapContext.cs @@ -22,19 +22,9 @@ namespace YooAsset.Editor public int AssetFileCount; /// - /// 是否启用可寻址资源定位 + /// 收集命令 /// - public bool EnableAddressable; - - /// - /// 资源包名唯一化 - /// - public bool UniqueBundleName; - - /// - /// 着色器统一的全名称 - /// - public string ShadersBundleName; + public CollectCommand Command { set; get; } /// /// 资源包信息列表 diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildReport/ReportSummary.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildReport/ReportSummary.cs index 509fa3c..26def14 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildReport/ReportSummary.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildReport/ReportSummary.cs @@ -58,6 +58,16 @@ namespace YooAsset.Editor /// public bool EnableAddressable; + /// + /// 资源定位地址大小写不敏感 + /// + public bool LocationToLower; + + /// + /// 包含资源GUID数据 + /// + public bool IncludeAssetGUID; + /// /// 资源包名唯一化 /// diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskBuilding_SBP.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskBuilding_SBP.cs index 4947601..a45feb8 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskBuilding_SBP.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskBuilding_SBP.cs @@ -33,7 +33,7 @@ namespace YooAsset.Editor // 开始构建 IBundleBuildResults buildResults; var buildParameters = buildParametersContext.GetSBPBuildParameters(); - var taskList = SBPBuildTasks.Create(buildMapContext.ShadersBundleName); + var taskList = SBPBuildTasks.Create(buildMapContext.Command.ShadersBundleName); ReturnCode exitCode = ContentPipeline.BuildAssetBundles(buildParameters, buildContent, out buildResults, taskList); if (exitCode < 0) { @@ -43,7 +43,7 @@ namespace YooAsset.Editor // 创建着色器信息 // 说明:解决因为着色器资源包导致验证失败。 // 例如:当项目里没有着色器,如果有依赖内置着色器就会验证失败。 - string shadersBundleName = buildMapContext.ShadersBundleName; + string shadersBundleName = buildMapContext.Command.ShadersBundleName; if (buildResults.BundleInfos.ContainsKey(shadersBundleName)) { buildMapContext.CreateShadersBundleInfo(shadersBundleName); diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreateManifest.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreateManifest.cs index ec7c193..77581e7 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreateManifest.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreateManifest.cs @@ -34,7 +34,9 @@ namespace YooAsset.Editor // 创建新补丁清单 PackageManifest manifest = new PackageManifest(); manifest.FileVersion = YooAssetSettings.ManifestFileVersion; - manifest.EnableAddressable = buildMapContext.EnableAddressable; + manifest.EnableAddressable = buildMapContext.Command.EnableAddressable; + manifest.LocationToLower = buildMapContext.Command.LocationToLower; + manifest.IncludeAssetGUID = buildMapContext.Command.IncludeAssetGUID; manifest.OutputNameStyle = (int)buildParameters.OutputNameStyle; manifest.PackageName = buildParameters.PackageName; manifest.PackageVersion = buildParameters.PackageVersion; @@ -47,7 +49,7 @@ namespace YooAsset.Editor if (buildParameters.BuildMode == EBuildMode.IncrementalBuild) { var buildResultContext = context.GetContextObject(); - UpdateBuiltInBundleReference(manifest, buildResultContext, buildMapContext.ShadersBundleName); + UpdateBuiltInBundleReference(manifest, buildResultContext, buildMapContext.Command.ShadersBundleName); } } @@ -141,11 +143,9 @@ namespace YooAsset.Editor foreach (var assetInfo in assetInfos) { PackageAsset packageAsset = new PackageAsset(); - if (buildMapContext.EnableAddressable) - packageAsset.Address = assetInfo.Address; - else - packageAsset.Address = string.Empty; + packageAsset.Address = buildMapContext.Command.EnableAddressable ? assetInfo.Address : string.Empty; packageAsset.AssetPath = assetInfo.AssetPath; + packageAsset.AssetGUID = buildMapContext.Command.IncludeAssetGUID ? assetInfo.AssetGUID : string.Empty; packageAsset.AssetTags = assetInfo.AssetTags.ToArray(); packageAsset.BundleID = GetAssetBundleID(assetInfo.BundleName, manifest); packageAsset.DependIDs = GetAssetBundleDependIDs(packageAsset.BundleID, assetInfo, manifest); diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreateReport.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreateReport.cs index 600fa1f..eab46a4 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreateReport.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskCreateReport.cs @@ -45,8 +45,10 @@ namespace YooAsset.Editor buildReport.Summary.BuildMode = buildParameters.BuildMode; buildReport.Summary.BuildPackageName = buildParameters.PackageName; buildReport.Summary.BuildPackageVersion = buildParameters.PackageVersion; - buildReport.Summary.EnableAddressable = buildMapContext.EnableAddressable; - buildReport.Summary.UniqueBundleName = buildMapContext.UniqueBundleName; + buildReport.Summary.EnableAddressable = buildMapContext.Command.EnableAddressable; + buildReport.Summary.LocationToLower = buildMapContext.Command.LocationToLower; + buildReport.Summary.IncludeAssetGUID = buildMapContext.Command.IncludeAssetGUID; + buildReport.Summary.UniqueBundleName = buildMapContext.Command.UniqueBundleName; buildReport.Summary.AutoAnalyzeRedundancy = buildParameters.AutoAnalyzeRedundancy; buildReport.Summary.ShareAssetPackRuleClassName = buildParameters.ShareAssetPackRule == null ? "null" : buildParameters.ShareAssetPackRule.GetType().FullName; diff --git a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskGetBuildMap.cs b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskGetBuildMap.cs index 31b01da..22cff99 100644 --- a/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskGetBuildMap.cs +++ b/Assets/YooAsset/Editor/AssetBundleBuilder/BuildTasks/TaskGetBuildMap.cs @@ -98,9 +98,7 @@ namespace YooAsset.Editor // 7. 记录关键信息 BuildMapContext context = new BuildMapContext(); context.AssetFileCount = allBuildAssetInfoDic.Count; - context.EnableAddressable = collectResult.Command.EnableAddressable; - context.UniqueBundleName = collectResult.Command.UniqueBundleName; - context.ShadersBundleName = collectResult.Command.ShadersBundleName; + context.Command = collectResult.Command; // 8. 计算共享的资源包名 if (autoAnalyzeRedundancy) diff --git a/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorConfig.cs b/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorConfig.cs index 7db138a..17f8117 100644 --- a/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorConfig.cs +++ b/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorConfig.cs @@ -15,6 +15,8 @@ namespace YooAsset.Editor public const string XmlVersion = "Version"; public const string XmlCommon = "Common"; public const string XmlEnableAddressable = "AutoAddressable"; + public const string XmlLocationToLower = "LocationToLower"; + public const string XmlIncludeAssetGUID = "IncludeAssetGUID"; public const string XmlUniqueBundleName = "UniqueBundleName"; public const string XmlShowPackageView = "ShowPackageView"; public const string XmlShowEditorAlias = "ShowEditorAlias"; @@ -66,6 +68,8 @@ namespace YooAsset.Editor // 读取公共配置 bool enableAddressable = false; + bool locationToLower = false; + bool includeAssetGUID = false; bool uniqueBundleName = false; bool showPackageView = false; bool showEditorAlias = false; @@ -73,19 +77,18 @@ namespace YooAsset.Editor if (commonNodeList.Count > 0) { XmlElement commonElement = commonNodeList[0] as XmlElement; - if (commonElement.HasAttribute(XmlEnableAddressable) == false) - throw new Exception($"Not found attribute {XmlEnableAddressable} in {XmlCommon}"); - if (commonElement.HasAttribute(XmlUniqueBundleName) == false) - throw new Exception($"Not found attribute {XmlUniqueBundleName} in {XmlCommon}"); - if (commonElement.HasAttribute(XmlShowPackageView) == false) - throw new Exception($"Not found attribute {XmlShowPackageView} in {XmlCommon}"); - if (commonElement.HasAttribute(XmlShowEditorAlias) == false) - throw new Exception($"Not found attribute {XmlShowEditorAlias} in {XmlCommon}"); - - enableAddressable = commonElement.GetAttribute(XmlEnableAddressable) == "True" ? true : false; - uniqueBundleName = commonElement.GetAttribute(XmlUniqueBundleName) == "True" ? true : false; - showPackageView = commonElement.GetAttribute(XmlShowPackageView) == "True" ? true : false; - showEditorAlias = commonElement.GetAttribute(XmlShowEditorAlias) == "True" ? true : false; + if (commonElement.HasAttribute(XmlEnableAddressable)) + enableAddressable = commonElement.GetAttribute(XmlEnableAddressable) == "True" ? true : false; + if (commonElement.HasAttribute(XmlLocationToLower)) + locationToLower = commonElement.GetAttribute(XmlLocationToLower) == "True" ? true : false; + if (commonElement.HasAttribute(XmlIncludeAssetGUID)) + includeAssetGUID = commonElement.GetAttribute(XmlIncludeAssetGUID) == "True" ? true : false; + if (commonElement.HasAttribute(XmlUniqueBundleName)) + uniqueBundleName = commonElement.GetAttribute(XmlUniqueBundleName) == "True" ? true : false; + if (commonElement.HasAttribute(XmlShowPackageView)) + showPackageView = commonElement.GetAttribute(XmlShowPackageView) == "True" ? true : false; + if (commonElement.HasAttribute(XmlShowEditorAlias)) + showEditorAlias = commonElement.GetAttribute(XmlShowEditorAlias) == "True" ? true : false; } // 读取包裹配置 @@ -162,7 +165,7 @@ namespace YooAsset.Editor } // 检测配置错误 - foreach(var package in packages) + foreach (var package in packages) { package.CheckConfigError(); } @@ -170,6 +173,8 @@ namespace YooAsset.Editor // 保存配置数据 AssetBundleCollectorSettingData.ClearAll(); AssetBundleCollectorSettingData.Setting.EnableAddressable = enableAddressable; + AssetBundleCollectorSettingData.Setting.LocationToLower = locationToLower; + AssetBundleCollectorSettingData.Setting.IncludeAssetGUID = includeAssetGUID; AssetBundleCollectorSettingData.Setting.UniqueBundleName = uniqueBundleName; AssetBundleCollectorSettingData.Setting.ShowPackageView = showPackageView; AssetBundleCollectorSettingData.Setting.ShowEditorAlias = showEditorAlias; @@ -201,6 +206,8 @@ namespace YooAsset.Editor // 设置公共配置 var commonElement = xmlDoc.CreateElement(XmlCommon); commonElement.SetAttribute(XmlEnableAddressable, AssetBundleCollectorSettingData.Setting.EnableAddressable.ToString()); + commonElement.SetAttribute(XmlLocationToLower, AssetBundleCollectorSettingData.Setting.LocationToLower.ToString()); + commonElement.SetAttribute(XmlIncludeAssetGUID, AssetBundleCollectorSettingData.Setting.IncludeAssetGUID.ToString()); commonElement.SetAttribute(XmlUniqueBundleName, AssetBundleCollectorSettingData.Setting.UniqueBundleName.ToString()); commonElement.SetAttribute(XmlShowPackageView, AssetBundleCollectorSettingData.Setting.ShowPackageView.ToString()); commonElement.SetAttribute(XmlShowEditorAlias, AssetBundleCollectorSettingData.Setting.ShowEditorAlias.ToString()); @@ -359,14 +366,14 @@ namespace YooAsset.Editor } // 2.3 -> 2.4 - if(configVersion == "2.3") + if (configVersion == "2.3") { // 获取所有分组元素 var groupNodeList = root.GetElementsByTagName(XmlGroup); foreach (var groupNode in groupNodeList) { XmlElement groupElement = groupNode as XmlElement; - if(groupElement.HasAttribute(XmlGroupActiveRule) == false) + if (groupElement.HasAttribute(XmlGroupActiveRule) == false) groupElement.SetAttribute(XmlGroupActiveRule, $"{nameof(EnableGroup)}"); } diff --git a/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorSetting.cs b/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorSetting.cs index 3aba54b..b571851 100644 --- a/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorSetting.cs +++ b/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorSetting.cs @@ -10,15 +10,25 @@ namespace YooAsset.Editor public class AssetBundleCollectorSetting : ScriptableObject { /// - /// 是否显示包裹列表视图 + /// 显示包裹列表视图 /// public bool ShowPackageView = false; /// - /// 是否启用可寻址资源定位 + /// 启用可寻址资源定位 /// public bool EnableAddressable = false; + /// + /// 资源定位地址大小写不敏感 + /// + public bool LocationToLower = false; + + /// + /// 包含资源GUID数据 + /// + public bool IncludeAssetGUID = false; + /// /// 资源包名唯一化 /// @@ -41,7 +51,12 @@ namespace YooAsset.Editor /// public void ClearAll() { + ShowPackageView = false; EnableAddressable = false; + LocationToLower = false; + IncludeAssetGUID = false; + UniqueBundleName = false; + ShowEditorAlias = false; Packages.Clear(); } @@ -101,7 +116,8 @@ namespace YooAsset.Editor { if (package.PackageName == packageName) { - CollectCommand command = new CollectCommand(buildMode, packageName, EnableAddressable, UniqueBundleName); + CollectCommand command = new CollectCommand(buildMode, packageName, + EnableAddressable, LocationToLower, IncludeAssetGUID, UniqueBundleName); CollectResult collectResult = new CollectResult(command); collectResult.SetCollectAssets(package.GetAllCollectAssets(command)); return collectResult; diff --git a/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorSettingData.cs b/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorSettingData.cs index 5fd5aee..7c8d34a 100644 --- a/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorSettingData.cs +++ b/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorSettingData.cs @@ -331,6 +331,16 @@ namespace YooAsset.Editor Setting.EnableAddressable = enableAddressable; IsDirty = true; } + public static void ModifyLocationToLower(bool locationToLower) + { + Setting.LocationToLower = locationToLower; + IsDirty = true; + } + public static void ModifyIncludeAssetGUID(bool includeAssetGUID) + { + Setting.IncludeAssetGUID = includeAssetGUID; + IsDirty = true; + } public static void ModifyUniqueBundleName(bool uniqueBundleName) { Setting.UniqueBundleName = uniqueBundleName; diff --git a/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorWindow.cs b/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorWindow.cs index 839860c..b07c152 100644 --- a/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorWindow.cs +++ b/Assets/YooAsset/Editor/AssetBundleCollector/AssetBundleCollectorWindow.cs @@ -25,8 +25,13 @@ namespace YooAsset.Editor private List _packRuleList; private List _filterRuleList; + private Button _settingsButton; + private VisualElement _setting1Container; + private VisualElement _setting2Container; private Toggle _showPackageToogle; private Toggle _enableAddressableToogle; + private Toggle _locationToLowerToogle; + private Toggle _includeAssetGUIDToogle; private Toggle _uniqueBundleNameToogle; private Toggle _showEditorAliasToggle; @@ -47,6 +52,7 @@ namespace YooAsset.Editor private int _lastModifyPackageIndex = 0; private int _lastModifyGroupIndex = 0; + private bool _showSettings = false; public void CreateGUI() @@ -77,6 +83,10 @@ namespace YooAsset.Editor visualAsset.CloneTree(root); // 公共设置相关 + _settingsButton = root.Q