From 763481a7dd914c308eddc0a40ddf7d30b68395fd Mon Sep 17 00:00:00 2001 From: Starfire-Mac Date: Tue, 16 Jan 2024 07:16:43 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Feature=20-=20=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E6=94=B6=E9=9B=86=E5=99=A8=E9=80=89=E6=8B=A9=20=E9=94=AE?= =?UTF-8?q?=E7=9B=98=E6=94=AF=E6=8C=81=20-=20=E6=96=B0=E5=A2=9E=E8=B5=84?= =?UTF-8?q?=E6=BA=90=E6=9F=A5=E8=AF=A2=E5=8F=B3=E9=94=AE=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E6=8C=87=E5=AE=9A=E8=B5=84=E6=BA=90=E8=BF=9B=E5=85=A5?= =?UTF-8?q?=E9=A6=96=E5=8C=85=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ✒️ Fix - 配置保存顺序 ⭐ Improvement - 优化规则名为中文 --- Editor/Windows/AssetCollectWindow.Data.cs | 147 ++------------ .../Windows/AssetCollectWindow.GUIContent.cs | 151 +++++++++++++++ .../AssetCollectWindow.GUIContent.cs.meta | 3 + Editor/Windows/AssetCollectWindow.cs | 68 ++++++- Editor/Windows/Data/ASBuildConfig.Ftp.cs | 1 - Editor/Windows/Data/ASBuildConfig.cs | 44 +++-- Editor/Windows/Data/AssetCollectGroup.cs | 76 ++++++-- Editor/Windows/Data/AssetCollectItem.cs | 181 +++++++++++------- Editor/Windows/Data/AssetCollectPackage.cs | 55 ++++-- Editor/Windows/Data/AssetCollectRoot.cs | 53 +++-- Editor/Windows/Data/AssetCollectSetting.cs | 8 +- .../IAssetRuleAddress/RuleAddress.cs | 49 ++--- Editor/Windows/Interface/IAssetRulePack.cs | 5 + .../Interface/IAssetRulePack/RulePack.cs | 30 ++- .../Mode/AssetCollectWindow.OnDrawConfig.cs | 5 - .../Mode/AssetCollectWindow.OnDrawLookMode.cs | 148 ++++++++++---- .../AssetCollectWindow.OnDrawBuildMode.cs | 110 ++++++----- .../AssetCollectWindow.OnDrawEditor.cs | 10 + .../AssetCollectWindow.OnDrawGroup.cs | 9 +- .../AssetCollectWindow.OnDrawGroupList.cs | 36 +++- .../AssetCollectWindow.OnDrawHeader.cs | 5 + .../AssetCollectWindow.OnDrawItem.cs | 58 ++++-- .../AssetCollectWindow.OnDrawPackage.cs | 16 +- .../1.5.7/ConvertYooAsset.AIOPackRule.cs | 2 +- Runtime/Config/ASConfig.cs | 2 +- 25 files changed, 854 insertions(+), 418 deletions(-) create mode 100644 Editor/Windows/AssetCollectWindow.GUIContent.cs create mode 100644 Editor/Windows/AssetCollectWindow.GUIContent.cs.meta diff --git a/Editor/Windows/AssetCollectWindow.Data.cs b/Editor/Windows/AssetCollectWindow.Data.cs index 148f0d9..f463931 100644 --- a/Editor/Windows/AssetCollectWindow.Data.cs +++ b/Editor/Windows/AssetCollectWindow.Data.cs @@ -53,7 +53,7 @@ public partial class AssetCollectWindow private Vector2 OnDrawPackageScroll = Vector2.zero; private Vector2 OnDrawGroupScroll = Vector2.zero; private Vector2 OnDrawGroupListScroll = Vector2.zero; - private Vector2 OnDrawListScroll = Vector2.zero; + private Vector2 OnDrawItemListScroll = Vector2.zero; private Vector2 OnDrawLookDataScroll = Vector2.zero; #region Build @@ -83,11 +83,6 @@ public partial class AssetCollectWindow /// private bool FoldoutUploadGCloud = true; - // /// - // /// 折叠栏 - 钉钉通知 - // /// - // private bool FoldoutNoticeDingDing = true; - #endregion #region Draw Group List @@ -393,10 +388,11 @@ private class DependenciesInfo private Hashtable TempTable = new Hashtable(); private GUILayoutOption GP_MAX_Width_100; private GUILayoutOption GP_MIN_Width_50; - + private GUILayoutOption GP_Width_100; private GUILayoutOption GP_Width_120; private GUILayoutOption GP_Width_150; + private GUILayoutOption GP_Width_160; private GUILayoutOption GP_Width_80; private GUILayoutOption GP_Width_75; private GUILayoutOption GP_Width_50; @@ -411,93 +407,6 @@ private class DependenciesInfo private GUILayoutOption GP_Height_30; - /// - /// 界面内容 - 添加 - /// - private GUIContent GC_ADD; - - /// - /// 界面内容 - 收缩 - /// - private GUIContent GC_FOLDOUT; - - /// - /// 界面内容 - 展开 - /// - private GUIContent GC_FOLDOUT_ON; - - /// - /// 界面内容 - 合并 - /// - private GUIContent GC_MERGE; - - /// - /// 界面内容 - 删除 - /// - private GUIContent GC_DEL; - - /// - /// 界面内容 - 清空 - /// - private GUIContent GC_CLEAR; - - /// - /// 界面内容 - 上传 - /// - private GUIContent GC_UPLOAD; - - /// - /// 界面内容 - 下载 - /// - private GUIContent GC_DOWNLOAD; - - /// - /// 界面内容 - 云端 - /// - private GUIContent GC_NET; - - /// - /// 界面内容 - 打开 - /// - private GUIContent GC_OPEN; - - /// - /// 界面内容 - 打开文件夹 - /// - private GUIContent GC_OPEN_FOLDER; - - /// - /// 界面内容 - 刷新 - /// - private GUIContent GC_REFRESH; - - /// - /// 界面内容 - 同步 - /// - private GUIContent GC_SyncData; - - /// - /// 界面内容 - 复制 - /// - private GUIContent GC_COPY; - - /// - /// 界面内容 - 保存 - /// - private GUIContent GC_SAVE; - - /// - /// 界面内容 - 转化 - /// - private GUIContent GC_ToConvert; - - /// - /// 界面内容 - 报告 - /// - private GUIContent GC_REPORT; - - private GUIContent GC_Select_ASConfig; - #endregion /// @@ -539,10 +448,18 @@ private class DependenciesInfo private int LookModeCollectorsPageIndex; + /// + /// 当前选择的资源 + /// private int CurrentSelectAssetIndex; private GenericMenu onDrawLookDataItemMenu; + /// + /// 当前选择的收集器 + /// + private int CurrentCurrentCollectorsIndex; + private void GPInit() { GP_MAX_Width_100 = GUILayout.MaxWidth(100); @@ -550,6 +467,7 @@ private void GPInit() GP_Width_EXPAND = GUILayout.ExpandWidth(true); GP_Width_120 = GUILayout.Width(120); GP_Width_150 = GUILayout.Width(150); + GP_Width_160 = GUILayout.Width(160); GP_Width_100 = GUILayout.Width(100); GP_Width_75 = GUILayout.Width(75); GP_Width_80 = GUILayout.Width(80); @@ -563,48 +481,15 @@ private void GPInit() GP_Height_20 = GUILayout.Height(20); } + partial void GUIContentInit(); + partial void GCInit() { ViewRectUpdate(); GPInit(); + GUIContentInit(); - GC_MERGE = new GUIContent("合","合并收集器"); - GC_ToConvert = new GUIContent("转","转换为第三方配置文件"); - GC_REPORT = new GUIContent("报","生成报告"); - GC_SAVE = GEContent.NewBuiltin("d_SaveAs", "保存"); - GC_LookMode_Object_Select = GEContent.NewBuiltin("d_scenepicking_pickable_hover", "选择指向指定资源"); - - GC_OPEN_FOLDER = GEContent.NewSetting("bangdingliucheng", "打开文件"); - GC_NET = GEContent.NewSetting("国际", "云端"); - GC_UPLOAD = GEContent.NewSetting("上传", "上传"); - GC_DOWNLOAD = GEContent.NewSetting("下载", "下载"); - GC_FOLDOUT = GEContent.NewSetting("quanping-shouqi-xian", "收缩"); - GC_FOLDOUT_ON = GEContent.NewSetting("quanping-zhankai-xian", "展开"); - GC_Select_ASConfig = GEContent.NewSetting("ic_Eyes", "选择资源配置文件"); - GC_REFRESH = GEContent.NewSetting("重置", "刷新数据"); - GC_COPY = GEContent.NewSetting("ic_copy", "复制资源路径"); - GC_ADD = GEContent.NewSetting("新增", "添加元素"); - GC_DEL = GEContent.NewSetting("删除", "删除元素"); - GC_CLEAR = GEContent.NewSetting("cancel", "清空元素"); - GC_OPEN = GEContent.NewSettingCustom("Editor/Setting/icon_information", "打开指定查询模式"); - GC_SyncData = GEContent.NewSetting("下载", "下载"); - GC_LookMode_Data_Sort = GEContent.NewSetting("ic_sort", "排序方式"); - GC_LookMode_Page_MaxLeft = GEContent.NewSettingCustom("Editor/Icon/Arrows/Arrow_Big_Left", "跳转到第一页"); - GC_LookMode_Page_Left = GEContent.NewSettingCustom("Editor/Icon/Arrows/Arrow_Left_Bar", "上一页"); - GC_LookMode_Page_MaxRight = GEContent.NewSettingCustom("Editor/Icon/Arrows/Arrow_Right_Bar", "跳转到最后一页"); - GC_LookMode_Page_Right = GEContent.NewSettingCustom("Editor/Icon/Arrows/Arrow_Big_Right", "下一页"); - GC_LookMode_Page_Size = GEContent.NewSettingCustom("Editor/Setting/icon_setting_2", "设置页面大小"); - - GC_LookMode_Detail_Tags = new GUIContent("Tags", "资源标签"); - GC_LookMode_Detail_GUID = new GUIContent("GUID", "资源GUID"); - GC_LookMode_Detail_Asset = new GUIContent("Asset", "资源实例"); - GC_LookMode_Detail_Type = new GUIContent("Type", "资源类型"); - GC_LookMode_Detail_Path = new GUIContent("Path", "资源文件路径"); - GC_LookMode_Detail_Size = new GUIContent("Size", "文件大小"); - GC_LookMode_Detail_LastWriteTime = new GUIContent("Last Write Time", "最后写入时间"); - GC_LookMode_Detail_IsSubAsset = new GUIContent("IsSubAsset", "资源是否构成了其他资源的一部分?"); - - if (CurrentPageValues is null) CurrentPageValues = new PageList { PageSize = 25 }; + if (CurrentPageValues is null) CurrentPageValues = new PageList { PageSize = 30 }; if (LookDataPageSizeMenu is null) UpdatePageSizeMenu(); } diff --git a/Editor/Windows/AssetCollectWindow.GUIContent.cs b/Editor/Windows/AssetCollectWindow.GUIContent.cs new file mode 100644 index 0000000..cf3a17d --- /dev/null +++ b/Editor/Windows/AssetCollectWindow.GUIContent.cs @@ -0,0 +1,151 @@ +/*|============|*| +|*|Author: |*| USER +|*|Date: |*| 2024-01-16 +|*|E-Mail: |*| xinansky99@gmail.com +|*|============|*/ + +using UnityEngine; + +namespace AIO.UEditor +{ + public partial class AssetCollectWindow + { + /// + /// 界面内容 - 添加 + /// + private GUIContent GC_ADD; + + /// + /// 界面内容 - 收缩 + /// + private GUIContent GC_FOLDOUT; + + /// + /// 界面内容 - 展开 + /// + private GUIContent GC_FOLDOUT_ON; + + /// + /// 界面内容 - 合并 + /// + private GUIContent GC_MERGE; + + /// + /// 界面内容 - 数据排序 + /// + private GUIContent GC_SORT; + + /// + /// 界面内容 - 删除 + /// + private GUIContent GC_DEL; + + /// + /// 界面内容 - 清空 + /// + private GUIContent GC_CLEAR; + + /// + /// 界面内容 - 上传 + /// + private GUIContent GC_UPLOAD; + + /// + /// 界面内容 - 下载 + /// + private GUIContent GC_DOWNLOAD; + + /// + /// 界面内容 - 云端 + /// + private GUIContent GC_NET; + + /// + /// 界面内容 - 打开 + /// + private GUIContent GC_OPEN; + + /// + /// 界面内容 - 打开文件夹 + /// + private GUIContent GC_OPEN_FOLDER; + + /// + /// 界面内容 - 刷新 + /// + private GUIContent GC_REFRESH; + + /// + /// 界面内容 - 同步 + /// + private GUIContent GC_SyncData; + + /// + /// 界面内容 - 复制 + /// + private GUIContent GC_COPY; + + /// + /// 界面内容 - 保存 + /// + private GUIContent GC_SAVE; + + /// + /// 界面内容 - 转化 + /// + private GUIContent GC_ToConvert; + + /// + /// 界面内容 - 报告 + /// + private GUIContent GC_REPORT; + + private GUIContent GC_Select_ASConfig; + + /// + /// 界面内容 - 编辑标签 + /// + private GUIContent GC_Edit_Tags; + + partial void GUIContentInit() + { + GC_Edit_Tags = new GUIContent("标签", "建议:以 ; 分割\n警告:一个组内的标签不能超过 31 个"); + GC_SORT = new GUIContent("序", "数据排序"); + GC_MERGE = new GUIContent("合", "合并收集器"); + GC_ToConvert = new GUIContent("转", "转换为第三方配置文件"); + GC_REPORT = new GUIContent("报", "资源报告工具"); + GC_SAVE = GEContent.NewBuiltin("d_SaveAs", "保存"); + GC_LookMode_Object_Select = GEContent.NewBuiltin("d_scenepicking_pickable_hover", "选择指向指定资源"); + + GC_OPEN_FOLDER = GEContent.NewSetting("bangdingliucheng", "打开文件"); + GC_NET = GEContent.NewSetting("国际", "云端"); + GC_UPLOAD = GEContent.NewSetting("上传", "上传"); + GC_DOWNLOAD = GEContent.NewSetting("下载", "下载"); + GC_FOLDOUT = GEContent.NewSetting("quanping-shouqi-xian", "收缩"); + GC_FOLDOUT_ON = GEContent.NewSetting("quanping-zhankai-xian", "展开"); + GC_Select_ASConfig = GEContent.NewSetting("ic_Eyes", "选择资源配置文件"); + GC_REFRESH = GEContent.NewSetting("重置", "刷新数据"); + GC_COPY = GEContent.NewSetting("ic_copy", "复制资源路径"); + GC_ADD = GEContent.NewSetting("新增", "添加元素"); + GC_DEL = GEContent.NewSetting("删除", "删除元素"); + GC_CLEAR = GEContent.NewSetting("cancel", "清空元素"); + GC_OPEN = GEContent.NewSettingCustom("Editor/Setting/icon_information", "打开指定查询模式"); + GC_SyncData = GEContent.NewSetting("下载", "下载"); + GC_LookMode_Data_Sort = GEContent.NewSetting("ic_sort", "排序方式"); + GC_LookMode_Page_MaxLeft = GEContent.NewSettingCustom("Editor/Icon/Arrows/Arrow_Big_Left", "跳转到第一页"); + GC_LookMode_Page_Left = GEContent.NewSettingCustom("Editor/Icon/Arrows/Arrow_Left_Bar", "上一页"); + GC_LookMode_Page_MaxRight = GEContent.NewSettingCustom("Editor/Icon/Arrows/Arrow_Right_Bar", "跳转到最后一页"); + GC_LookMode_Page_Right = GEContent.NewSettingCustom("Editor/Icon/Arrows/Arrow_Big_Right", "下一页"); + GC_LookMode_Page_Size = GEContent.NewSettingCustom("Editor/Setting/icon_setting_2", "设置页面大小"); + + GC_LookMode_Detail_Tags = new GUIContent("Tags", "资源标签"); + GC_LookMode_Detail_GUID = new GUIContent("GUID", "资源GUID"); + GC_LookMode_Detail_Asset = new GUIContent("Asset", "资源实例"); + GC_LookMode_Detail_Type = new GUIContent("Type", "资源类型"); + GC_LookMode_Detail_Path = new GUIContent("Path", "资源文件路径"); + GC_LookMode_Detail_Size = new GUIContent("Size", "文件大小"); + GC_LookMode_Detail_LastWriteTime = new GUIContent("Last Write Time", "最后写入时间"); + GC_LookMode_Detail_IsSubAsset = new GUIContent("IsSubAsset", "资源是否构成了其他资源的一部分?"); + } + } +} \ No newline at end of file diff --git a/Editor/Windows/AssetCollectWindow.GUIContent.cs.meta b/Editor/Windows/AssetCollectWindow.GUIContent.cs.meta new file mode 100644 index 0000000..6d1a7eb --- /dev/null +++ b/Editor/Windows/AssetCollectWindow.GUIContent.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 6c7e671d9b6e48b892f04143e395e8aa +timeCreated: 1705351225 \ No newline at end of file diff --git a/Editor/Windows/AssetCollectWindow.cs b/Editor/Windows/AssetCollectWindow.cs index 07dbf92..a1536c2 100644 --- a/Editor/Windows/AssetCollectWindow.cs +++ b/Editor/Windows/AssetCollectWindow.cs @@ -82,7 +82,7 @@ protected void UpdateData() UpdateDataConfigMode(); break; case Mode.Editor: - + UpdateDataEditorMode(); break; case Mode.Look: UpdateDataLookMode(); @@ -158,9 +158,10 @@ protected override void OnDraw() protected override void OnDisable() { - Data?.Save(); - Config?.Save(); - BuildConfig?.Save(); + if (Data != null) Data.Save(); + if (Config != null) Config.Save(); + if (BuildConfig != null) BuildConfig.Save(); + AssetDatabase.SaveAssets(); } public override void EventMouseDown(in Event eventData) @@ -221,6 +222,13 @@ public override void EventKeyDown(in Event eventData, in KeyCode keyCode) { switch (keyCode) { + // 判断ESC + case KeyCode.Escape: + GUI.FocusControl(null); + CancelCurrentSelectAsset(); + eventData.Use(); + break; + case KeyCode.LeftArrow: // 数字键盘 右键 if (CurrentPageValues.PageIndex > 0) { @@ -291,6 +299,57 @@ public override void EventKeyDown(in Event eventData, in KeyCode keyCode) break; case Mode.Editor: + switch (keyCode) + { + case KeyCode.UpArrow: // 数字键盘 上键 + if (Data.CurrentGroup.Length <= 0) break; + if (CurrentCurrentCollectorsIndex < Data.CurrentGroup.Length) + { + CurrentCurrentCollectorsIndex += 1; + if (CurrentCurrentCollectorsIndex >= Data.CurrentGroup.Length) + { + CurrentCurrentCollectorsIndex = 0; + OnDrawItemListScroll.y = 20 * Data.CurrentGroup.Length; + } + else OnDrawItemListScroll.y -= 20; + + GUI.FocusControl(null); + eventData.Use(); + } + + break; + + case KeyCode.DownArrow: // 数字键盘 下键 + if (Data.CurrentGroup.Length <= 0) break; + if (CurrentCurrentCollectorsIndex >= 0) + { + CurrentCurrentCollectorsIndex -= 1; + if (CurrentCurrentCollectorsIndex < 0) + { + CurrentCurrentCollectorsIndex = Data.CurrentGroup.Length - 1; + OnDrawItemListScroll.y = 0; + } + else OnDrawItemListScroll.y += 20; + + GUI.FocusControl(null); + eventData.Use(); + } + + break; + // 判断回车 + case KeyCode.Return: + case KeyCode.KeypadEnter: + if (CurrentCurrentCollectorsIndex >= 0) + { + GUI.FocusControl(null); + Data.CurrentGroup.Collectors[CurrentCurrentCollectorsIndex].Folded = + !Data.CurrentGroup.Collectors[CurrentCurrentCollectorsIndex].Folded; + eventData.Use(); + } + + break; + } + if (eventData.control && keyCode == KeyCode.S) { GUI.FocusControl(null); @@ -383,7 +442,6 @@ public override void EventMouseUp(in Event eventData) partial void OnDrawPackage(); partial void OnDrawGroup(); partial void OnDrawGroupList(); - partial void OnDrawItem(AssetCollectItem item); partial void OnDrawASConfig(); /// diff --git a/Editor/Windows/Data/ASBuildConfig.Ftp.cs b/Editor/Windows/Data/ASBuildConfig.Ftp.cs index b2a400d..6e5672f 100644 --- a/Editor/Windows/Data/ASBuildConfig.Ftp.cs +++ b/Editor/Windows/Data/ASBuildConfig.Ftp.cs @@ -5,7 +5,6 @@ |*|============|*/ using System; -using System.Collections; using System.Collections.Generic; using System.IO; using System.Linq; diff --git a/Editor/Windows/Data/ASBuildConfig.cs b/Editor/Windows/Data/ASBuildConfig.cs index b1570cb..ab8cbe4 100644 --- a/Editor/Windows/Data/ASBuildConfig.cs +++ b/Editor/Windows/Data/ASBuildConfig.cs @@ -5,6 +5,7 @@ |*|============|*/ using System; +using System.ComponentModel; using System.IO; using AIO.UEngine; using UnityEditor; @@ -12,6 +13,7 @@ namespace AIO.UEditor { + [Description("资源打包配置")] [Serializable] [HelpURL( "https://github.com/AIO-GAME/Unity.Asset.CLI/blob/main/.github/API_USAGE/ToolWindow.md#-%E6%89%93%E5%8C%85%E5%B7%A5%E5%85%B7-")] @@ -84,29 +86,31 @@ public partial class ASBuildConfig : ScriptableObject /// public static ASBuildConfig GetOrCreate() { - if (_instance != null) return _instance; - var objects = EHelper.IO.GetScriptableObjects(); - if (objects != null && objects.Length > 0) + if (_instance is null) { - foreach (var asset in objects) + var objects = EHelper.IO.GetScriptableObjects(); + if (objects != null && objects.Length > 0) { - if (asset is null) continue; - if (string.IsNullOrEmpty(asset.BuildOutputPath)) + foreach (var asset in objects) { - asset.BuildOutputPath = Path.Combine(EHelper.Path.Project, "Bundles"); + if (asset is null) continue; + if (string.IsNullOrEmpty(asset.BuildOutputPath)) + { + asset.BuildOutputPath = Path.Combine(EHelper.Path.Project, "Bundles"); + } + + _instance = asset; + break; } - - _instance = asset; - break; } - } - if (_instance is null) - { - _instance = CreateInstance(); - _instance.BuildOutputPath = Path.Combine(EHelper.Path.Project, "Bundles"); - AssetDatabase.CreateAsset(_instance, "Assets/Editor/ASBuildConfig.asset"); - AssetDatabase.SaveAssets(); + if (_instance is null) + { + _instance = CreateInstance(); + _instance.BuildOutputPath = Path.Combine(EHelper.Path.Project, "Bundles"); + AssetDatabase.CreateAsset(_instance, "Assets/Editor/ASBuildConfig.asset"); + AssetDatabase.SaveAssets(); + } } return _instance; @@ -114,7 +118,11 @@ public static ASBuildConfig GetOrCreate() public void Save() { - if (Equals(null)) return; + if (Equals(null)) + { + Debug.LogWarning("ASBuildConfig is null so not save"); + return; + } #if UNITY_2021_1_OR_NEWER AssetDatabase.SaveAssetIfDirty(this); #else diff --git a/Editor/Windows/Data/AssetCollectGroup.cs b/Editor/Windows/Data/AssetCollectGroup.cs index d7df51a..9d06458 100644 --- a/Editor/Windows/Data/AssetCollectGroup.cs +++ b/Editor/Windows/Data/AssetCollectGroup.cs @@ -8,6 +8,7 @@ using System.Collections.Generic; using System.Linq; using UnityEditor; +using Object = UnityEngine.Object; namespace AIO.UEditor { @@ -34,13 +35,28 @@ public class AssetCollectGroup : IDisposable, IEqualityComparer public AssetCollectItem[] Collectors; + /// + /// 获取资源收集器数量 + /// + public int Length + { + get + { + if (Collectors is null) Collectors = Array.Empty(); + return Collectors.Length; + } + } + + /// + /// 刷新资源 + /// public void Refresh() { - if (Collectors is null || Collectors.Length == 0) return; + if (Collectors is null) Collectors = Array.Empty(); foreach (var collect in Collectors) { if (!AHelper.IO.Exists(collect.CollectPath)) continue; - collect.Path = AssetDatabase.LoadAssetAtPath(collect.CollectPath); + collect.Path = AssetDatabase.LoadAssetAtPath(collect.CollectPath); } } @@ -50,38 +66,68 @@ public AssetCollectItem this[int index] set => Collectors[index] = value; } + /// + /// 获取资源收集器 + /// + /// 收集器资源路径 会被转化成 GUID + /// 收集器 public AssetCollectItem GetCollector(string collectPath) { + if (Collectors is null) + { + Collectors = Array.Empty(); + return null; + } + + var guid = AssetDatabase.AssetPathToGUID(collectPath); return Collectors - .Where(collectItem => !(collectItem is null)) - .FirstOrDefault(collectItem => collectItem.CollectPath == collectPath); + .Where(collectItem => collectItem != null) + .FirstOrDefault(collectItem => collectItem.GUID == guid); } - public string[] GetTags() + /// + /// 获取资源收集器 + /// + /// 收集器资源路径GUID + /// 收集器 + public AssetCollectItem GetCollectorGUID(string guid) { - var dictionary = new Dictionary(); - foreach (var collect in Collectors) + if (Collectors is null) { - if (collect.Type != EAssetCollectItemType.MainAssetCollector) continue; - if (string.IsNullOrEmpty(collect.Tags)) continue; - foreach (var tag in collect.Tags.Split(';')) dictionary[tag] = true; + Collectors = Array.Empty(); + return null; } - if (string.IsNullOrEmpty(Tags)) return dictionary.Keys.ToArray(); + return Collectors + .Where(collectItem => collectItem != null) + .FirstOrDefault(collectItem => collectItem.GUID == guid); + } - foreach (var tag in Tags.Split(';')) dictionary[tag] = true; - return dictionary.Keys.ToArray(); + /// + /// 获取所有标签 + /// + /// 标签列表 + public string[] GetTags() + { + var dictionary = new List(); + foreach (var collect in Collectors) dictionary.AddRange(collect.GetTags()); + if (string.IsNullOrEmpty(Tags)) return dictionary.Distinct().ToArray(); + dictionary.AddRange(Tags.Split(';', ' ', ',')); + return dictionary.Distinct().ToArray(); } + /// + /// 保存 + /// public void Save() { - if (Collectors is null || Collectors.Length == 0) return; + if (Collectors is null) Collectors = Array.Empty(); foreach (var collect in Collectors) collect.UpdateData(); } public void Dispose() { - if (Collectors is null || Collectors.Length == 0) return; + if (Collectors is null) Collectors = Array.Empty(); foreach (var collect in Collectors) collect.Dispose(); } diff --git a/Editor/Windows/Data/AssetCollectItem.cs b/Editor/Windows/Data/AssetCollectItem.cs index 29cb5de..2bb67ce 100644 --- a/Editor/Windows/Data/AssetCollectItem.cs +++ b/Editor/Windows/Data/AssetCollectItem.cs @@ -16,7 +16,7 @@ namespace AIO.UEditor { /// - /// + /// 收集器列表 /// [Serializable] public class AssetCollectItem : IEqualityComparer, IDisposable @@ -59,7 +59,7 @@ public class AssetCollectItem : IEqualityComparer, IDisposable /// /// 收集器全路径 /// - public string FullPath => System.IO.Path.Combine(EHelper.Path.Project, CollectPath).Replace("\\", "/"); + public string FullPath => System.IO.Path.Combine(EHelper.Path.Project, CollectPath); /// /// 自定义数据 @@ -81,6 +81,24 @@ public class AssetCollectItem : IEqualityComparer, IDisposable /// public bool HasExtension; + /// + /// 打包规则 + /// + public int RulePackIndex = 1; + + /// + /// 收集器路径 + /// + public Object Path + { + get => _Path; + set + { + _Path = value; + UpdateData(); + } + } + #region Collect /// @@ -89,7 +107,7 @@ public class AssetCollectItem : IEqualityComparer, IDisposable public int RuleCollectIndex; /// - /// 收集规则 + /// 开启自定义收集规则 /// public bool RuleUseCollectCustom; @@ -108,35 +126,17 @@ public class AssetCollectItem : IEqualityComparer, IDisposable public int RuleFilterIndex; /// - /// 过滤规则 + /// 开启自定义过滤规则 /// public bool RuleUseFilterCustom; /// - /// 过滤规则 + /// 过滤规则 自定义 /// public string RuleFilter; #endregion - /// - /// 打包规则 - /// - public int RulePackIndex; - - /// - /// 收集器路径 - /// - public Object Path - { - get => _Path; - set - { - _Path = value; - UpdateData(); - } - } - /// /// 收集器路径 /// @@ -158,11 +158,27 @@ public Object Path /// private string[] RuleCustomCollect { get; set; } + /// + /// 资源包名称 + /// + public string PackageName { get; private set; } + + /// + /// 资源组名称 + /// + public string GroupName { get; private set; } + + /// + /// 获取收集规则 + /// public AssetRulePackResult GetPackRule(AssetRuleData data) { return AssetCollectSetting.MapPacks.GetValue(RulePackIndex).GetPackRuleResult(data); } + /// + /// 设置可寻址规则 + /// public void SetAddress() where T : IAssetRuleAddress { Address = AssetCollectSetting.MapAddress.Values.FindIndex(address => address is T); @@ -183,29 +199,52 @@ public bool IsCollectAsset(AssetRuleData data) return false; } - // 判断收集规则是否符合条件 如果不符合则跳过 - if (RuleCollects.Count != 0 && - !RuleCollects.Exists(filter => filter.IsCollectAsset(data)) - ) return false; - - // 判断自定义收集规则等 - if (RuleUseCollectCustom && RuleCustomCollect?.Length > 0 && - !UEditor.RuleCollect.IsCollectAssetCustom(RuleCustomCollect, data.Extension) - ) return false; - - // 判断过滤规则是否符合条件 如果符合则跳过 - if (RuleFilters.Count != 0 && - RuleFilters.Exists(filter => filter.IsCollectAsset(data)) - ) return false; + if (RuleUseCollectCustom) // 判断是否使用自定义收集规则 + { + if (RuleCustomCollect?.Length > 0 && // 判断自定义收集规则等 + !UEditor.RuleCollect.IsCollectAssetCustom(RuleCustomCollect, data.Extension) + ) return false; + } + else + { + if (RuleCollects.Count != 0 && // 判断收集规则是否符合条件 如果不符合则跳过 + !RuleCollects.Exists(filter => filter.IsCollectAsset(data)) + ) return false; + } - // 判断自定义过滤规则等 - if (RuleUseFilterCustom && RuleCustomFilter?.Length > 0 && - UEditor.RuleCollect.IsCollectAssetCustom(RuleCustomFilter, data.Extension) - ) return false; + if (RuleUseFilterCustom) // 判断是否使用自定义过滤规则 + { + if (RuleCustomFilter?.Length > 0 && // 判断自定义过滤规则等 + UEditor.RuleCollect.IsCollectAssetCustom(RuleCustomFilter, data.Extension) + ) return false; + } + else + { + if (RuleFilters.Count != 0 && // 判断过滤规则是否符合条件 如果符合则跳过 + RuleFilters.Exists(filter => filter.IsCollectAsset(data)) + ) return false; + } return true; } + /// + /// 获取所有标签 + /// + /// + public string[] GetTags() + { + if (Type != EAssetCollectItemType.MainAssetCollector) return Array.Empty(); + if (string.IsNullOrEmpty(Tags)) return Array.Empty(); + if (!AHelper.IO.Exists(CollectPath)) return Array.Empty(); + return Tags.Split(';', ' ', ','); + } + + /// + /// 获取资源可寻地址 + /// + /// + /// public string GetAddress(string assetPath) { UpdateCollect(); @@ -225,6 +264,7 @@ public string GetAddress(string assetPath) } data.AssetPath = assetPath.Substring(0, assetPath.Length - data.Extension.Length - 1); + data.AssetPath = data.AssetPath; return IsCollectAsset(data) ? GetAssetAddress(data, ASConfig.GetOrCreate().LoadPathToLower) : string.Empty; } @@ -274,18 +314,19 @@ public string GetAssetAddress(AssetRuleData data, bool pathToLower = false) public void UpdateFilter() { - RuleFilters.Clear(); if (RuleUseFilterCustom) { if (!string.IsNullOrEmpty(RuleFilter)) - RuleCustomFilter = RuleFilter.Split(';'); + RuleCustomFilter = RuleFilter.Split(';', ' ', ','); } else if (RuleFilterIndex < 0) { + RuleFilters.Clear(); RuleFilters.AddRange(AssetCollectSetting.MapFilter.Values); } else if (RuleFilterIndex > 0) { + RuleFilters.Clear(); var status = 1; foreach (var item in AssetCollectSetting.MapFilter.Values) { @@ -295,20 +336,24 @@ public void UpdateFilter() } } + /// + /// 更新收集规则 + /// public void UpdateCollect() { - RuleCollects.Clear(); if (RuleUseCollectCustom) { if (!string.IsNullOrEmpty(RuleCollect)) - RuleCustomCollect = RuleCollect.Split(';'); + RuleCustomCollect = RuleCollect.Split(';', ' ', ','); } - else if (RuleCollectIndex < 0) + else if (RuleCollectIndex < 0) // 判断是否为全部收集 { + RuleCollects.Clear(); RuleCollects.AddRange(AssetCollectSetting.MapCollect.Values); } - else if (RuleCollectIndex > 0) + else if (RuleCollectIndex > 0) // 判断是否为选择收集 { + RuleCollects.Clear(); var status = 1; foreach (var item in AssetCollectSetting.MapCollect.Values) { @@ -318,20 +363,19 @@ public void UpdateCollect() } } - public string PackageName { get; private set; } - - public string GroupName { get; private set; } - + /// + /// 是否允许多线程收集 + /// private bool IsAllowThread() { - if (!AssetCollectSetting.MapAddress.GetValue(Address).AllowThread) - { - return false; - } - - return true; + return AssetCollectSetting.MapAddress.GetValue(Address).AllowThread; } + /// + /// 收集资源 + /// + /// 标签列表 + /// 路径是否小写 private void CollectAsset(string[] tags, bool pathToLower) { UpdateCollect(); @@ -356,20 +400,19 @@ private void CollectAsset(string[] tags, bool pathToLower) { foreach (var file in EHelper.IO.GetFilesRelativeAssetNoMeta(CollectPath, SearchOption.AllDirectories)) { - var fixedPath = file.Replace("\\", "/"); - var temp = System.IO.Path.GetFileName(fixedPath); + var temp = System.IO.Path.GetFileName(file); var index = temp.LastIndexOf('.'); if (index >= 0) { data.Extension = temp.Substring(index).Replace(".", "").ToLower(); } - data.AssetPath = fixedPath.Substring(0, fixedPath.Length - data.Extension.Length - 1); + data.AssetPath = file.Substring(0, file.Length - data.Extension.Length - 1); if (!IsCollectAsset(data)) continue; info.Address = GetAssetAddress(data, pathToLower); - info.AssetPath = fixedPath; + info.AssetPath = file; info.Extension = data.Extension; - AssetDataInfos[fixedPath] = info; + AssetDataInfos[file] = info; } } else @@ -378,7 +421,7 @@ private void CollectAsset(string[] tags, bool pathToLower) data.AssetPath = data.CollectPath.Substring(0, data.CollectPath.Length - data.Extension.Length - 1); if (!IsCollectAsset(data)) return; info.Address = GetAssetAddress(data, pathToLower); - info.AssetPath = data.CollectPath.Replace("\\", "/"); + info.AssetPath = data.CollectPath; info.Extension = data.Extension; AssetDataInfos[data.CollectPath] = info; } @@ -393,15 +436,14 @@ public async Task CollectAssetTask(string package, string group, PackageName = package; GroupName = group; if (!AHelper.IO.Exists(FullPath)) return; + if (Type != EAssetCollectItemType.MainAssetCollector) return; if (CollectPath.Contains("/Resources/") || CollectPath.EndsWith("Resources")) { Debug.LogWarningFormat("Resources 目录下的资源不允许打包 !!! 已自动过滤 !!! -> {0}", CollectPath); return; } - - if (Type != EAssetCollectItemType.MainAssetCollector) return; - var tags = AssetCollectRoot.GetOrCreate(false).GetTags(PackageName, GroupName, CollectPath); + var tags = AssetCollectRoot.GetOrCreate().GetTags(PackageName, GroupName, CollectPath); var pathToLower = ASConfig.GetOrCreate().LoadPathToLower; if (IsAllowThread()) @@ -420,12 +462,11 @@ public void UpdateData() { if (_Path is null) { - Debug.LogWarningFormat("收集器路径为空 !!! -> {0}", CollectPath); Folded = false; } else { - var temp = AssetDatabase.GetAssetPath(_Path); + var temp = AssetDatabase.GetAssetPath(_Path).Replace("\\", "/"); if (!AHelper.IO.Exists(temp)) return; CollectPath = temp; GUID = AssetDatabase.AssetPathToGUID(CollectPath); @@ -439,6 +480,10 @@ public void Dispose() RuleFilters?.Clear(); RuleCollects?.Clear(); UpdateData(); + if (_Path is null) + { + Debug.LogWarningFormat("收集器路径为空 !!! -> {0}", CollectPath); + } } public bool Equals(AssetCollectItem x, AssetCollectItem y) diff --git a/Editor/Windows/Data/AssetCollectPackage.cs b/Editor/Windows/Data/AssetCollectPackage.cs index 624c4a0..824df8c 100644 --- a/Editor/Windows/Data/AssetCollectPackage.cs +++ b/Editor/Windows/Data/AssetCollectPackage.cs @@ -27,48 +27,79 @@ public class AssetCollectPackage : IDisposable public string Description; /// - /// 资源收集配置 + /// 资源组配置 /// public AssetCollectGroup[] Groups; + /// + /// 获取组数量 + /// + public int Length + { + get + { + if (Groups is null) Groups = Array.Empty(); + return Groups.Length; + } + } + public AssetCollectGroup this[int index] { get => Groups[index]; set => Groups[index] = value; } + /// + /// 获取资源收集组 + /// + /// 组名 + /// 收集组 public AssetCollectGroup GetGroup(string groupName) { - return Groups.Where(group => !(group is null)).FirstOrDefault(group => group.Name == groupName); + if (Groups is null) Groups = Array.Empty(); + return Groups.Where(group => (group != null)).FirstOrDefault(group => group.Name == groupName); } + /// + /// 获取所有标签 + /// public string[] GetTags() { - var dictionary = new Dictionary(); + if (Groups is null) + { + Groups = Array.Empty(); + return Array.Empty(); + } + + var dictionary = new List(); foreach (var group in Groups) { - foreach (var collect in group.Collectors) - { - if (string.IsNullOrEmpty(collect.Tags)) continue; - foreach (var tag in collect.Tags.Split(';')) dictionary[tag] = true; - } + dictionary.AddRange(group.Collectors + .Where(collect => !string.IsNullOrEmpty(collect.Tags)) + .SelectMany(collect => collect.Tags.Split(';', ' ', ','))); if (string.IsNullOrEmpty(group.Tags)) continue; - foreach (var tag in group.Tags.Split(';')) dictionary[tag] = true; + dictionary.AddRange(group.Tags.Split(';', ' ', ',')); } - return dictionary.Keys.ToArray(); + return dictionary.Distinct().ToArray(); } + /// + /// 保存 + /// public void Save() { - if (Groups is null || Groups.Length == 0) return; + if (Groups is null) Groups = Array.Empty(); foreach (var group in Groups) group.Save(); } + /// + /// 释放 + /// public void Dispose() { - if (Groups is null) return; + if (Groups is null) Groups = Array.Empty(); foreach (var item in Groups) item.Dispose(); } } diff --git a/Editor/Windows/Data/AssetCollectRoot.cs b/Editor/Windows/Data/AssetCollectRoot.cs index ca7aa87..2f9cbc2 100644 --- a/Editor/Windows/Data/AssetCollectRoot.cs +++ b/Editor/Windows/Data/AssetCollectRoot.cs @@ -6,6 +6,7 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.Linq; using UnityEditor; using UnityEngine; @@ -15,6 +16,7 @@ namespace AIO.UEditor /// /// 资源收集配置 /// + [Description("资源收集配置")] [Serializable] [HelpURL( "https://github.com/AIO-GAME/Unity.Asset.CLI/blob/main/.github/API_USAGE/ToolWindow.md#asset-system-%E5%B7%A5%E5%85%B7%E8%AF%B4%E6%98%8E")] @@ -27,39 +29,60 @@ public class AssetCollectRoot : ScriptableObject { private static AssetCollectRoot _Instance; - public static void Sort() + /// + /// 获取资源包数量 + /// + public int Length { - for (var i = 0; i < _Instance.Packages.Length; i++) + get { - if (_Instance.Packages[i] is null) + if (Packages is null) Packages = Array.Empty(); + return Packages.Length; + } + } + + /// + /// 资源收集器排序 + /// + public void Sort() + { + if (Packages is null) + { + Packages = Array.Empty(); + return; + } + + for (var i = 0; i < Packages.Length; i++) + { + if (Packages[i] is null) { - _Instance.Packages[i] = new AssetCollectPackage(); - _Instance.Packages[i].Groups = Array.Empty(); + Packages[i] = new AssetCollectPackage(); + Packages[i].Groups = Array.Empty(); continue; } - if (_Instance.Packages[i].Groups is null) + if (Packages[i].Groups is null) { - _Instance.Packages[i].Groups = Array.Empty(); + Packages[i].Groups = Array.Empty(); continue; } - for (var j = 0; j < _Instance.Packages[i].Groups.Length; j++) + for (var j = 0; j < Packages[i].Groups.Length; j++) { - _Instance.Packages[i].Groups = _Instance.Packages[i].Groups + Packages[i].Groups = Packages[i].Groups .OrderByDescending(group => group.Name) .ToArray(); - if (_Instance.Packages[i].Groups[j].Collectors is null || - _Instance.Packages[i].Groups[j].Collectors.Length == 0) + if (Packages[i].Groups[j].Collectors is null || + Packages[i].Groups[j].Collectors.Length == 0) continue; - _Instance.Packages[i].Groups[j].Collectors = _Instance.Packages[i].Groups[j].Collectors + Packages[i].Groups[j].Collectors = Packages[i].Groups[j].Collectors .OrderByDescending(collect => collect.CollectPath) .ToArray(); } } - _Instance.Packages = _Instance.Packages.OrderByDescending(package => package.Name).ToArray(); + Packages = Packages.OrderByDescending(package => package.Name).ToArray(); } /// @@ -127,7 +150,7 @@ public void MergeCollector(string packageName) /// /// 获取资源收集配置 /// - public static AssetCollectRoot GetOrCreate(bool isSort = true) + public static AssetCollectRoot GetOrCreate() { if (_Instance is null) { @@ -159,8 +182,6 @@ public static AssetCollectRoot GetOrCreate(bool isSort = true) } } - if (isSort) Sort(); - return _Instance; } diff --git a/Editor/Windows/Data/AssetCollectSetting.cs b/Editor/Windows/Data/AssetCollectSetting.cs index 19d8254..f8f1177 100644 --- a/Editor/Windows/Data/AssetCollectSetting.cs +++ b/Editor/Windows/Data/AssetCollectSetting.cs @@ -11,10 +11,10 @@ namespace AIO.UEditor { public static class AssetCollectSetting { - public static DisplayList MapAddress; - public static DisplayList MapCollect; - public static DisplayList MapFilter; - public static DisplayList MapPacks; + public static DisplayList MapAddress { get; private set; } + public static DisplayList MapCollect { get; private set; } + public static DisplayList MapFilter { get; private set; } + public static DisplayList MapPacks { get; private set; } public static void Initialize() { diff --git a/Editor/Windows/Interface/IAssetRuleAddress/RuleAddress.cs b/Editor/Windows/Interface/IAssetRuleAddress/RuleAddress.cs index c883c5f..498a18f 100644 --- a/Editor/Windows/Interface/IAssetRuleAddress/RuleAddress.cs +++ b/Editor/Windows/Interface/IAssetRuleAddress/RuleAddress.cs @@ -7,7 +7,6 @@ using System; using System.IO; using UnityEditor; -using UnityEngine; using IAddressRule = AIO.UEditor.IAssetRuleAddress; using Object = UnityEngine.Object; @@ -19,14 +18,11 @@ public class AddressRuleGroupRelative : IAddressRule { public bool AllowThread => true; - public string DisplayAddressName => "Location = Group + Relative File Path"; + public string DisplayAddressName => "寻址路径 = 组名 + 资源文件相对收集器路径"; string IAddressRule.GetAssetAddress(AssetRuleData data) { - return data.AssetPath.Replace( - string.Concat(data.CollectPath, '/'), - string.Concat(Path.GetFileName(data.GroupName) + '/') - ); + return data.AssetPath.Replace(data.CollectPath, data.GroupName).Replace('\\', '/'); } } @@ -34,11 +30,12 @@ public class AddressRuleGroupFileName : IAddressRule { public bool AllowThread => true; - public string DisplayAddressName => "Location = Group + FileName"; + public string DisplayAddressName => "寻址路径 = 组名 + 资源文件名"; string IAddressRule.GetAssetAddress(AssetRuleData data) { - return string.Concat(Path.GetFileName(data.GroupName), '/', Path.GetFileName(data.AssetPath)); + return Path.Combine(Path.GetFileName(data.GroupName), Path.GetFileName(data.AssetPath)) + .Replace('\\', '/'); } } @@ -46,11 +43,11 @@ public class AddressRuleFileName : IAddressRule { public bool AllowThread => true; - public string DisplayAddressName => "Location = FileName"; + public string DisplayAddressName => "寻址路径 = 资源文件名"; string IAddressRule.GetAssetAddress(AssetRuleData data) { - return Path.GetFileName(data.AssetPath); + return Path.GetFileName(data.AssetPath).Replace('\\', '/'); } } @@ -58,7 +55,7 @@ public class AddressRuleInstanceID : IAddressRule { public bool AllowThread => false; - public string DisplayAddressName => "Location = InstanceID"; + public string DisplayAddressName => "寻址路径 = 资源 实例ID"; string IAddressRule.GetAssetAddress(AssetRuleData data) { @@ -71,11 +68,12 @@ public class AddressRuleCollectRelative : IAddressRule { public bool AllowThread => true; - public string DisplayAddressName => "Location = Collect + Relative File Path"; + public string DisplayAddressName => "寻址路径 = 收集器文件名 + 资源文件相对收集器路径"; string IAddressRule.GetAssetAddress(AssetRuleData data) { - return data.AssetPath.Substring(data.CollectPath.LastIndexOf('/') + 1); + return data.AssetPath.Substring(data.CollectPath.Replace('\\', '/').LastIndexOf('/') + 1) + .Replace('\\', '/'); } } @@ -83,11 +81,13 @@ public class AddressRuleCollectFileName : IAddressRule { public bool AllowThread => true; - public string DisplayAddressName => "Location = Collect + FileName"; + public string DisplayAddressName => "寻址路径 = 收集器文件名 + 资源文件名"; string IAddressRule.GetAssetAddress(AssetRuleData data) { - return string.Concat(Path.GetFileName(data.CollectPath), '/', Path.GetFileName(data.AssetPath)); + return string.Concat( + Path.GetFileName(data.CollectPath), '/', Path.GetFileName(data.AssetPath)) + .Replace('\\', '/'); } } @@ -95,11 +95,11 @@ public class AddressRuleRootRelative : IAddressRule { public bool AllowThread => true; - public string DisplayAddressName => "Location = Root Relative"; + public string DisplayAddressName => "寻址路径 = 资源文件相对Asset路径"; string IAddressRule.GetAssetAddress(AssetRuleData data) { - return data.AssetPath; + return data.AssetPath.Replace('\\', '/'); } } @@ -107,14 +107,14 @@ public class AddressRuleUserDataRelative : IAddressRule { public bool AllowThread => true; - public string DisplayAddressName => "Location = UserData + Relative File Path"; + public string DisplayAddressName => "寻址路径 = 自定义根路径 + 资源文件相对收集器路径"; string IAddressRule.GetAssetAddress(AssetRuleData data) { - return data.AssetPath.Replace( - string.Concat(data.CollectPath, '/'), - string.Concat(data.UserData, '/') - ); + var temp = data.AssetPath.Replace(data.CollectPath, ""); + temp = temp.Trim('/', '\\'); + if (string.IsNullOrEmpty(data.UserData)) return temp.Replace('\\', '/'); + return Path.Combine(data.UserData, temp).Replace('\\', '/'); } } @@ -122,11 +122,12 @@ public class AddressRuleUserDataFileName : IAddressRule { public bool AllowThread => true; - public string DisplayAddressName => "Location = UserData + FileName"; + public string DisplayAddressName => "寻址路径 = 自定义根路径 + 资源文件名"; string IAddressRule.GetAssetAddress(AssetRuleData data) { - return string.Concat(data.UserData, '/', Path.GetFileName(data.AssetPath)); + if (string.IsNullOrEmpty(data.UserData)) return Path.GetFileName(data.AssetPath); + return Path.Combine(data.UserData, Path.GetFileName(data.AssetPath)).Replace('\\', '/'); } } } diff --git a/Editor/Windows/Interface/IAssetRulePack.cs b/Editor/Windows/Interface/IAssetRulePack.cs index 72b9222..eaf5d0d 100644 --- a/Editor/Windows/Interface/IAssetRulePack.cs +++ b/Editor/Windows/Interface/IAssetRulePack.cs @@ -28,6 +28,11 @@ public interface IAssetRulePack /// string DisplayPackName { get; } + /// + /// 打包规则优先级 + /// + int Priority { get; } + /// /// 获取打包规则结果 /// diff --git a/Editor/Windows/Interface/IAssetRulePack/RulePack.cs b/Editor/Windows/Interface/IAssetRulePack/RulePack.cs index 9481f0a..930232e 100644 --- a/Editor/Windows/Interface/IAssetRulePack/RulePack.cs +++ b/Editor/Windows/Interface/IAssetRulePack/RulePack.cs @@ -40,12 +40,14 @@ public static PackRuleResult CreateShadersPackRuleResult() /// /// /// 注意:每个文件独自打资源包 - /// 例如:"Assets/UIPanel/Shop/Image/backgroud.png" --> "assets_uipanel_shop_image_backgroud.bundle" + /// 例如:"Assets/UIPanel/Shop/Image/background.png" --> "assets_uipanel_shop_image_background.bundle" /// 例如:"Assets/UIPanel/Shop/View/main.prefab" --> "assets_uipanel_shop_view_main.bundle" /// public class PackSeparately : IAssetRulePack { - public string DisplayPackName => "PackRule = 文件路径"; + public int Priority => 0; + + public string DisplayPackName => "资源打包规则 = 文件路径"; PackRuleResult IAssetRulePack.GetPackRuleResult(PackRuleData data) { @@ -65,7 +67,9 @@ PackRuleResult IAssetRulePack.GetPackRuleResult(PackRuleData data) /// public class PackDirectory : IAssetRulePack { - public string DisplayPackName => "PackRule = 父类文件夹路径"; + public string DisplayPackName => "资源打包规则 = 父类文件夹路径"; + + public int Priority => 1; PackRuleResult IAssetRulePack.GetPackRuleResult(PackRuleData data) { @@ -86,7 +90,9 @@ PackRuleResult IAssetRulePack.GetPackRuleResult(PackRuleData data) /// public class PackTopDirectory : IAssetRulePack { - public string DisplayPackName => "PackRule = 收集器下顶级文件夹路径"; + public string DisplayPackName => "资源打包规则 = 收集器下顶级文件夹路径"; + + public int Priority => 2; PackRuleResult IAssetRulePack.GetPackRuleResult(PackRuleData data) { @@ -116,7 +122,9 @@ PackRuleResult IAssetRulePack.GetPackRuleResult(PackRuleData data) /// public class PackCollector : IAssetRulePack { - public string DisplayPackName => "PackRule = 收集器路径"; + public string DisplayPackName => "资源打包规则 = 收集器路径"; + + public int Priority => 3; PackRuleResult IAssetRulePack.GetPackRuleResult(PackRuleData data) { @@ -137,7 +145,9 @@ PackRuleResult IAssetRulePack.GetPackRuleResult(PackRuleData data) /// public class PackGroup : IAssetRulePack { - public string DisplayPackName => "PackRule = 分组名称"; + public string DisplayPackName => "资源打包规则 = 分组名称"; + + public int Priority => 4; PackRuleResult IAssetRulePack.GetPackRuleResult(PackRuleData data) { @@ -154,7 +164,9 @@ PackRuleResult IAssetRulePack.GetPackRuleResult(PackRuleData data) /// public class PackRawFile : IAssetRulePack { - public string DisplayPackName => "PackRule = 打包原生文件"; + public string DisplayPackName => "资源打包规则 = 打包原生文件"; + + public int Priority => 5; PackRuleResult IAssetRulePack.GetPackRuleResult(PackRuleData data) { @@ -171,7 +183,9 @@ PackRuleResult IAssetRulePack.GetPackRuleResult(PackRuleData data) /// public class PackShaderVariants : IAssetRulePack { - public string DisplayPackName => "PackRule = 打包着色器变种集合文件"; + public string DisplayPackName => "资源打包规则 = 打包着色器变种集合文件"; + + public int Priority => 6; public PackRuleResult GetPackRuleResult(PackRuleData data) { diff --git a/Editor/Windows/Mode/AssetCollectWindow.OnDrawConfig.cs b/Editor/Windows/Mode/AssetCollectWindow.OnDrawConfig.cs index 502f898..a8ac800 100644 --- a/Editor/Windows/Mode/AssetCollectWindow.OnDrawConfig.cs +++ b/Editor/Windows/Mode/AssetCollectWindow.OnDrawConfig.cs @@ -32,11 +32,6 @@ private void OnDrawHeaderConfigMode() Config.Save(); if (EditorUtility.DisplayDialog("保存", "保存成功", "确定")) { -#if UNITY_2020_1_OR_NEWER - AssetDatabase.SaveAssetIfDirty(Config); -#else - AssetDatabase.SaveAssets(); -#endif AssetDatabase.Refresh(); } } diff --git a/Editor/Windows/Mode/AssetCollectWindow.OnDrawLookMode.cs b/Editor/Windows/Mode/AssetCollectWindow.OnDrawLookMode.cs index cffce29..7131339 100644 --- a/Editor/Windows/Mode/AssetCollectWindow.OnDrawLookMode.cs +++ b/Editor/Windows/Mode/AssetCollectWindow.OnDrawLookMode.cs @@ -301,19 +301,19 @@ private void LookModeDataPageValueSort(ESort sort, bool minToMax) /// partial void OnDrawLookMode() { - if (Data.Packages.Length == 0) + if (Data.Length == 0) { GELayout.HelpBox("当前无包资源数据"); return; } - if (Data.CurrentPackage.Groups.Length == 0) + if (Data.CurrentPackage.Length == 0) { GELayout.HelpBox("当前无组资源数据"); return; } - if (Data.CurrentGroup.Collectors.Length == 0) + if (Data.CurrentGroup.Length == 0) { GELayout.HelpBox("当前无收集器资源数据"); return; @@ -530,32 +530,47 @@ private bool LookModeDataFilter(AssetDataInfo data) private void OnDrawLookModeHeader(Rect rect) { - var rect1 = new Rect(rect) + var rect4 = new Rect(rect) { - x = 0, - width = rect.width - 160, + width = 80, + x = rect.width - 80 }; - var rect2 = new Rect(rect) + var rect3 = new Rect(rect4) { - x = rect1.x + rect1.width, + x = rect4.x - 80, width = 80 }; - var rect3 = new Rect(rect2) + var rect2 = new Rect(rect3); + if (LookModeShowAssetDetail) + { + rect2.width = 0; + rect2.x = rect3.x; + } + else { - x = rect2.x + rect2.width, + rect2.width = (rect.width - rect3.width - rect4.width) / 2 - 100; + rect2.x = rect3.x - rect2.width; + } + + var rect1 = new Rect(rect2) + { + x = 0, + width = rect2.x }; + GUI.Box(rect1, "", GEStyle.TEtoolbarbutton); - GUI.Box(rect2, "", GEStyle.TEtoolbarbutton); + if (!LookModeShowAssetDetail) GUI.Box(rect2, "", GEStyle.TEtoolbarbutton); GUI.Box(rect3, "", GEStyle.TEtoolbarbutton); + GUI.Box(rect4, "", GEStyle.TEtoolbarbutton); var rect1Content = new GUIContent( $" Asset[{LookModeCollectorsPageSize.ToConverseStringFileSize()}\\{LookModeCollectorsALLSize.ToConverseStringFileSize()}]"); - var rect2Content = new GUIContent(" Size"); - var rect3Content = new GUIContent(" Ago"); - + var rect3Content = new GUIContent(" Size"); + var rect4Content = new GUIContent(" Ago"); + var rect2Content = new GUIContent(" AssetPath"); if (LookModeSortEnableAssetName) rect1Content.image = GC_LookMode_Data_Sort.image; else if (LookModeSortEnableSize) rect2Content.image = GC_LookMode_Data_Sort.image; else if (LookModeSortEnableLastWrite) rect3Content.image = GC_LookMode_Data_Sort.image; @@ -566,13 +581,15 @@ private void OnDrawLookModeHeader(Rect rect) LookModeDataPageValueSort(ESort.AssetName, LookModeSortEnableAssetNameToMin); } - if (GUI.Button(rect2, rect2Content, GEStyle.HeaderLabel)) + if (!LookModeShowAssetDetail) GUI.Label(rect2, rect2Content, GEStyle.HeaderLabel); + + if (GUI.Button(rect3, rect3Content, GEStyle.HeaderLabel)) { LookModeSortEnableSizeToMin = !LookModeSortEnableSizeToMin; LookModeDataPageValueSort(ESort.FileSize, LookModeSortEnableSizeToMin); } - if (GUI.Button(rect3, rect3Content, GEStyle.HeaderLabel)) + if (GUI.Button(rect4, rect4Content, GEStyle.HeaderLabel)) { LookModeSortEnableLastWriteToMin = !LookModeSortEnableLastWriteToMin; LookModeDataPageValueSort(ESort.LastWrite, LookModeSortEnableLastWriteToMin); @@ -584,21 +601,34 @@ private void OnDrawLookModeHeader(Rect rect) /// private void OnDrawLookDataItem(Rect rect, AssetDataInfo data, int index) { - var rect1 = new Rect(rect) + var rect4 = new Rect(rect) { - x = 10, - width = rect.width - 160 + width = 80, + x = rect.width - 80 + 10 }; - var rect2 = new Rect(rect) + var rect3 = new Rect(rect4) { - x = rect1.x + rect1.width, - width = 80 + x = rect4.x - 80, + width = 80 + 10 }; - var rect3 = new Rect(rect2) + var rect2 = new Rect(rect3); + if (LookModeShowAssetDetail) { - x = rect2.x + rect2.width, + rect2.width = 0; + rect2.x = rect3.x; + } + else + { + rect2.width = (rect.width - rect3.width - rect4.width) / 2 - 100 +10; + rect2.x = rect3.x - rect2.width; + } + + var rect1 = new Rect(rect2) + { + x = 10, + width = rect2.x - 10 }; GUI.Box(rect, "", GEStyle.ProjectBrowserHeaderBgMiddle); @@ -610,8 +640,10 @@ private void OnDrawLookDataItem(Rect rect, AssetDataInfo data, int index) var content = EditorGUIUtility.ObjectContent(AssetDatabase.LoadMainAssetAtPath(data.AssetPath), null); content.text = data.Address; EditorGUI.LabelField(rect1, content, EditorStyles.label); - EditorGUI.LabelField(rect2, data.SizeStr, EditorStyles.label); - EditorGUI.LabelField(rect3, data.GetLatestTime(), EditorStyles.label); + if (!LookModeShowAssetDetail) EditorGUI.LabelField(rect2, data.AssetPath, EditorStyles.label); + + EditorGUI.LabelField(rect3, data.SizeStr, EditorStyles.label); + EditorGUI.LabelField(rect4, data.GetLatestTime(), EditorStyles.label); if (Event.current.isMouse && rect.Contains(Event.current.mousePosition)) { @@ -619,30 +651,70 @@ private void OnDrawLookDataItem(Rect rect, AssetDataInfo data, int index) { GUI.FocusControl(null); onDrawLookDataItemMenu = new GenericMenu(); - onDrawLookDataItemMenu.AddItem(new GUIContent("Open Default Asset"), false, - () => { EditorUtility.OpenWithDefaultApp(data.AssetPath); }); - onDrawLookDataItemMenu.AddItem(new GUIContent("Open Local Folder"), false, + onDrawLookDataItemMenu.AddItem(new GUIContent("打开 资源所在文件夹"), false, () => { EditorUtility.RevealInFinder(data.AssetPath); }); - onDrawLookDataItemMenu.AddItem(new GUIContent("Select Asset"), false, - () => { Selection.activeObject = AssetDatabase.LoadMainAssetAtPath(data.AssetPath); }); - onDrawLookDataItemMenu.AddItem(new GUIContent("Copy Address"), false, + if (AHelper.IO.ExistsFile(data.AssetPath)) + { + onDrawLookDataItemMenu.AddItem(new GUIContent("打开 使用默认程序打开"), false, + () => { EditorUtility.OpenWithDefaultApp(data.AssetPath); }); + onDrawLookDataItemMenu.AddItem(new GUIContent("选择 资源"), false, + () => { Selection.activeObject = AssetDatabase.LoadMainAssetAtPath(data.AssetPath); }); + } + + onDrawLookDataItemMenu.AddItem(new GUIContent("复制 可寻址路径"), false, () => { GUIUtility.systemCopyBuffer = data.Address; }); - onDrawLookDataItemMenu.AddItem(new GUIContent("Copy AssetPath"), false, + onDrawLookDataItemMenu.AddItem(new GUIContent("复制 资源路径"), false, () => { GUIUtility.systemCopyBuffer = data.AssetPath; }); - onDrawLookDataItemMenu.AddItem(new GUIContent("Copy GUID"), false, + onDrawLookDataItemMenu.AddItem(new GUIContent("复制 GUID"), false, () => { GUIUtility.systemCopyBuffer = data.GUID; }); - onDrawLookDataItemMenu.AddItem(new GUIContent("Copy Type"), false, + onDrawLookDataItemMenu.AddItem(new GUIContent("复制 资源类型"), false, () => { GUIUtility.systemCopyBuffer = data.Type; }); - onDrawLookDataItemMenu.AddItem(new GUIContent("Copy Tags"), false, - () => { GUIUtility.systemCopyBuffer = data.Tags; }); + if (!string.IsNullOrEmpty(data.Tags)) + { + onDrawLookDataItemMenu.AddItem(new GUIContent("复制 标签列表"), false, + () => { GUIUtility.systemCopyBuffer = data.Tags; }); + } + + if (Config.EnableSequenceRecord) + { + onDrawLookDataItemMenu.AddItem(new GUIContent("添加 首包列表"), false, () => + { + if (SequenceRecords is null) + SequenceRecords = new AssetSystem.SequenceRecordQueue(true); + if (SequenceRecords.ExistsLocal()) SequenceRecords.UpdateLocal(); + SequenceRecords.Add(new AssetSystem.SequenceRecord + { + AssetPath = data.AssetPath, + Location = data.Address, + PackageName = Data.CurrentPackage.Name, + Bytes = data.Size, + Count = 1, + Time = DateTime.MinValue + }); + SequenceRecords.Save(); + }); + } + onDrawLookDataItemMenu.ShowAsContext(); } - else UpdateCurrentSelectAsset(index); + else + { + UpdateCurrentSelectAsset(index); + } Event.current.Use(); } } + private void CancelCurrentSelectAsset() + { + GUI.FocusControl(null); + LookModeCurrentSelectAsset = null; + Dependencies.Clear(); + DependenciesSize = 0; + DependenciesSearchText = string.Empty; + } + private void UpdateCurrentSelectAsset(int index) { GUI.FocusControl(null); diff --git a/Editor/Windows/Mode/BuildMode/AssetCollectWindow.OnDrawBuildMode.cs b/Editor/Windows/Mode/BuildMode/AssetCollectWindow.OnDrawBuildMode.cs index de49fbc..e43faec 100644 --- a/Editor/Windows/Mode/BuildMode/AssetCollectWindow.OnDrawBuildMode.cs +++ b/Editor/Windows/Mode/BuildMode/AssetCollectWindow.OnDrawBuildMode.cs @@ -23,7 +23,15 @@ public partial class AssetCollectWindow private void UpdateDataBuildMode() { // 获取当前文件磁盘剩余空间 - Disk = new DriveInfo(EHelper.Path.Project); + try + { + Disk = new DriveInfo(EHelper.Path.Project); + } + catch (Exception) + { + // ignored + } + LookModeDisplayPackages = Data.Packages.Select(x => x.Name).ToArray(); BuildConfig.BuildVersion = DateTime.Now.ToString("yyyy-MM-dd-HHmmss"); Tags = Data.GetTags(); @@ -50,15 +58,19 @@ private void UpdateDataBuildMode() /// partial void OnDrawHeaderBuildMode() { - EditorGUILayout.LabelField($" 磁盘剩余空间:{Disk.AvailableFreeSpace.ToConverseStringFileSize()}", - GEStyle.HeaderLabel); + if (Disk != null) + { + EditorGUILayout.LabelField($" 磁盘剩余空间:{Disk.AvailableFreeSpace.ToConverseStringFileSize()}", + GEStyle.HeaderLabel, GP_Width_160); + } + EditorGUILayout.LabelField($"资源包数量:{Data.Packages.Length}", GEStyle.HeaderLabel, GP_Width_150); EditorGUILayout.Separator(); #if SUPPORT_YOOASSET if (GUILayout.Button(GC_REPORT, GEStyle.TEtoolbarbutton, GP_Width_30, GP_Height_20)) { - // 打开菜单栏 YooAsset/Report - EditorApplication.ExecuteMenuItem("YooAsset/Report Window"); + GUI.FocusControl(null); + EditorApplication.ExecuteMenuItem("YooAsset/AssetBundle Reporter"); } #endif @@ -72,13 +84,9 @@ partial void OnDrawHeaderBuildMode() { GUI.FocusControl(null); BuildConfig.Save(); + AssetDatabase.SaveAssets(); if (EditorUtility.DisplayDialog("保存", "保存成功", "确定")) { -#if UNITY_2020_1_OR_NEWER - AssetDatabase.SaveAssetIfDirty(BuildConfig); -#else - AssetDatabase.SaveAssets(); -#endif AssetDatabase.Refresh(); } } @@ -103,8 +111,6 @@ partial void OnDrawBuildMode() "Google Cloud", FoldoutUploadGCloud, () => { BuildConfig.AddOrNewGCloud(); }, 0, null, new GUIContent("✚")); - - // FoldoutNoticeDingDing = GELayout.VFoldoutHeaderGroupWithHelp(OnDrawBuildNoticeDingDing, "钉钉通知", FoldoutNoticeDingDing); } /// @@ -131,14 +137,19 @@ private void OnDrawBuildBuild() BuildConfig.ValidateBuild = GELayout.ToggleLeft("验证构建结果", BuildConfig.ValidateBuild, GP_Width_100); BuildConfig.MergeToLatest = GELayout.ToggleLeft("生成Latest版本", BuildConfig.MergeToLatest, GP_Width_100); + EditorGUILayout.Separator(); if (GUILayout.Button("选择目录", GEStyle.toolbarbutton, GP_Width_75)) - BuildConfig.BuildOutputPath = - EditorUtility.OpenFolderPanel("请选择导出路径", BuildConfig.BuildOutputPath, ""); + { + GUI.FocusControl(null); + BuildConfig.BuildOutputPath = EditorUtility.OpenFolderPanel( + "请选择导出路径", BuildConfig.BuildOutputPath, ""); + } if (GUILayout.Button("打开目录", GEStyle.toolbarbutton, GP_Width_75)) { + GUI.FocusControl(null); if (!Directory.Exists(BuildConfig.BuildOutputPath)) Directory.CreateDirectory(BuildConfig.BuildOutputPath); PrPlatform.Open.Path(BuildConfig.BuildOutputPath).Async(); @@ -146,9 +157,14 @@ private void OnDrawBuildBuild() if (GUILayout.Button("清空缓存", GEStyle.toolbarbutton, GP_Width_75)) { - var sandbox = Path.Combine(EHelper.Path.Project, "Bundles"); + var sandbox = Path.Combine(BuildConfig.BuildOutputPath); if (Directory.Exists(sandbox)) - AHelper.IO.DeleteDir(sandbox, SearchOption.AllDirectories, true); + { + if (EditorUtility.DisplayDialog("清空缓存", $"确定清空缓存?\n-----------------------\n清空缓存代表着\n之后每个资源包\n第一次构建必定是强制构建模式", "确定", "取消")) + { + AHelper.IO.DeleteDir(sandbox, SearchOption.AllDirectories, true); + } + } } if (GUILayout.Button("生成配置", GEStyle.toolbarbutton, GP_Width_75)) @@ -159,15 +175,18 @@ private void OnDrawBuildBuild() if (Application.isPlaying) GUI.enabled = false; if (GUILayout.Button("构建资源", GEStyle.toolbarbutton, GP_Width_75)) { - try + if (EditorUtility.DisplayDialog("构建资源", "确定构建资源?", "确定", "取消")) { - AssetProxyEditor.ConvertConfig(Data, false); - AssetProxyEditor.BuildArt(BuildConfig, true); - BuildConfig.BuildVersion = DateTime.Now.ToString("yyyy-MM-dd-HHmmss"); - } - catch (Exception) - { - BuildConfig.BuildVersion = DateTime.Now.ToString("yyyy-MM-dd-HHmmss"); + try + { + AssetProxyEditor.ConvertConfig(Data, false); + AssetProxyEditor.BuildArt(BuildConfig, true); + BuildConfig.BuildVersion = DateTime.Now.ToString("yyyy-MM-dd-HHmmss"); + } + catch (Exception) + { + BuildConfig.BuildVersion = DateTime.Now.ToString("yyyy-MM-dd-HHmmss"); + } } } @@ -234,27 +253,39 @@ private void OnDrawBuildBuild() BuildConfig.BuildMode = GELayout.Popup(BuildConfig.BuildMode, GEStyle.PreDropDown); } - if (Tags != null && Tags.Length > 0) + if (!(Tags is null) && Tags.Length > 0) { - using (new EditorGUILayout.HorizontalScope(GEStyle.ToolbarBottom)) + if (Tags.Length > 31) { - EditorGUILayout.LabelField("首包标签", GP_Width_100); - CurrentTagIndex = EditorGUILayout.MaskField(CurrentTagIndex, Tags, GEStyle.PreDropDown); + // 位运算最大支持31位 2^31 显示警告 + using (new EditorGUILayout.HorizontalScope(GEStyle.ToolbarBottom)) + { + EditorGUILayout.LabelField("首包标签", GP_Width_100); + EditorGUILayout.HelpBox("首包标签数量超过31个, 请减少标签数量", MessageType.Warning); + } } - - if (GUI.changed) + else { - BuildConfig.FirstPackTag = string.Empty; - for (var i = 0; i < Tags.Length; i++) + using (new EditorGUILayout.HorizontalScope(GEStyle.ToolbarBottom)) + { + EditorGUILayout.LabelField("首包标签", GP_Width_100); + CurrentTagIndex = EditorGUILayout.MaskField(CurrentTagIndex, Tags, GEStyle.PreDropDown); + } + + if (GUI.changed) { - if ((CurrentTagIndex & (1 << i)) != 0) + BuildConfig.FirstPackTag = string.Empty; + for (var i = 0; i < Tags.Length; i++) { - BuildConfig.FirstPackTag += string.Concat(Tags[i], ";"); + if ((CurrentTagIndex & (1 << i)) != 0) + { + BuildConfig.FirstPackTag += string.Concat(Tags[i], ";"); + } } } - } - if (CurrentTagIndex != 0) GELayout.HelpBox(BuildConfig.FirstPackTag); + if (CurrentTagIndex != 0) GELayout.HelpBox(BuildConfig.FirstPackTag); + } } using (new EditorGUILayout.HorizontalScope(GEStyle.ToolbarBottom)) @@ -264,12 +295,5 @@ private void OnDrawBuildBuild() } } } - - // private void OnDrawBuildNoticeDingDing() - // { - // // 钉钉 WebHook - // // 钉钉 Secret(请选择加签方式 内容过滤可能导致消息丢失) - // // 钉钉 通知事件类型列表 - // } } } \ No newline at end of file diff --git a/Editor/Windows/Mode/EditorMode/AssetCollectWindow.OnDrawEditor.cs b/Editor/Windows/Mode/EditorMode/AssetCollectWindow.OnDrawEditor.cs index 324fb68..bcd67c3 100644 --- a/Editor/Windows/Mode/EditorMode/AssetCollectWindow.OnDrawEditor.cs +++ b/Editor/Windows/Mode/EditorMode/AssetCollectWindow.OnDrawEditor.cs @@ -37,5 +37,15 @@ partial void OnDrawEditorMode() ViewCollectorsList.Draw(DoEditorDrawRect, () => { OnDrawGroupListScroll = GELayout.VScrollView(OnDrawGroupList, OnDrawGroupListScroll); }); } + + + protected void UpdateDataEditorMode() + { + if (Data.CurrentGroup.Length > 0) + { + CurrentCurrentCollectorsIndex = Data.CurrentGroup.Length - 1; + OnDrawItemListScroll.y = 0; + } + } } } \ No newline at end of file diff --git a/Editor/Windows/Mode/EditorMode/AssetCollectWindow.OnDrawGroup.cs b/Editor/Windows/Mode/EditorMode/AssetCollectWindow.OnDrawGroup.cs index 6ca82db..39a0a0d 100644 --- a/Editor/Windows/Mode/EditorMode/AssetCollectWindow.OnDrawGroup.cs +++ b/Editor/Windows/Mode/EditorMode/AssetCollectWindow.OnDrawGroup.cs @@ -82,7 +82,14 @@ partial void OnDrawGroup() { Data.CurrentGroupIndex = i; ViewGroupList.IsShow = true; - Data.CurrentGroup.Refresh(); + + if (Data.CurrentGroup.Length > 0) + { + Data.CurrentGroup.Refresh(); + CurrentCurrentCollectorsIndex = Data.CurrentGroup.Length - 1; + } + else CurrentCurrentCollectorsIndex = 0; + GUI.FocusControl(null); } } diff --git a/Editor/Windows/Mode/EditorMode/AssetCollectWindow.OnDrawGroupList.cs b/Editor/Windows/Mode/EditorMode/AssetCollectWindow.OnDrawGroupList.cs index 713a519..dcf4580 100644 --- a/Editor/Windows/Mode/EditorMode/AssetCollectWindow.OnDrawGroupList.cs +++ b/Editor/Windows/Mode/EditorMode/AssetCollectWindow.OnDrawGroupList.cs @@ -41,22 +41,37 @@ private void OnDrawPackageInfo() private void OnDrawItem() { if (!Data.IsCollectValid()) return; - for (var i = Data.CurrentGroup.Collectors.Length - 1; - i >= 0; - i--) + using (var sp = new EditorGUILayout.ScrollViewScope(OnDrawItemListScroll)) { - OnDrawItem(Data.CurrentGroup.Collectors[i]); - EditorGUILayout.Space(); + OnDrawItemListScroll = sp.scrollPosition; + for (var i = Data.CurrentGroup.Collectors.Length - 1; + i >= 0; + i--) + { + if (CurrentCurrentCollectorsIndex == i) + { + using (new EditorGUILayout.VerticalScope(GEStyle.SelectionRect)) + { + OnDrawItem(Data.CurrentGroup.Collectors[i], i); + } + } + else OnDrawItem(Data.CurrentGroup.Collectors[i], i); + + EditorGUILayout.Space(); + } } } partial void OnDrawGroupList() { - if (Data.Packages.Length <= 0) return; + if (Data.Length <= 0) return; using (new EditorGUILayout.VerticalScope(GEStyle.GridList)) { EditorGUILayout.Space(); - FoldoutPackageInfo = GELayout.VFoldoutHeaderGroupWithHelp(OnDrawPackageInfo, "Data Info", FoldoutPackageInfo); + FoldoutPackageInfo = GELayout.VFoldoutHeaderGroupWithHelp( + OnDrawPackageInfo, + "Data Info", + FoldoutPackageInfo); EditorGUILayout.Space(); var content = new GUIContent($"Collectors ({Data.CurrentGroup.Collectors.Length})"); @@ -64,7 +79,12 @@ partial void OnDrawGroupList() OnDrawItem, content, FoldoutCollectors, - () => { Data.CurrentGroup.Collectors = Data.CurrentGroup.Collectors.Add(new AssetCollectItem()); }, + () => + { + CurrentCurrentCollectorsIndex = Data.CurrentGroup.Collectors.Length; + OnDrawItemListScroll.y = 0; + Data.CurrentGroup.Collectors = Data.CurrentGroup.Collectors.Add(new AssetCollectItem()); + }, 0, null, new GUIContent("✚") diff --git a/Editor/Windows/Mode/EditorMode/AssetCollectWindow.OnDrawHeader.cs b/Editor/Windows/Mode/EditorMode/AssetCollectWindow.OnDrawHeader.cs index 2febab0..18f9abb 100644 --- a/Editor/Windows/Mode/EditorMode/AssetCollectWindow.OnDrawHeader.cs +++ b/Editor/Windows/Mode/EditorMode/AssetCollectWindow.OnDrawHeader.cs @@ -73,6 +73,11 @@ private void OnDrawHeaderEditorMode() } } + if (GUILayout.Button(GC_SORT, GEStyle.TEtoolbarbutton, GP_Width_30, GP_Height_20)) + { + Data.Sort(); + } + if (GUILayout.Button(GC_MERGE, GEStyle.TEtoolbarbutton, GP_Width_30, GP_Height_20)) { if (EditorUtility.DisplayDialog("合并", "确定合并当前资源包的所有组和收集器?", "确定", "取消")) diff --git a/Editor/Windows/Mode/EditorMode/AssetCollectWindow.OnDrawItem.cs b/Editor/Windows/Mode/EditorMode/AssetCollectWindow.OnDrawItem.cs index aac3406..3486e7a 100644 --- a/Editor/Windows/Mode/EditorMode/AssetCollectWindow.OnDrawItem.cs +++ b/Editor/Windows/Mode/EditorMode/AssetCollectWindow.OnDrawItem.cs @@ -29,22 +29,23 @@ private static string GetInfo(IEnumerable Displays, long source) return builder.ToString(); } - partial void OnDrawItem(AssetCollectItem item) + private void OnDrawItem(AssetCollectItem item, int index) { - using (GELayout.VHorizontal(GEStyle.Toolbar)) + using (new EditorGUILayout.HorizontalScope(GEStyle.Toolbar)) { if (item.Path is null) GUI.enabled = false; - if (GELayout.Button(item.Folded ? GC_FOLDOUT : GC_FOLDOUT_ON, + if (GUILayout.Button(item.Folded ? GC_FOLDOUT : GC_FOLDOUT_ON, GEStyle.TEtoolbarbutton, GP_Width_30)) { item.Folded = !item.Folded; + CurrentCurrentCollectorsIndex = index; GUI.FocusControl(null); } item.Type = GELayout.Popup(item.Type, GEStyle.PreDropDown, GP_Width_80); if (item.Path is null) GUI.enabled = true; - item.Path = GELayout.Field(item.Path, GTOption.Width(120)); + item.Path = GELayout.Field(item.Path, GTOption.WidthMin(120), GTOption.WidthMax(240)); if (item.Path is null) GUI.enabled = false; if (!item.Folded) @@ -61,7 +62,7 @@ partial void OnDrawItem(AssetCollectItem item) { if (!string.IsNullOrEmpty(item.CollectPath)) { - if (GELayout.Button(item.CollectPath, GEStyle.toolbarbutton)) + if (GUILayout.Button(item.CollectPath, GEStyle.toolbarbutton)) { _ = PrPlatform.Open.Path(item.CollectPath).Async(); } @@ -75,6 +76,7 @@ partial void OnDrawItem(AssetCollectItem item) if (GELayout.Button(GC_OPEN, GEStyle.TEtoolbarbutton, 24)) { + GUI.FocusControl(null); if (item.Type == EAssetCollectItemType.MainAssetCollector) { var status = 1; @@ -110,6 +112,25 @@ partial void OnDrawItem(AssetCollectItem item) GUI.FocusControl(null); if (EditorUtility.DisplayDialog("删除", "确定删除当前收集器?", "确定", "取消")) { + if (CurrentCurrentCollectorsIndex == index) + { + if (index == Data.CurrentGroup.Length - 1) + { + CurrentCurrentCollectorsIndex = index - 1; + OnDrawItemListScroll.y = 0; + } + else + { + CurrentCurrentCollectorsIndex = index; + OnDrawItemListScroll.y = index * 20; + } + } + else if (CurrentCurrentCollectorsIndex > index) + { + CurrentCurrentCollectorsIndex--; + OnDrawItemListScroll.y += 20; + } + Data.CurrentGroup.Collectors = Data.CurrentGroup.Collectors.Remove(item); } @@ -119,11 +140,11 @@ partial void OnDrawItem(AssetCollectItem item) if (!item.Folded) return; - using (GELayout.Vertical(GEStyle.PreBackground)) + using (new EditorGUILayout.VerticalScope(GEStyle.PreBackground)) { - using (GELayout.VHorizontal()) + using (new EditorGUILayout.HorizontalScope()) { - GELayout.Label("定位", GP_Width_25); + EditorGUILayout.LabelField("定位", GP_Width_25); if (Config.LoadPathToLower) { GUI.enabled = false; @@ -131,8 +152,9 @@ partial void OnDrawItem(AssetCollectItem item) GUI.enabled = true; } else - item.LocationFormat = - GELayout.Popup(item.LocationFormat, GEStyle.PreDropDown, GP_Width_80); + { + item.LocationFormat = GELayout.Popup(item.LocationFormat, GEStyle.PreDropDown, GP_Width_80); + } item.Address = GELayout.Popup(item.Address, AssetCollectSetting.MapAddress.Displays, GEStyle.PreDropDown); @@ -145,9 +167,9 @@ partial void OnDrawItem(AssetCollectItem item) GELayout.ToggleLeft("后缀", item.HasExtension, GTOption.Width(42)); } - using (GELayout.VHorizontal()) + using (new EditorGUILayout.HorizontalScope()) { - GELayout.Label("收集", GP_Width_25); + EditorGUILayout.LabelField("收集", GP_Width_25); if (item.RuleUseCollectCustom) { item.RuleCollect = GELayout.Field(item.RuleCollect); @@ -165,9 +187,9 @@ partial void OnDrawItem(AssetCollectItem item) item.RuleUseCollectCustom, GTOption.Width(42)); } - using (GELayout.VHorizontal()) + using (new EditorGUILayout.HorizontalScope()) { - GELayout.Label("过滤", GP_Width_25); + EditorGUILayout.LabelField("过滤", GP_Width_25); if (item.RuleUseFilterCustom) { item.RuleFilter = GELayout.Field(item.RuleFilter); @@ -187,18 +209,18 @@ partial void OnDrawItem(AssetCollectItem item) if (AssetCollectSetting.MapAddress.Displays[item.Address].Contains("UserData")) { - using (GELayout.VHorizontal()) + using (new EditorGUILayout.HorizontalScope()) { - GELayout.Label("自定", GP_Width_25); + EditorGUILayout.LabelField("自定", GP_Width_25); item.UserData = GELayout.Field(item.UserData); } } if (item.Type == EAssetCollectItemType.MainAssetCollector) { - using (GELayout.VHorizontal()) + using (new EditorGUILayout.HorizontalScope()) { - GELayout.Label("标签", GP_Width_25); + EditorGUILayout.LabelField(GC_Edit_Tags, GP_Width_25); item.Tags = GELayout.Field(item.Tags); } } diff --git a/Editor/Windows/Mode/EditorMode/AssetCollectWindow.OnDrawPackage.cs b/Editor/Windows/Mode/EditorMode/AssetCollectWindow.OnDrawPackage.cs index a92c840..8eebac4 100644 --- a/Editor/Windows/Mode/EditorMode/AssetCollectWindow.OnDrawPackage.cs +++ b/Editor/Windows/Mode/EditorMode/AssetCollectWindow.OnDrawPackage.cs @@ -49,7 +49,8 @@ partial void OnDrawPackage() { if (GUILayout.Button(GC_DEL, GEStyle.TEtoolbarbutton, GP_Width_20)) { - if (EditorUtility.DisplayDialog("Delete Package", $"Are you sure you want to delete {Data.Packages[i].Name}?", "Yes", "No")) + if (EditorUtility.DisplayDialog("Delete Package", + $"Are you sure you want to delete {Data.Packages[i].Name}?", "Yes", "No")) { Data.Packages = Data.Packages.RemoveAt(i); if (--Data.CurrentPackageIndex < 0) Data.CurrentPackageIndex = 0; @@ -70,7 +71,20 @@ partial void OnDrawPackage() if (GUILayout.Button(label, style, GTOption.WidthMin(100))) { Data.CurrentPackageIndex = i; + Data.CurrentGroupIndex = 0; ViewGroupList.IsShow = true; + if (Data.CurrentGroup.Length > 0) + { + Data.CurrentGroup.Refresh(); + CurrentCurrentCollectorsIndex = Data.CurrentGroup.Length - 1; + OnDrawItemListScroll.y = 0; + } + else + { + CurrentCurrentCollectorsIndex = 0; + } + + GUI.FocusControl(null); } } diff --git a/Extensions/YooAsset.CLI/Editor/1.5.7/ConvertYooAsset.AIOPackRule.cs b/Extensions/YooAsset.CLI/Editor/1.5.7/ConvertYooAsset.AIOPackRule.cs index aa9dc78..5b0e66e 100644 --- a/Extensions/YooAsset.CLI/Editor/1.5.7/ConvertYooAsset.AIOPackRule.cs +++ b/Extensions/YooAsset.CLI/Editor/1.5.7/ConvertYooAsset.AIOPackRule.cs @@ -20,7 +20,7 @@ public PackRuleResult GetPackRuleResult(PackRuleData data) { if (!data.GroupName.Contains('_')) throw new Exception("Error : Rule mismatch"); var info = data.GroupName.SplitOnce('_'); - var collector = Instance.GetPackage(info.Item1)?.GetGroup(info.Item2).GetCollector(data.CollectPath); + var collector = Instance.GetPackage(info.Item1)?.GetGroup(info.Item2)?.GetCollector(data.CollectPath); if (collector is null) throw new Exception("Error : Not found collector"); if (!Collectors.ContainsKey(collector)) { diff --git a/Runtime/Config/ASConfig.cs b/Runtime/Config/ASConfig.cs index 2fd774b..3424410 100644 --- a/Runtime/Config/ASConfig.cs +++ b/Runtime/Config/ASConfig.cs @@ -140,7 +140,7 @@ public void UpdatePackage() var assembly = Assembly.Load("AIO.Asset.Editor"); var type = assembly.GetType("AIO.UEditor.AssetCollectRoot", true); var getOrCreate = type.GetMethod("GetOrCreate", BindingFlags.Static | BindingFlags.Public); - var CollectRoot = getOrCreate?.Invoke(null, new object[] { true }); + var CollectRoot = getOrCreate?.Invoke(null, new object[] { }); if (CollectRoot is null) break; var packages = type.GetField("Packages", BindingFlags.Instance | BindingFlags.Public) ?.GetValue(CollectRoot);