mirror of https://github.com/tuyoogame/YooAsset
update UIElements
parent
793a57647d
commit
5e2fc84ebf
|
@ -1,12 +1,33 @@
|
||||||
#if UNITY_2019_4_OR_NEWER
|
#if UNITY_2019_4_OR_NEWER
|
||||||
|
using UnityEditor;
|
||||||
|
|
||||||
namespace YooAsset.Editor
|
namespace YooAsset.Editor
|
||||||
{
|
{
|
||||||
public class AssetPathCell : StringValueCell
|
public class AssetPathCell : StringValueCell
|
||||||
{
|
{
|
||||||
public AssetPathCell(string headerTitle) : base(headerTitle)
|
public AssetPathCell(string headerTitle, object cellValue) : base(headerTitle, cellValue)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 检视资源对象
|
||||||
|
/// Ping an asset object in the Scene like clicking it in an inspector.
|
||||||
|
/// </summary>
|
||||||
|
public bool PingAssetObject()
|
||||||
|
{
|
||||||
|
var assetPath = StringValue;
|
||||||
|
var assetGUID = AssetDatabase.AssetPathToGUID(assetPath);
|
||||||
|
if (string.IsNullOrEmpty(assetGUID))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
UnityEngine.Object asset = AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(assetPath);
|
||||||
|
if (asset == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
Selection.activeObject = asset;
|
||||||
|
EditorGUIUtility.PingObject(asset);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
|
@ -15,9 +15,10 @@ namespace YooAsset.Editor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public IntegerValueCell(string headerTitle)
|
public IntegerValueCell(string headerTitle, object cellValue)
|
||||||
{
|
{
|
||||||
HeaderTitle = headerTitle;
|
HeaderTitle = headerTitle;
|
||||||
|
CellValue = cellValue;
|
||||||
}
|
}
|
||||||
public object GetDisplayObject()
|
public object GetDisplayObject()
|
||||||
{
|
{
|
||||||
|
|
|
@ -15,9 +15,10 @@ namespace YooAsset.Editor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public SingleValueCell(string headerTitle)
|
public SingleValueCell(string headerTitle, object cellValue)
|
||||||
{
|
{
|
||||||
HeaderTitle = headerTitle;
|
HeaderTitle = headerTitle;
|
||||||
|
CellValue = cellValue;
|
||||||
}
|
}
|
||||||
public object GetDisplayObject()
|
public object GetDisplayObject()
|
||||||
{
|
{
|
||||||
|
|
|
@ -15,9 +15,10 @@ namespace YooAsset.Editor
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public StringValueCell(string headerTitle)
|
public StringValueCell(string headerTitle, object cellValue)
|
||||||
{
|
{
|
||||||
HeaderTitle = headerTitle;
|
HeaderTitle = headerTitle;
|
||||||
|
CellValue = cellValue;
|
||||||
}
|
}
|
||||||
public object GetDisplayObject()
|
public object GetDisplayObject()
|
||||||
{
|
{
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: f347ad29484952842a01a1489fbbef5d
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
|
@ -0,0 +1,50 @@
|
||||||
|
#if UNITY_2019_4_OR_NEWER
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEditor;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace YooAsset.Editor
|
||||||
|
{
|
||||||
|
public class DefaultTableData : ITableData
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 是否可见
|
||||||
|
/// </summary>
|
||||||
|
public bool Visible { set; get; } = true;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 单元格集合
|
||||||
|
/// </summary>
|
||||||
|
public IList<ITableCell> Cells { set; get; } = new List<ITableCell>();
|
||||||
|
|
||||||
|
#region 添加默认的单元格数据
|
||||||
|
public void AddButtonCell()
|
||||||
|
{
|
||||||
|
var cell = new ButtonCell();
|
||||||
|
Cells.Add(cell);
|
||||||
|
}
|
||||||
|
public void AddAssetPathCell(string headerTitle, string path)
|
||||||
|
{
|
||||||
|
var cell = new AssetPathCell(headerTitle, path);
|
||||||
|
Cells.Add(cell);
|
||||||
|
}
|
||||||
|
public void AddStringValueCell(string headerTitle, string value)
|
||||||
|
{
|
||||||
|
var cell = new StringValueCell(headerTitle, value);
|
||||||
|
Cells.Add(cell);
|
||||||
|
}
|
||||||
|
public void AddIntegerValueCell(string headerTitle, long value)
|
||||||
|
{
|
||||||
|
var cell = new IntegerValueCell(headerTitle, value);
|
||||||
|
Cells.Add(cell);
|
||||||
|
}
|
||||||
|
public void AddSingleValueCell(string headerTitle, double value)
|
||||||
|
{
|
||||||
|
var cell = new SingleValueCell(headerTitle, value);
|
||||||
|
Cells.Add(cell);
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: b93bf9f1eb7024c44a1c84b299dc9622
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
|
@ -15,6 +15,13 @@ namespace YooAsset.Editor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class TableView : VisualElement
|
public class TableView : VisualElement
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Instantiates a TableView using data from a UXML file.
|
||||||
|
/// </summary>
|
||||||
|
public new class UxmlFactory : UxmlFactory<TableView, UxmlTraits>
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
private readonly Toolbar _toolbar;
|
private readonly Toolbar _toolbar;
|
||||||
private readonly ListView _listView;
|
private readonly ListView _listView;
|
||||||
|
|
||||||
|
@ -55,6 +62,11 @@ namespace YooAsset.Editor
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public Action<TableColumn> ClickTableHeadEvent;
|
public Action<TableColumn> ClickTableHeadEvent;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 单元视图变化事件
|
||||||
|
/// </summary>
|
||||||
|
public Action<ITableData> SelectionChangedEvent;
|
||||||
|
|
||||||
|
|
||||||
public TableView()
|
public TableView()
|
||||||
{
|
{
|
||||||
|
@ -65,6 +77,15 @@ namespace YooAsset.Editor
|
||||||
_listView.makeItem = MakeListViewElement;
|
_listView.makeItem = MakeListViewElement;
|
||||||
_listView.bindItem = BindListViewElement;
|
_listView.bindItem = BindListViewElement;
|
||||||
_listView.RegisterCallback<PointerDownEvent>(OnClickListItem);
|
_listView.RegisterCallback<PointerDownEvent>(OnClickListItem);
|
||||||
|
|
||||||
|
#if UNITY_2022_3_OR_NEWER
|
||||||
|
_listView.selectionChanged += OnSelectionChanged;
|
||||||
|
#elif UNITY_2020_1_OR_NEWER
|
||||||
|
_listView.onSelectionChange += OnSelectionChanged;
|
||||||
|
#else
|
||||||
|
_listView.onSelectionChanged += OnSelectionChanged;
|
||||||
|
#endif
|
||||||
|
|
||||||
this.Add(_listView);
|
this.Add(_listView);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,37 +142,28 @@ namespace YooAsset.Editor
|
||||||
_listView.Rebuild();
|
_listView.Rebuild();
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool CheckItemsSource(List<ITableData> itemsSource)
|
/// <summary>
|
||||||
|
/// 清空所有数据
|
||||||
|
/// </summary>
|
||||||
|
public void ClearAll(bool clearColumns, bool clearSource)
|
||||||
{
|
{
|
||||||
if (itemsSource == null || itemsSource.Count == 0)
|
if (clearColumns)
|
||||||
{
|
{
|
||||||
Debug.LogWarning("Items source is null or empty !");
|
_columns.Clear();
|
||||||
return false;
|
_toolbar.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
int cellCount = itemsSource[0].Cells.Count;
|
if (clearSource)
|
||||||
for (int i = 0; i < itemsSource.Count; i++)
|
|
||||||
{
|
{
|
||||||
var tableData = itemsSource[i];
|
if (_itemsSource != null)
|
||||||
if (tableData == null)
|
_itemsSource.Clear();
|
||||||
{
|
if (_sortingDatas != null)
|
||||||
Debug.LogWarning($"Items source has null instance !");
|
_sortingDatas.Clear();
|
||||||
return false;
|
_listView.Clear();
|
||||||
}
|
_listView.ClearSelection();
|
||||||
if (tableData.Cells == null || tableData.Cells.Count == 0)
|
|
||||||
{
|
|
||||||
Debug.LogWarning($"Items source data has empty cells !");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (tableData.Cells.Count != cellCount)
|
|
||||||
{
|
|
||||||
Debug.LogWarning($"Items source data has inconsisten cells count ! Item index {i}");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnClickListItem(PointerDownEvent evt)
|
private void OnClickListItem(PointerDownEvent evt)
|
||||||
{
|
{
|
||||||
var selectData = _listView.selectedItem as ITableData;
|
var selectData = _listView.selectedItem as ITableData;
|
||||||
|
@ -204,6 +216,47 @@ namespace YooAsset.Editor
|
||||||
// 刷新数据表
|
// 刷新数据表
|
||||||
RebuildView();
|
RebuildView();
|
||||||
}
|
}
|
||||||
|
private void OnSelectionChanged(IEnumerable<object> items)
|
||||||
|
{
|
||||||
|
foreach (var item in items)
|
||||||
|
{
|
||||||
|
var tableData = item as ITableData;
|
||||||
|
SelectionChangedEvent?.Invoke(tableData);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool CheckItemsSource(List<ITableData> itemsSource)
|
||||||
|
{
|
||||||
|
if (itemsSource == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (itemsSource.Count > 0)
|
||||||
|
{
|
||||||
|
int cellCount = itemsSource[0].Cells.Count;
|
||||||
|
for (int i = 0; i < itemsSource.Count; i++)
|
||||||
|
{
|
||||||
|
var tableData = itemsSource[i];
|
||||||
|
if (tableData == null)
|
||||||
|
{
|
||||||
|
Debug.LogWarning($"Items source has null instance !");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (tableData.Cells == null || tableData.Cells.Count == 0)
|
||||||
|
{
|
||||||
|
Debug.LogWarning($"Items source data has empty cells !");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (tableData.Cells.Count != cellCount)
|
||||||
|
{
|
||||||
|
Debug.LogWarning($"Items source data has inconsisten cells count ! Item index {i}");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
private VisualElement MakeListViewElement()
|
private VisualElement MakeListViewElement()
|
||||||
{
|
{
|
||||||
VisualElement listViewElement = new VisualElement();
|
VisualElement listViewElement = new VisualElement();
|
||||||
|
|
Loading…
Reference in New Issue