Compare commits

..

No commits in common. "b74a44dc36e3d3d1af222e882811c412becb939c" and "56ae1a8f95eb22426501c5ee56881f1e1832de80" have entirely different histories.

11 changed files with 56 additions and 364 deletions

View File

@ -22,8 +22,11 @@ namespace YooAsset.Editor
private TableView _operationTableView;
private Toolbar _bottomToolbar;
private TreeViewer _childTreeView;
#if UNITY_2022_3_OR_NEWER
private TreeView _childTreeView;
#endif
private int _treeItemID = 0;
private List<ITableData> _sourceDatas;
@ -50,9 +53,11 @@ namespace YooAsset.Editor
CreateBottomToolbarHeaders();
// 子列表
_childTreeView = _root.Q<TreeViewer>("BottomTreeView");
#if UNITY_2022_3_OR_NEWER
_childTreeView = _root.Q<TreeView>("BottomTreeView");
_childTreeView.makeItem = MakeTreeViewItem;
_childTreeView.bindItem = BindTreeViewItem;
#endif
// 面板分屏
var topGroup = _root.Q<VisualElement>("TopGroup");
@ -302,8 +307,11 @@ namespace YooAsset.Editor
{
// 清空旧数据
_operationTableView.ClearAll(false, true);
_childTreeView.ClearAll();
_childTreeView.RebuildView();
#if UNITY_2022_3_OR_NEWER
_childTreeView.SetRootItems(new List<TreeViewItemData<DebugOperationInfo>>());
_childTreeView.Rebuild();
#endif
// 填充数据源
_sourceDatas = new List<ITableData>(1000);
@ -337,7 +345,10 @@ namespace YooAsset.Editor
public void ClearView()
{
_operationTableView.ClearAll(false, true);
_childTreeView.ClearAll();
#if UNITY_2022_3_OR_NEWER
_childTreeView.SetRootItems(new List<TreeViewItemData<DebugOperationInfo>>());
_childTreeView.Rebuild();
#endif
RebuildView(null);
}
@ -351,7 +362,6 @@ namespace YooAsset.Editor
// 重建视图
_operationTableView.RebuildView();
_childTreeView.RebuildView();
}
/// <summary>
@ -370,20 +380,23 @@ namespace YooAsset.Editor
_root.RemoveFromHierarchy();
}
#if UNITY_2022_3_OR_NEWER
private void OnOperationTableViewSelectionChanged(ITableData data)
{
var operationTableData = data as OperationTableData;
DebugPackageData packageData = operationTableData.PackageData;
DebugOperationInfo operationInfo = operationTableData.OperationInfo;
TreeNode rootNode = new TreeNode(operationInfo);
FillTreeData(operationInfo, rootNode);
_childTreeView.ClearAll();
_childTreeView.SetRootItem(rootNode);
_childTreeView.RebuildView();
_treeItemID = 0;
var rootItems = CreateTreeData(operationInfo);
_childTreeView.SetRootItems(rootItems);
_childTreeView.Rebuild();
}
private void MakeTreeViewItem(VisualElement container)
private VisualElement MakeTreeViewItem()
{
VisualElement treeViewElement = new VisualElement();
treeViewElement.style.flexDirection = FlexDirection.Row;
// OperationName
{
Label label = new Label();
@ -391,7 +404,7 @@ namespace YooAsset.Editor
label.style.flexGrow = 0f;
label.style.width = 300;
label.style.unityTextAlign = TextAnchor.MiddleLeft;
container.Add(label);
treeViewElement.Add(label);
}
// Progress
@ -401,7 +414,7 @@ namespace YooAsset.Editor
label.style.flexGrow = 0f;
label.style.width = 100;
label.style.unityTextAlign = TextAnchor.MiddleLeft;
container.Add(label);
treeViewElement.Add(label);
}
// BeginTime
@ -411,7 +424,7 @@ namespace YooAsset.Editor
label.style.flexGrow = 0f;
label.style.width = 100;
label.style.unityTextAlign = TextAnchor.MiddleLeft;
container.Add(label);
treeViewElement.Add(label);
}
// ProcessTime
@ -421,7 +434,7 @@ namespace YooAsset.Editor
label.style.flexGrow = 0f;
label.style.width = 100;
label.style.unityTextAlign = TextAnchor.MiddleLeft;
container.Add(label);
treeViewElement.Add(label);
}
// Status
@ -431,7 +444,7 @@ namespace YooAsset.Editor
label.style.flexGrow = 0f;
label.style.width = 100;
label.style.unityTextAlign = TextAnchor.MiddleLeft;
container.Add(label);
treeViewElement.Add(label);
}
// Desc
@ -441,34 +454,36 @@ namespace YooAsset.Editor
label.style.flexGrow = 1f;
label.style.width = 500;
label.style.unityTextAlign = TextAnchor.MiddleLeft;
container.Add(label);
treeViewElement.Add(label);
}
return treeViewElement;
}
private void BindTreeViewItem(VisualElement container, object userData)
private void BindTreeViewItem(VisualElement element, int index)
{
var operationInfo = userData as DebugOperationInfo;
var operationInfo = _childTreeView.GetItemDataForIndex<DebugOperationInfo>(index);
// OperationName
{
var label = container.Q<Label>("OperationName");
var label = element.Q<Label>("OperationName");
label.text = operationInfo.OperationName;
}
// Progress
{
var label = container.Q<Label>("Progress");
var label = element.Q<Label>("Progress");
label.text = operationInfo.Progress.ToString();
}
// BeginTime
{
var label = container.Q<Label>("BeginTime");
var label = element.Q<Label>("BeginTime");
label.text = operationInfo.BeginTime;
}
// ProcessTime
{
var label = container.Q<Label>("ProcessTime");
var label = element.Q<Label>("ProcessTime");
label.text = operationInfo.ProcessTime.ToString();
}
@ -480,26 +495,33 @@ namespace YooAsset.Editor
else
textColor = new StyleColor(Color.white);
var label = container.Q<Label>("Status");
var label = element.Q<Label>("Status");
label.text = operationInfo.Status;
label.style.color = textColor;
}
// Desc
{
var label = container.Q<Label>("Desc");
var label = element.Q<Label>("Desc");
label.text = operationInfo.OperationDesc;
}
}
private void FillTreeData(DebugOperationInfo parentOperation, TreeNode rootNode)
private List<TreeViewItemData<DebugOperationInfo>> CreateTreeData(DebugOperationInfo parentOperation)
{
var rootItemList = new List<TreeViewItemData<DebugOperationInfo>>();
foreach (var childOperation in parentOperation.Childs)
{
var childNode = new TreeNode(childOperation);
rootNode.AddChild(childNode);
FillTreeData(childOperation, childNode);
var childItemList = CreateTreeData(childOperation);
var treeItem = new TreeViewItemData<DebugOperationInfo>(_treeItemID++, childOperation, childItemList);
rootItemList.Add(treeItem);
}
return rootItemList;
}
#else
private void OnOperationTableViewSelectionChanged(ITableData data)
{
}
#endif
}
}
#endif

View File

@ -4,6 +4,6 @@
</ui:VisualElement>
<ui:VisualElement name="BottomGroup" style="flex-grow: 1;">
<uie:Toolbar name="BottomToolbar" />
<YooAsset.Editor.TreeViewer name="BottomTreeView" />
<ui:TreeView name="BottomTreeView" />
</ui:VisualElement>
</ui:UXML>

View File

@ -1,55 +0,0 @@
#if UNITY_2019_4_OR_NEWER
using System;
using UnityEditor;
using UnityEngine;
using UnityEditor.UIElements;
using UnityEngine.UIElements;
namespace YooAsset.Editor
{
/// <summary>
/// 折叠开关
/// </summary>
public class ToggleFoldout : Toggle
{
public new class UxmlFactory : UxmlFactory<ToggleFoldout, UxmlTraits>
{
}
private readonly VisualElement _checkbox;
public ToggleFoldout()
{
_checkbox = this.Q<VisualElement>("unity-checkmark");
RefreshIcon();
}
public override void SetValueWithoutNotify(bool newValue)
{
base.SetValueWithoutNotify(newValue);
RefreshIcon();
}
#if UNITY_2021_3_OR_NEWER
protected override void ToggleValue()
{
base.ToggleValue();
RefreshIcon();
}
#endif
public void RefreshIcon()
{
if (this.value)
{
var icon = EditorGUIUtility.IconContent(UIElementsIcon.FoldoutOn).image as Texture2D;
_checkbox.style.backgroundImage = icon;
}
else
{
var icon = EditorGUIUtility.IconContent(UIElementsIcon.FoldoutOff).image as Texture2D;
_checkbox.style.backgroundImage = icon;
}
}
}
}
#endif

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 2619997e70d98794da26a947f9129e25
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 1797f960cdbd5aa41a96bb02d16c4998
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,77 +0,0 @@
#if UNITY_2019_4_OR_NEWER
using System.IO;
using System.Linq;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEditor.UIElements;
using UnityEngine.UIElements;
namespace YooAsset.Editor
{
public class TreeNode
{
/// <summary>
/// 子节点集合
/// </summary>
public List<TreeNode> Children = new List<TreeNode>(10);
/// <summary>
/// 父节点
/// </summary>
public TreeNode Parent { get; set; }
/// <summary>
/// 用户数据
/// </summary>
public object UserData { get; set; }
/// <summary>
/// 是否展开
/// </summary>
public bool IsExpanded { get; set; } = false;
public TreeNode(object userData)
{
UserData = userData;
}
/// <summary>
/// 添加子节点
/// </summary>
public void AddChild(TreeNode child)
{
child.Parent = this;
Children.Add(child);
}
/// <summary>
/// 清理所有子节点
/// </summary>
public void ClearChildren()
{
foreach(var child in Children)
{
child.Parent = null;
}
Children.Clear();
}
/// <summary>
/// 计算节点的深度
/// </summary>
public int GetDepth()
{
int depth = 0;
TreeNode current = this;
while (current.Parent != null)
{
depth++;
current = current.Parent;
}
return depth;
}
}
}
#endif

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 473cdc8e1dd7b0f43938ddb99287a2a8
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,152 +0,0 @@
#if UNITY_2019_4_OR_NEWER
using System;
using System.Linq;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEditor.UIElements;
using UnityEngine.UIElements;
namespace YooAsset.Editor
{
public class TreeViewer : VisualElement
{
public new class UxmlFactory : UxmlFactory<TreeViewer, UxmlTraits>
{
}
private readonly ListView _listView;
private readonly List<TreeNode> _flattenList = new List<TreeNode>(1000);
private readonly List<TreeNode> _rootList = new List<TreeNode>(100);
/// <summary>
/// 制作列表元素
/// </summary>
public Action<VisualElement> makeItem { get; set; }
/// <summary>
/// 绑定列表数据
/// </summary>
public Action<VisualElement, object> bindItem { get; set; }
public TreeViewer()
{
this.style.flexShrink = 1f;
this.style.flexGrow = 1f;
// 创建ListView
_listView = new ListView();
_listView.style.flexShrink = 1f;
_listView.style.flexGrow = 1f;
_listView.itemsSource = _flattenList;
_listView.makeItem = MakeItemInternal;
_listView.bindItem = BindItemInternal;
this.Add(_listView);
}
/// <summary>
/// 设置根节点数据
/// </summary>
public void SetRootItem(TreeNode rootNode)
{
_rootList.Add(rootNode);
}
/// <summary>
/// 设置根节点数据
/// </summary>
public void SetRootItems(List<TreeNode> rootNodes)
{
_rootList.AddRange(rootNodes);
}
/// <summary>
/// 清理数据
/// </summary>
public void ClearAll()
{
_rootList.Clear();
}
/// <summary>
/// 重新绘制视图
/// </summary>
public void RebuildView()
{
_flattenList.Clear();
foreach (var treeRoot in _rootList)
{
FlattenTree(treeRoot, 0);
}
_listView.Rebuild();
}
/// <summary>
/// 将树形结构扁平化为列表
/// </summary>
private void FlattenTree(TreeNode node, int depth)
{
_flattenList.Add(node);
if (node.IsExpanded)
{
foreach (var child in node.Children)
{
FlattenTree(child, depth + 1);
}
}
}
private VisualElement MakeItemInternal()
{
var container = new VisualElement();
container.style.flexDirection = FlexDirection.Row;
// 折叠按钮
var toggle = new ToggleFoldout();
toggle.text = string.Empty;
toggle.name = "foldout";
toggle.style.alignSelf = Align.Center;
toggle.style.width = 15;
toggle.style.height = 15;
toggle.RegisterValueChangedCallback((ChangeEvent<bool> callback) =>
{
var treeNode = toggle.userData as TreeNode;
treeNode.IsExpanded = toggle.value;
RebuildView();
});
container.Add(toggle);
// 用户自定义元素
if (makeItem != null)
{
makeItem.Invoke(container);
}
return container;
}
private void BindItemInternal(VisualElement item, int index)
{
var treeNode = _flattenList[index];
// 设置折叠状态
var toggle = item.Q<ToggleFoldout>("foldout");
toggle.SetValueWithoutNotify(treeNode.IsExpanded);
toggle.userData = treeNode;
toggle.style.marginLeft = treeNode.GetDepth() * 15;
// 隐藏折叠按钮
if (treeNode.Children.Count == 0)
{
toggle.style.visibility = Visibility.Hidden;
}
// 用户自定义元素
if (bindItem != null)
{
bindItem.Invoke(item, treeNode.UserData);
}
}
}
}
#endif

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: db2fb30e2d4512149b615fe6b2562ecd
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -10,14 +10,6 @@ namespace YooAsset.Editor
public const string RecordOn = "d_Record On@2x";
public const string RecordOff = "d_Record Off@2x";
#if UNITY_2019
public const string FoldoutOn = "IN foldout on";
public const string FoldoutOff = "IN foldout";
#else
public const string FoldoutOn = "d_IN_foldout_on@2x";
public const string FoldoutOff = "d_IN_foldout@2x";
#endif
public const string VisibilityToggleOff = "animationvisibilitytoggleoff@2x";
public const string VisibilityToggleOn = "animationvisibilitytoggleon@2x";
}

View File

@ -23,10 +23,12 @@ namespace YooAsset
public void Initialize()
{
Debug.LogWarning("X=Initialize");
_messageCallbacks.Clear();
}
public void Register(Guid messageID, UnityAction<MessageEventArgs> callback)
{
Debug.LogWarning("X=Register");
if (messageID == Guid.Empty)
throw new ArgumentException("messageID is empty !");
@ -35,6 +37,7 @@ namespace YooAsset
}
public void Unregister(Guid messageID)
{
Debug.LogWarning("X=Unregister");
if (_messageCallbacks.ContainsKey(messageID))
_messageCallbacks.Remove(messageID);
}