diff --git a/Assets/YooAsset/Editor/AssetArtReporter/ReportHeader.cs b/Assets/YooAsset/Editor/AssetArtReporter/ReportHeader.cs index 4009c367..adb05c1e 100644 --- a/Assets/YooAsset/Editor/AssetArtReporter/ReportHeader.cs +++ b/Assets/YooAsset/Editor/AssetArtReporter/ReportHeader.cs @@ -20,7 +20,7 @@ namespace YooAsset.Editor /// /// 单元列最小宽度 /// - public int MinWidth = 30; + public int MinWidth = 50; /// /// 单元列最大宽度 @@ -52,7 +52,17 @@ namespace YooAsset.Editor { HeaderTitle = headerTitle; Width = width; + MinWidth = width; + MaxWidth = width; } + public ReportHeader(string headerTitle, int width, int minWidth, int maxWidth) + { + HeaderTitle = headerTitle; + Width = width; + MinWidth = minWidth; + MaxWidth = maxWidth; + } + public ReportHeader SetMinWidth(int value) { MinWidth = value; diff --git a/Assets/YooAsset/Editor/AssetArtReporter/ScanReport.cs b/Assets/YooAsset/Editor/AssetArtReporter/ScanReport.cs index 3da7c5b2..b8133dca 100644 --- a/Assets/YooAsset/Editor/AssetArtReporter/ScanReport.cs +++ b/Assets/YooAsset/Editor/AssetArtReporter/ScanReport.cs @@ -61,5 +61,11 @@ namespace YooAsset.Editor HeaderTitles.Add(reportHeader); return reportHeader; } + public ReportHeader AddHeader(string headerTitle, int width, int minWidth, int maxWidth) + { + var reportHeader = new ReportHeader(headerTitle, width, minWidth, maxWidth); + HeaderTitles.Add(reportHeader); + return reportHeader; + } } } \ No newline at end of file diff --git a/Assets/YooAsset/Editor/UIElements/ElementsDefine/PanelSplitView.cs b/Assets/YooAsset/Editor/UIElements/ElementsDefine/PanelSplitView.cs index d4cbf918..85ccead2 100644 --- a/Assets/YooAsset/Editor/UIElements/ElementsDefine/PanelSplitView.cs +++ b/Assets/YooAsset/Editor/UIElements/ElementsDefine/PanelSplitView.cs @@ -17,7 +17,7 @@ namespace YooAsset.Editor { } #else - public new class UxmlFactory : UxmlFactory + public new class UxmlFactory : UxmlFactory { } #endif diff --git a/Assets/YooAsset/Editor/UIElements/ElementsDefine/ResizeHandle.cs b/Assets/YooAsset/Editor/UIElements/ElementsDefine/ResizeHandle.cs new file mode 100644 index 00000000..87e4280a --- /dev/null +++ b/Assets/YooAsset/Editor/UIElements/ElementsDefine/ResizeHandle.cs @@ -0,0 +1,111 @@ +#if UNITY_2019_4_OR_NEWER +using System; +using UnityEditor; +using UnityEngine; +using UnityEditor.UIElements; +using UnityEngine.UIElements; + +namespace YooAsset.Editor +{ + public class ResizeHandle : VisualElement + { + /// + /// Instantiates a TableView using data from a UXML file. + /// + public new class UxmlFactory : UxmlFactory + { + } + + private bool _isResizing = false; + private float _initialWidth; + private Vector2 _initialMousePos; + + /// + /// 控制的UI元素 + /// + public VisualElement ControlTarget { get; set; } + + /// + /// 控制元素的最小宽度 + /// + public int ControlMinWidth { get; set; } + + /// + /// 控制元素的最大宽度 + /// + public int ControlMaxWidth { get; set; } + + /// + /// 尺寸发生变化 + /// + public Action ResizeChanged { get; set; } + + public ResizeHandle() + { + int defaultWidth = 5; + this.style.width = defaultWidth; + this.style.minWidth = defaultWidth; + this.style.maxWidth = defaultWidth; + this.style.opacity = 0; + this.style.cursor = UIElementsCursor.CreateCursor(MouseCursor.ResizeHorizontal); + + this.RegisterCallback(OnMouseDown); + this.RegisterCallback(OnMouseMove); + this.RegisterCallback(OnMouseUp); + } + public ResizeHandle(int handleWidth, VisualElement controlTarget, int controlMinWidth, int controlMaxWidth) + { + ControlTarget = controlTarget; + ControlMinWidth = controlMinWidth; + ControlMaxWidth = controlMaxWidth; + + this.style.width = handleWidth; + this.style.minWidth = handleWidth; + this.style.maxWidth = handleWidth; + this.style.opacity = 0; + this.style.cursor = UIElementsCursor.CreateCursor(MouseCursor.ResizeHorizontal); + + this.RegisterCallback(OnMouseDown); + this.RegisterCallback(OnMouseMove); + this.RegisterCallback(OnMouseUp); + } + + private void OnMouseDown(MouseDownEvent evt) + { + // 鼠标左键按下 + if (ControlTarget != null && evt.button == 0) + { + _isResizing = true; + _initialWidth = ControlTarget.resolvedStyle.width; + _initialMousePos = evt.mousePosition; + this.CaptureMouse(); + } + } + private void OnMouseMove(MouseMoveEvent evt) + { + if (ControlTarget != null && _isResizing) + { + // 计算鼠标移动距离 + float deltaX = evt.mousePosition.x - _initialMousePos.x; + + // 更新控制元素尺寸 + float newWidth = _initialWidth + deltaX; + float width = Mathf.Clamp(newWidth, ControlMinWidth, ControlMaxWidth); + ControlTarget.style.width = width; + ControlTarget.style.minWidth = width; + ControlTarget.style.maxWidth = width; + ResizeChanged?.Invoke(width); + } + } + private void OnMouseUp(MouseUpEvent evt) + { + // 鼠标左键释放 + if (ControlTarget != null && evt.button == 0) + { + _isResizing = false; + this.ReleaseMouse(); + } + } + } +} +#endif \ No newline at end of file diff --git a/Assets/YooAsset/Editor/UIElements/ElementsDefine/ResizeHandle.cs.meta b/Assets/YooAsset/Editor/UIElements/ElementsDefine/ResizeHandle.cs.meta new file mode 100644 index 00000000..4b892d89 --- /dev/null +++ b/Assets/YooAsset/Editor/UIElements/ElementsDefine/ResizeHandle.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: adb565f9b5e9fb3428e54d0cfd58676d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/YooAsset/Editor/UIElements/TableView/TableColumn.cs b/Assets/YooAsset/Editor/UIElements/TableView/TableColumn.cs index aada90ef..3c2b2a6c 100644 --- a/Assets/YooAsset/Editor/UIElements/TableView/TableColumn.cs +++ b/Assets/YooAsset/Editor/UIElements/TableView/TableColumn.cs @@ -1,5 +1,6 @@ #if UNITY_2019_4_OR_NEWER using System; +using System.Collections.Generic; using UnityEditor; using UnityEngine; using UnityEditor.UIElements; @@ -14,6 +15,11 @@ namespace YooAsset.Editor /// internal int ColumnIndex; + /// + /// 单元元素集合 + /// + internal List CellElements = new List(1000); + /// /// UI元素名称 /// diff --git a/Assets/YooAsset/Editor/UIElements/TableView/TableView.cs b/Assets/YooAsset/Editor/UIElements/TableView/TableView.cs index 76ee6d0e..797fa29b 100644 --- a/Assets/YooAsset/Editor/UIElements/TableView/TableView.cs +++ b/Assets/YooAsset/Editor/UIElements/TableView/TableView.cs @@ -127,15 +127,37 @@ namespace YooAsset.Editor toolbarBtn.name = column.ElementName; toolbarBtn.text = column.HeaderTitle; toolbarBtn.style.unityTextAlign = column.ColumnStyle.TxtAnchor; - toolbarBtn.style.flexGrow = column.ColumnStyle.Stretchable ? 1f : 0f; + toolbarBtn.style.flexGrow = 0; toolbarBtn.style.width = column.ColumnStyle.Width; - toolbarBtn.style.minWidth = column.ColumnStyle.MinWidth; - toolbarBtn.style.maxWidth = column.ColumnStyle.MaxWidth; + toolbarBtn.style.minWidth = column.ColumnStyle.Width; + toolbarBtn.style.maxWidth = column.ColumnStyle.Width; toolbarBtn.clickable.clickedWithEventInfo += OnClickTableHead; SetCellElementStyle(toolbarBtn); _toolbar.Add(toolbarBtn); _columns.Add(column); + // 可伸缩控制柄 + if (column.ColumnStyle.Stretchable) + { + int handleWidth = 3; + int minWidth = (int)column.ColumnStyle.MinWidth.value; + int maxWidth = (int)column.ColumnStyle.MaxWidth.value; + var resizeHandle = new ResizeHandle(handleWidth, toolbarBtn, minWidth, maxWidth); + resizeHandle.ResizeChanged += (float value) => + { + float width = Mathf.Clamp(value, column.ColumnStyle.MinWidth.value, column.ColumnStyle.MaxWidth.value); + column.ColumnStyle.Width = width; + + foreach (var element in column.CellElements) + { + element.style.width = width; + element.style.minWidth = width; + element.style.maxWidth = width; + } + }; + _toolbar.Add(resizeHandle); + } + // 计算索引值 column.ColumnIndex = _columns.Count - 1; @@ -293,8 +315,10 @@ namespace YooAsset.Editor { var cellElement = colum.MakeCell.Invoke(); cellElement.name = colum.ElementName; + cellElement.style.flexGrow = 0f; SetCellElementStyle(cellElement); listViewElement.Add(cellElement); + colum.CellElements.Add(cellElement); } return listViewElement; } @@ -314,12 +338,13 @@ namespace YooAsset.Editor StyleLength defaultStyle = new StyleLength(1f); element.style.paddingTop = defaultStyle; element.style.paddingBottom = defaultStyle; - element.style.paddingLeft = defaultStyle; - element.style.paddingRight = defaultStyle; element.style.marginTop = defaultStyle; element.style.marginBottom = defaultStyle; - element.style.marginLeft = defaultStyle; - element.style.marginRight = defaultStyle; + + element.style.paddingLeft = 1; + element.style.paddingRight = 1; + element.style.marginLeft = 0; + element.style.marginRight = 0; } } } diff --git a/Assets/YooAsset/Editor/UIElements/UIElementsCursor.cs b/Assets/YooAsset/Editor/UIElements/UIElementsCursor.cs new file mode 100644 index 00000000..2d33cebf --- /dev/null +++ b/Assets/YooAsset/Editor/UIElements/UIElementsCursor.cs @@ -0,0 +1,30 @@ +#if UNITY_2019_4_OR_NEWER +using System.Reflection; +using UnityEditor; + +namespace YooAsset.Editor +{ + public static class UIElementsCursor + { + private static PropertyInfo _defaultCursorId; + private static PropertyInfo DefaultCursorId + { + get + { + if (_defaultCursorId != null) + return _defaultCursorId; + + _defaultCursorId = typeof(UnityEngine.UIElements.Cursor).GetProperty("defaultCursorId", BindingFlags.NonPublic | BindingFlags.Instance); + return _defaultCursorId; + } + } + + public static UnityEngine.UIElements.Cursor CreateCursor(MouseCursor cursorType) + { + var ret = (object)new UnityEngine.UIElements.Cursor(); + DefaultCursorId.SetValue(ret, (int)cursorType); + return (UnityEngine.UIElements.Cursor)ret; + } + } +} +#endif \ No newline at end of file diff --git a/Assets/YooAsset/Editor/UIElements/UIElementsCursor.cs.meta b/Assets/YooAsset/Editor/UIElements/UIElementsCursor.cs.meta new file mode 100644 index 00000000..4545b8ac --- /dev/null +++ b/Assets/YooAsset/Editor/UIElements/UIElementsCursor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 35d99a1727f773b46bc6a7bb1a2be970 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: