update diagnostic system

pull/497/head
何冠峰 2025-02-28 18:38:18 +08:00
parent e7d346e4e1
commit 3069b1d1f1
44 changed files with 765 additions and 172 deletions

View File

@ -326,7 +326,7 @@ namespace YooAsset.Editor
var column = new TableColumn("眼睛框", string.Empty, columnStyle);
column.MakeCell = () =>
{
var toggle = new DisplayToggle();
var toggle = new ToggleDisplay();
toggle.text = string.Empty;
toggle.style.unityTextAlign = TextAnchor.MiddleCenter;
toggle.RegisterValueChangedCallback((evt) => { OnDisplayToggleValueChange(toggle, evt); });
@ -334,11 +334,10 @@ namespace YooAsset.Editor
};
column.BindCell = (VisualElement element, ITableData data, ITableCell cell) =>
{
var toggle = element as DisplayToggle;
var toggle = element as ToggleDisplay;
toggle.userData = data;
var tableData = data as ElementTableData;
toggle.SetValueWithoutNotify(tableData.Element.Hidden);
toggle.RefreshIcon();
};
_elementTableView.AddColumn(column);
var headerElement = _elementTableView.GetHeaderElement("眼睛框");
@ -577,10 +576,8 @@ namespace YooAsset.Editor
// 重绘视图
RebuildView();
}
private void OnDisplayToggleValueChange(DisplayToggle toggle, ChangeEvent<bool> e)
private void OnDisplayToggleValueChange(ToggleDisplay toggle, ChangeEvent<bool> e)
{
toggle.RefreshIcon();
// 处理自身
toggle.SetValueWithoutNotify(e.newValue);

View File

@ -48,7 +48,7 @@ namespace YooAsset.Editor
private readonly Dictionary<int, RemotePlayerSession> _playerSessions = new Dictionary<int, RemotePlayerSession>();
private Label _playerName;
private ToolbarButton _playerName;
private ToolbarMenu _viewModeMenu;
private SliderInt _frameSlider;
private DebuggerAssetListViewer _assetListViewer;
@ -84,7 +84,7 @@ namespace YooAsset.Editor
exportBtn.clicked += ExportBtn_clicked;
// 用户列表菜单
_playerName = root.Q<Label>("PlayerName");
_playerName = root.Q<ToolbarButton>("PlayerName");
_playerName.text = "Editor player";
// 视口模式菜单
@ -118,6 +118,9 @@ namespace YooAsset.Editor
var frameClear = root.Q<ToolbarButton>("FrameClear");
frameClear.clicked += OnFrameClear_clicked;
var recorderToggle = root.Q<ToggleRecord>("FrameRecord");
recorderToggle.RegisterValueChangedCallback(OnRecordToggleValueChange);
}
// 加载视图
@ -140,8 +143,9 @@ namespace YooAsset.Editor
EditorConnection.instance.Initialize();
EditorConnection.instance.RegisterConnection(OnHandleConnectionEvent);
EditorConnection.instance.RegisterDisconnection(OnHandleDisconnectionEvent);
EditorConnection.instance.Register(RemoteDebuggerDefine.kMsgSendPlayerToEditor, OnHandlePlayerMessage);
RemoteDebuggerInRuntime.EditorHandleDebugReportCallback = OnHandleDebugReport;
EditorConnection.instance.Register(RemoteDebuggerDefine.kMsgPlayerSendToEditor, OnHandlePlayerMessage);
RemoteEditorConnection.Instance.Initialize();
RemoteEditorConnection.Instance.Register(RemoteDebuggerDefine.kMsgPlayerSendToEditor, OnHandlePlayerMessage);
}
catch (Exception e)
{
@ -153,7 +157,8 @@ namespace YooAsset.Editor
// 远程调试
EditorConnection.instance.UnregisterConnection(OnHandleConnectionEvent);
EditorConnection.instance.UnregisterDisconnection(OnHandleDisconnectionEvent);
EditorConnection.instance.Unregister(RemoteDebuggerDefine.kMsgSendPlayerToEditor, OnHandlePlayerMessage);
EditorConnection.instance.Unregister(RemoteDebuggerDefine.kMsgPlayerSendToEditor, OnHandlePlayerMessage);
RemoteEditorConnection.Instance.Unregister(RemoteDebuggerDefine.kMsgPlayerSendToEditor);
_playerSessions.Clear();
}
@ -170,10 +175,7 @@ namespace YooAsset.Editor
private void OnHandlePlayerMessage(MessageEventArgs args)
{
var debugReport = DebugReport.Deserialize(args.data);
OnHandleDebugReport(args.playerId, debugReport);
}
private void OnHandleDebugReport(int playerId, DebugReport debugReport)
{
int playerId = args.playerId;
Debug.Log($"Handle player {playerId} debug report !");
_currentPlayerSession = GetOrCreatePlayerSession(playerId);
_currentPlayerSession.AddDebugReport(debugReport);
@ -221,6 +223,16 @@ namespace YooAsset.Editor
_operationListViewer.ClearView();
}
}
private void OnRecordToggleValueChange(ChangeEvent<bool> evt)
{
// 发送采集数据的命令
RemoteCommand command = new RemoteCommand();
command.CommandType = (int)ERemoteCommand.SampleAuto;
command.CommandParam = evt.newValue ? "open" : "close";
byte[] data = RemoteCommand.Serialize(command);
EditorConnection.instance.Send(RemoteDebuggerDefine.kMsgEditorSendToPlayer, data);
RemoteEditorConnection.Instance.Send(RemoteDebuggerDefine.kMsgEditorSendToPlayer, data);
}
private RemotePlayerSession GetOrCreatePlayerSession(int playerId)
{
@ -265,8 +277,8 @@ namespace YooAsset.Editor
command.CommandType = (int)ERemoteCommand.SampleOnce;
command.CommandParam = string.Empty;
byte[] data = RemoteCommand.Serialize(command);
EditorConnection.instance.Send(RemoteDebuggerDefine.kMsgSendEditorToPlayer, data);
RemoteDebuggerInRuntime.EditorRequestDebugReport();
EditorConnection.instance.Send(RemoteDebuggerDefine.kMsgEditorSendToPlayer, data);
RemoteEditorConnection.Instance.Send(RemoteDebuggerDefine.kMsgEditorSendToPlayer, data);
}
private void ExportBtn_clicked()
{

View File

@ -1,7 +1,7 @@
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../../UIElementsSchema/UIElements.xsd" editor-extension-mode="True">
<uie:Toolbar name="TopToolbar" style="display: flex;">
<ui:Label text="Player" display-tooltip-when-elided="true" name="PlayerName" style="width: 200px; -unity-text-align: lower-left; padding-left: 5px;" />
<uie:ToolbarMenu display-tooltip-when-elided="true" name="ViewModeMenu" text="ViewMode" style="width: 100px; flex-grow: 0;" />
<uie:ToolbarButton text="IP" parse-escape-sequences="true" display-tooltip-when-elided="true" name="PlayerName" style="width: 200px;" />
<uie:ToolbarMenu display-tooltip-when-elided="true" name="ViewModeMenu" text="ViewMode" style="width: 150px; flex-grow: 0;" />
<uie:ToolbarSearchField focusable="true" name="SearchField" style="flex-grow: 1;" />
<uie:ToolbarButton text="Refresh" display-tooltip-when-elided="true" name="SampleButton" style="width: 70px; background-color: rgb(15, 118, 31); -unity-text-align: middle-center; border-top-left-radius: 2px; border-bottom-left-radius: 2px; border-top-right-radius: 2px; border-bottom-right-radius: 2px; border-left-width: 1px; border-right-width: 1px;" />
<uie:ToolbarButton text="Export" display-tooltip-when-elided="true" name="ExportButton" style="width: 70px; background-color: rgb(15, 118, 31); -unity-text-align: middle-center; border-top-left-radius: 2px; border-bottom-left-radius: 2px; border-top-right-radius: 2px; border-bottom-right-radius: 2px; border-left-width: 1px; border-right-width: 1px;" />
@ -11,5 +11,6 @@
<uie:ToolbarButton text=" &lt;&lt; " display-tooltip-when-elided="true" name="FrameLast" />
<uie:ToolbarButton text=" &gt;&gt; " display-tooltip-when-elided="true" name="FrameNext" />
<uie:ToolbarButton text="Clear" display-tooltip-when-elided="true" name="FrameClear" />
<YooAsset.Editor.ToggleRecord name="FrameRecord" style="width: 20px;" />
</uie:Toolbar>
</ui:UXML>

View File

@ -27,7 +27,6 @@ namespace YooAsset.Editor
private TableView _providerTableView;
private TableView _dependTableView;
private DebugReport _debugReport;
private List<ITableData> _sourceDatas;
@ -53,13 +52,12 @@ namespace YooAsset.Editor
_dependTableView = _root.Q<TableView>("BottomTableView");
CreateDependTableViewColumns();
#if UNITY_2020_3_OR_NEWER
// 面板分屏
var topGroup = _root.Q<VisualElement>("TopGroup");
var bottomGroup = _root.Q<VisualElement>("BottomGroup");
topGroup.style.minHeight = 100;
bottomGroup.style.minHeight = 100f;
PanelSplitView.SplitVerticalPanel(_root, topGroup, bottomGroup);
#endif
UIElementsTools.SplitVerticalPanel(_root, topGroup, bottomGroup);
}
private void CreateAssetTableViewColumns()
{
@ -90,6 +88,7 @@ namespace YooAsset.Editor
columnStyle.Stretchable = true;
columnStyle.Searchable = true;
columnStyle.Sortable = true;
columnStyle.Counter = true;
var column = new TableColumn("AssetPath", "Asset Path", columnStyle);
column.MakeCell = () =>
{
@ -226,6 +225,7 @@ namespace YooAsset.Editor
columnStyle.Stretchable = true;
columnStyle.Searchable = true;
columnStyle.Sortable = true;
columnStyle.Counter = true;
var column = new TableColumn("DependBundles", "Depend Bundles", columnStyle);
column.MakeCell = () =>
{
@ -297,8 +297,6 @@ namespace YooAsset.Editor
/// </summary>
public void FillViewData(DebugReport debugReport)
{
_debugReport = debugReport;
// 清空旧数据
_providerTableView.ClearAll(false, true);
_dependTableView.ClearAll(false, true);
@ -333,7 +331,6 @@ namespace YooAsset.Editor
/// </summary>
public void ClearView()
{
_debugReport = null;
_providerTableView.ClearAll(false, true);
_dependTableView.ClearAll(false, true);
RebuildView(null);

View File

@ -32,7 +32,6 @@ namespace YooAsset.Editor
private TableView _usingTableView;
private TableView _referenceTableView;
private DebugReport _debugReport;
private List<ITableData> _sourceDatas;
/// <summary>
@ -61,14 +60,13 @@ namespace YooAsset.Editor
_referenceTableView = _root.Q<TableView>("ReferenceTableView");
CreateReferenceTableViewColumns();
#if UNITY_2020_3_OR_NEWER
// 面板分屏
var topGroup = _root.Q<VisualElement>("TopGroup");
var bottomGroup = _root.Q<VisualElement>("BottomGroup");
topGroup.style.minHeight = 100;
bottomGroup.style.minHeight = 100f;
PanelSplitView.SplitVerticalPanel(_root, topGroup, bottomGroup);
PanelSplitView.SplitVerticalPanel(bottomGroup, _usingTableView, _referenceTableView);
#endif
UIElementsTools.SplitVerticalPanel(_root, topGroup, bottomGroup);
UIElementsTools.SplitVerticalPanel(bottomGroup, _usingTableView, _referenceTableView);
}
private void CreateBundleTableViewColumns()
{
@ -99,6 +97,7 @@ namespace YooAsset.Editor
columnStyle.Stretchable = true;
columnStyle.Searchable = true;
columnStyle.Sortable = true;
columnStyle.Counter = true;
var column = new TableColumn("BundleName", "Bundle Name", columnStyle);
column.MakeCell = () =>
{
@ -172,6 +171,7 @@ namespace YooAsset.Editor
columnStyle.Stretchable = true;
columnStyle.Searchable = true;
columnStyle.Sortable = true;
columnStyle.Counter = true;
var column = new TableColumn("UsingAssets", "Using Assets", columnStyle);
column.MakeCell = () =>
{
@ -287,6 +287,7 @@ namespace YooAsset.Editor
columnStyle.Stretchable = true;
columnStyle.Searchable = true;
columnStyle.Sortable = true;
columnStyle.Counter = true;
var column = new TableColumn("ReferenceBundle", "Reference Bundle", columnStyle);
column.MakeCell = () =>
{
@ -358,8 +359,6 @@ namespace YooAsset.Editor
/// </summary>
public void FillViewData(DebugReport debugReport)
{
_debugReport = debugReport;
// 清空旧数据
_bundleTableView.ClearAll(false, true);
_usingTableView.ClearAll(false, true);
@ -392,7 +391,6 @@ namespace YooAsset.Editor
/// </summary>
public void ClearView()
{
_debugReport = null;
_bundleTableView.ClearAll(false, true);
_bundleTableView.RebuildView();
_usingTableView.ClearAll(false, true);

View File

@ -21,8 +21,10 @@ namespace YooAsset.Editor
private TemplateContainer _root;
private TableView _operationTableView;
private Toolbar _bottomToolbar;
private TreeView _childTreeView;
private DebugReport _debugReport;
private int _treeItemID = 0;
private List<ITableData> _sourceDatas;
@ -41,18 +43,32 @@ namespace YooAsset.Editor
// 任务列表
_operationTableView = _root.Q<TableView>("TopTableView");
_operationTableView.SelectionChangedEvent = OnOperationTableViewSelectionChanged;
CreateOperationTableViewColumns();
// 底部标题栏
_bottomToolbar = _root.Q<Toolbar>("BottomToolbar");
CreateBottomToolbarHeaders();
// 子列表
_childTreeView = _root.Q<TreeView>("BottomTreeView");
_childTreeView.makeItem = MakeTreeViewItem;
_childTreeView.bindItem = BindTreeViewItem;
// 面板分屏
var topGroup = _root.Q<VisualElement>("TopGroup");
var bottomGroup = _root.Q<VisualElement>("BottomGroup");
topGroup.style.minHeight = 100;
bottomGroup.style.minHeight = 100f;
UIElementsTools.SplitVerticalPanel(_root, topGroup, bottomGroup);
}
private void CreateOperationTableViewColumns()
{
// PackageName
{
var columnStyle = new ColumnStyle(200);
columnStyle.Stretchable = true;
columnStyle.Searchable = true;
columnStyle.Sortable = true;
columnStyle.Counter = true;
var column = new TableColumn("PackageName", "Package Name", columnStyle);
column.MakeCell = () =>
{
@ -159,7 +175,7 @@ namespace YooAsset.Editor
columnStyle.Stretchable = false;
columnStyle.Searchable = false;
columnStyle.Sortable = true;
var column = new TableColumn("LoadingTime", "Loading Time", columnStyle);
var column = new TableColumn("ProcessTime", "Process Time", columnStyle);
column.MakeCell = () =>
{
var label = new Label();
@ -202,6 +218,82 @@ namespace YooAsset.Editor
};
_operationTableView.AddColumn(column);
}
// Desc
{
var columnStyle = new ColumnStyle(500, 500, 1000);
columnStyle.Stretchable = true;
columnStyle.Searchable = true;
var column = new TableColumn("Desc", "Desc", columnStyle);
column.MakeCell = () =>
{
var label = new Label();
label.style.unityTextAlign = TextAnchor.MiddleLeft;
return label;
};
column.BindCell = (VisualElement element, ITableData data, ITableCell cell) =>
{
var infoLabel = element as Label;
infoLabel.text = (string)cell.GetDisplayObject();
};
_operationTableView.AddColumn(column);
}
}
private void CreateBottomToolbarHeaders()
{
// OperationName
{
ToolbarButton button = new ToolbarButton();
button.text = "OperationName";
button.style.flexGrow = 0;
button.style.width = 315;
_bottomToolbar.Add(button);
}
// Progress
{
ToolbarButton button = new ToolbarButton();
button.text = "Progress";
button.style.flexGrow = 0;
button.style.width = 100;
_bottomToolbar.Add(button);
}
// BeginTime
{
ToolbarButton button = new ToolbarButton();
button.text = "BeginTime";
button.style.flexGrow = 0;
button.style.width = 100;
_bottomToolbar.Add(button);
}
// ProcessTime
{
ToolbarButton button = new ToolbarButton();
button.text = "ProcessTime";
button.style.flexGrow = 0;
button.style.width = 100;
_bottomToolbar.Add(button);
}
// Status
{
ToolbarButton button = new ToolbarButton();
button.text = "Status";
button.style.flexGrow = 0;
button.style.width = 100;
_bottomToolbar.Add(button);
}
// Desc
{
ToolbarButton button = new ToolbarButton();
button.text = "Desc";
button.style.flexGrow = 0;
button.style.width = 500;
_bottomToolbar.Add(button);
}
}
/// <summary>
@ -209,10 +301,10 @@ namespace YooAsset.Editor
/// </summary>
public void FillViewData(DebugReport debugReport)
{
_debugReport = debugReport;
// 清空旧数据
_operationTableView.ClearAll(false, true);
_childTreeView.SetRootItems(new List<TreeViewItemData<DebugOperationInfo>>());
_childTreeView.Rebuild();
// 填充数据源
_sourceDatas = new List<ITableData>(1000);
@ -230,6 +322,7 @@ namespace YooAsset.Editor
rowData.AddStringValueCell("BeginTime", operationInfo.BeginTime);
rowData.AddLongValueCell("LoadingTime", operationInfo.ProcessTime);
rowData.AddStringValueCell("Status", operationInfo.Status.ToString());
rowData.AddStringValueCell("Desc", operationInfo.OperationDesc);
_sourceDatas.Add(rowData);
}
}
@ -244,8 +337,9 @@ namespace YooAsset.Editor
/// </summary>
public void ClearView()
{
_debugReport = null;
_operationTableView.ClearAll(false, true);
_childTreeView.SetRootItems(new List<TreeViewItemData<DebugOperationInfo>>());
_childTreeView.Rebuild();
RebuildView(null);
}
@ -276,6 +370,145 @@ namespace YooAsset.Editor
{
_root.RemoveFromHierarchy();
}
#region 树状列表
private void OnOperationTableViewSelectionChanged(ITableData data)
{
var operationTableData = data as OperationTableData;
DebugPackageData packageData = operationTableData.PackageData;
DebugOperationInfo operationInfo = operationTableData.OperationInfo;
_treeItemID = 0;
var rootItems = CreateTreeData(operationInfo);
_childTreeView.SetRootItems(rootItems);
_childTreeView.Rebuild();
}
private VisualElement MakeTreeViewItem()
{
VisualElement treeViewElement = new VisualElement();
treeViewElement.style.flexDirection = FlexDirection.Row;
// OperationName
{
Label label = new Label();
label.name = "OperationName";
label.style.flexGrow = 0f;
label.style.width = 300;
label.style.unityTextAlign = TextAnchor.MiddleLeft;
treeViewElement.Add(label);
}
// Progress
{
var label = new Label();
label.name = "Progress";
label.style.flexGrow = 0f;
label.style.width = 100;
label.style.unityTextAlign = TextAnchor.MiddleLeft;
treeViewElement.Add(label);
}
// BeginTime
{
var label = new Label();
label.name = "BeginTime";
label.style.flexGrow = 0f;
label.style.width = 100;
label.style.unityTextAlign = TextAnchor.MiddleLeft;
treeViewElement.Add(label);
}
// ProcessTime
{
var label = new Label();
label.name = "ProcessTime";
label.style.flexGrow = 0f;
label.style.width = 100;
label.style.unityTextAlign = TextAnchor.MiddleLeft;
treeViewElement.Add(label);
}
// Status
{
var label = new Label();
label.name = "Status";
label.style.flexGrow = 0f;
label.style.width = 100;
label.style.unityTextAlign = TextAnchor.MiddleLeft;
treeViewElement.Add(label);
}
// Desc
{
Label label = new Label();
label.name = "Desc";
label.style.flexGrow = 1f;
label.style.width = 500;
label.style.unityTextAlign = TextAnchor.MiddleLeft;
treeViewElement.Add(label);
}
return treeViewElement;
}
private void BindTreeViewItem(VisualElement element, int index)
{
var operationInfo = _childTreeView.GetItemDataForIndex<DebugOperationInfo>(index);
// OperationName
{
var label = element.Q<Label>("OperationName");
label.text = operationInfo.OperationName;
}
// Progress
{
var label = element.Q<Label>("Progress");
label.text = operationInfo.Progress.ToString();
}
// BeginTime
{
var label = element.Q<Label>("BeginTime");
label.text = operationInfo.BeginTime;
}
// ProcessTime
{
var label = element.Q<Label>("ProcessTime");
label.text = operationInfo.ProcessTime.ToString();
}
// Status
{
StyleColor textColor;
if (operationInfo.Status == EOperationStatus.Failed.ToString())
textColor = new StyleColor(Color.yellow);
else
textColor = new StyleColor(Color.white);
var label = element.Q<Label>("Status");
label.text = operationInfo.Status;
label.style.color = textColor;
}
// Desc
{
var label = element.Q<Label>("Desc");
label.text = operationInfo.OperationDesc;
}
}
private List<TreeViewItemData<DebugOperationInfo>> CreateTreeData(DebugOperationInfo parentOperation)
{
var rootItemList = new List<TreeViewItemData<DebugOperationInfo>>();
foreach (var childOperation in parentOperation.Childs)
{
var childItemList = CreateTreeData(childOperation);
var treeItem = new TreeViewItemData<DebugOperationInfo>(_treeItemID++, childOperation, childItemList);
rootItemList.Add(treeItem);
}
return rootItemList;
}
#endregion
}
}
#endif

View File

@ -1,5 +1,9 @@
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" editor-extension-mode="False">
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" editor-extension-mode="True">
<ui:VisualElement name="TopGroup" style="flex-grow: 1; border-left-width: 1px; border-right-width: 1px; border-top-width: 1px; border-bottom-width: 1px; border-left-color: rgb(0, 0, 0); border-right-color: rgb(0, 0, 0); border-top-color: rgb(0, 0, 0); border-bottom-color: rgb(0, 0, 0); margin-left: 0; margin-right: 0; margin-top: 2px; margin-bottom: 1px; display: flex;">
<YooAsset.Editor.TableView name="TopTableView" />
</ui:VisualElement>
<ui:VisualElement name="BottomGroup" style="flex-grow: 1;">
<uie:Toolbar name="BottomToolbar" />
<ui:TreeView name="BottomTreeView" />
</ui:VisualElement>
</ui:UXML>

View File

@ -56,13 +56,12 @@ namespace YooAsset.Editor
_dependTableView.ClickTableDataEvent = OnClickBundleTableView;
CreateDependTableViewColumns();
#if UNITY_2020_3_OR_NEWER
// 面板分屏
var topGroup = _root.Q<VisualElement>("TopGroup");
var bottomGroup = _root.Q<VisualElement>("BottomGroup");
topGroup.style.minHeight = 100;
bottomGroup.style.minHeight = 100f;
PanelSplitView.SplitVerticalPanel(_root, topGroup, bottomGroup);
#endif
UIElementsTools.SplitVerticalPanel(_root, topGroup, bottomGroup);
}
private void CreateAssetTableViewColumns()
{

View File

@ -61,7 +61,7 @@ namespace YooAsset.Editor
var bottomGroup = _root.Q<VisualElement>("BottomGroup");
topGroup.style.minHeight = 100;
bottomGroup.style.minHeight = 100f;
PanelSplitView.SplitVerticalPanel(_root, topGroup, bottomGroup);
UIElementsTools.SplitVerticalPanel(_root, topGroup, bottomGroup);
#endif
}
private void CreateBundleTableViewColumns()

View File

@ -1,41 +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 DisplayToggle : Toggle
{
private readonly VisualElement _checkbox;
public DisplayToggle()
{
_checkbox = this.Q<VisualElement>("unity-checkmark");
RefreshIcon();
}
/// <summary>
/// 刷新图标
/// </summary>
public void RefreshIcon()
{
if (this.value)
{
var icon = EditorGUIUtility.IconContent("animationvisibilitytoggleoff@2x").image as Texture2D;
_checkbox.style.backgroundImage = icon;
}
else
{
var icon = EditorGUIUtility.IconContent("animationvisibilitytoggleon@2x").image as Texture2D;
_checkbox.style.backgroundImage = icon;
}
}
}
}
#endif

View File

@ -1,36 +0,0 @@
#if UNITY_2020_3_OR_NEWER
using System;
using UnityEditor;
using UnityEngine;
using UnityEditor.UIElements;
using UnityEngine.UIElements;
namespace YooAsset.Editor
{
/// <summary>
/// 分屏控件
/// </summary>
public class PanelSplitView : TwoPaneSplitView
{
public new class UxmlFactory : UxmlFactory<PanelSplitView, UxmlTraits>
{
}
/// <summary>
/// 竖版分屏
/// </summary>
public static void SplitVerticalPanel(VisualElement root, VisualElement panelA, VisualElement panelB)
{
root.Remove(panelA);
root.Remove(panelB);
var spliteView = new PanelSplitView();
spliteView.fixedPaneInitialDimension = 300;
spliteView.orientation = TwoPaneSplitViewOrientation.Vertical;
spliteView.contentContainer.Add(panelA);
spliteView.contentContainer.Add(panelB);
root.Add(spliteView);
}
}
}
#endif

View File

@ -0,0 +1,52 @@
#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 ToggleDisplay : Toggle
{
public new class UxmlFactory : UxmlFactory<ToggleDisplay, UxmlTraits>
{
}
private readonly VisualElement _checkbox;
public ToggleDisplay()
{
_checkbox = this.Q<VisualElement>("unity-checkmark");
RefreshIcon();
}
public override void SetValueWithoutNotify(bool newValue)
{
base.SetValueWithoutNotify(newValue);
RefreshIcon();
}
protected override void ToggleValue()
{
base.ToggleValue();
RefreshIcon();
}
private void RefreshIcon()
{
if (this.value)
{
var icon = EditorGUIUtility.IconContent(UIElementsIcon.VisibilityToggleOff).image as Texture2D;
_checkbox.style.backgroundImage = icon;
}
else
{
var icon = EditorGUIUtility.IconContent(UIElementsIcon.VisibilityToggleOn).image as Texture2D;
_checkbox.style.backgroundImage = icon;
}
}
}
}
#endif

View File

@ -0,0 +1,52 @@
#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 ToggleRecord : Toggle
{
public new class UxmlFactory : UxmlFactory<ToggleRecord, UxmlTraits>
{
}
private readonly VisualElement _checkbox;
public ToggleRecord()
{
_checkbox = this.Q<VisualElement>("unity-checkmark");
RefreshIcon();
}
public override void SetValueWithoutNotify(bool newValue)
{
base.SetValueWithoutNotify(newValue);
RefreshIcon();
}
protected override void ToggleValue()
{
base.ToggleValue();
RefreshIcon();
}
private void RefreshIcon()
{
if (this.value)
{
var icon = EditorGUIUtility.IconContent(UIElementsIcon.RecordOn).image as Texture2D;
_checkbox.style.backgroundImage = icon;
}
else
{
var icon = EditorGUIUtility.IconContent(UIElementsIcon.RecordOff).image as Texture2D;
_checkbox.style.backgroundImage = icon;
}
}
}
}
#endif

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: 0c3f4136cf7142346ae33e8a82cbdb27
guid: 4eace285493a0844f8a8b8f4a4ea02d8
MonoImporter:
externalObjects: {}
serializedVersion: 2

View File

@ -0,0 +1,17 @@
#if UNITY_2019_4_OR_NEWER
namespace YooAsset.Editor
{
/// <summary>
/// 引擎图标名称
/// </summary>
public class UIElementsIcon
{
public const string RecordOn = "d_Record On@2x";
public const string RecordOff = "d_Record Off@2x";
public const string VisibilityToggleOff = "animationvisibilitytoggleoff@2x";
public const string VisibilityToggleOn = "animationvisibilitytoggleon@2x";
}
}
#endif

View File

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

View File

@ -32,6 +32,34 @@ namespace YooAsset.Editor
label.style.minWidth = minWidth;
}
}
/// <summary>
/// 设置按钮图标
/// </summary>
public static void SetToolbarButtonIcon(ToolbarButton element, string iconName)
{
var image = EditorGUIUtility.IconContent(iconName).image as Texture2D;
element.style.backgroundImage = image;
element.text = string.Empty;
}
/// <summary>
/// 竖版分屏
/// </summary>
public static void SplitVerticalPanel(VisualElement root, VisualElement panelA, VisualElement panelB)
{
#if UNITY_2020_3_OR_NEWER
root.Remove(panelA);
root.Remove(panelB);
var spliteView = new TwoPaneSplitView();
spliteView.fixedPaneInitialDimension = 300;
spliteView.orientation = TwoPaneSplitViewOrientation.Vertical;
spliteView.contentContainer.Add(panelA);
spliteView.contentContainer.Add(panelB);
root.Add(spliteView);
#endif
}
}
}
#endif

View File

@ -12,6 +12,11 @@ namespace YooAsset
/// </summary>
public string OperationName;
/// <summary>
/// 任务说明
/// </summary>
public string OperationDesc;
/// <summary>
/// 优先级
/// </summary>
@ -37,6 +42,12 @@ namespace YooAsset
/// </summary>
public string Status;
/// <summary>
/// 子任务列表
/// TODO : Serialization depth limit 10 exceeded
/// </summary>
public List<DebugOperationInfo> Childs;
public int CompareTo(DebugOperationInfo other)
{
return Compare(this, other);

View File

@ -10,6 +10,11 @@ namespace YooAsset
/// 采样一次
/// </summary>
SampleOnce = 0,
/// <summary>
/// 自动采集
/// </summary>
SampleAuto = 1,
}
[Serializable]

View File

@ -5,7 +5,7 @@ namespace YooAsset
{
internal class RemoteDebuggerDefine
{
public static readonly Guid kMsgSendPlayerToEditor = new Guid("e34a5702dd353724aa315fb8011f08c3");
public static readonly Guid kMsgSendEditorToPlayer = new Guid("4d1926c9df5b052469a1c63448b7609a");
public static readonly Guid kMsgPlayerSendToEditor = new Guid("e34a5702dd353724aa315fb8011f08c3");
public static readonly Guid kMsgEditorSendToPlayer = new Guid("4d1926c9df5b052469a1c63448b7609a");
}
}

View File

@ -7,47 +7,66 @@ namespace YooAsset
{
internal class RemoteDebuggerInRuntime : MonoBehaviour
{
#if UNITY_EDITOR
/// <summary>
/// 编辑器下获取报告的回调
/// </summary>
public static Action<int, DebugReport> EditorHandleDebugReportCallback;
private static bool _sampleOnce = false;
private static bool _autoSample = false;
/// <summary>
/// 编辑器下请求报告数据
/// </summary>
public static void EditorRequestDebugReport()
private void Awake()
{
if (UnityEditor.EditorApplication.isPlaying)
{
var report = YooAssets.GetDebugReport();
EditorHandleDebugReportCallback?.Invoke(0, report);
}
#if UNITY_EDITOR
RemotePlayerConnection.Instance.Initialize();
#endif
}
#else
private void OnEnable()
{
PlayerConnection.instance.Register(RemoteDebuggerDefine.kMsgSendEditorToPlayer, OnHandleEditorMessage);
#if UNITY_EDITOR
RemotePlayerConnection.Instance.Register(RemoteDebuggerDefine.kMsgEditorSendToPlayer, OnHandleEditorMessage);
#else
PlayerConnection.instance.Register(RemoteDebuggerDefine.kMsgEditorSendToPlayer, OnHandleEditorMessage);
#endif
}
private void OnDisable()
{
PlayerConnection.instance.Unregister(RemoteDebuggerDefine.kMsgSendEditorToPlayer, OnHandleEditorMessage);
#if UNITY_EDITOR
RemotePlayerConnection.Instance.Unregister(RemoteDebuggerDefine.kMsgEditorSendToPlayer);
#else
PlayerConnection.instance.Unregister(RemoteDebuggerDefine.kMsgEditorSendToPlayer, OnHandleEditorMessage);
#endif
}
private void OnHandleEditorMessage(MessageEventArgs args)
private void LateUpdate()
{
if (_autoSample || _sampleOnce)
{
_sampleOnce = false;
var debugReport = YooAssets.GetDebugReport();
var data = DebugReport.Serialize(debugReport);
#if UNITY_EDITOR
RemotePlayerConnection.Instance.Send(RemoteDebuggerDefine.kMsgPlayerSendToEditor, data);
#else
PlayerConnection.instance.Send(RemoteDebuggerDefine.kMsgPlayerSendToEditor, data);
#endif
}
}
private static void OnHandleEditorMessage(MessageEventArgs args)
{
var command = RemoteCommand.Deserialize(args.data);
YooLogger.Log($"On handle remote command : {command.CommandType} Param : {command.CommandParam}");
if (command.CommandType == (int)ERemoteCommand.SampleOnce)
{
var debugReport = YooAssets.GetDebugReport();
var data = DebugReport.Serialize(debugReport);
PlayerConnection.instance.Send(RemoteDebuggerDefine.kMsgSendPlayerToEditor, data);
_sampleOnce = true;
}
else if (command.CommandType == (int)ERemoteCommand.SampleAuto)
{
if (command.CommandParam == "open")
_autoSample = true;
else
_autoSample = false;
}
else
{
throw new NotImplementedException(command.CommandType.ToString());
}
}
#endif
}
}

View File

@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
using UnityEngine.Events;
using UnityEngine.Networking.PlayerConnection;
using UnityEngine;
namespace YooAsset
{
internal class RemoteEditorConnection
{
private static RemoteEditorConnection _instance;
public static RemoteEditorConnection Instance
{
get
{
if (_instance == null)
_instance = new RemoteEditorConnection();
return _instance;
}
}
private readonly Dictionary<Guid, UnityAction<MessageEventArgs>> _messageCallbacks = new Dictionary<Guid, UnityAction<MessageEventArgs>>();
public void Initialize()
{
_messageCallbacks.Clear();
}
public void Register(Guid messageID, UnityAction<MessageEventArgs> callback)
{
if (messageID == Guid.Empty)
throw new ArgumentException("messageID is empty !");
if (_messageCallbacks.ContainsKey(messageID) == false)
_messageCallbacks.Add(messageID, callback);
}
public void Unregister(Guid messageID)
{
if (_messageCallbacks.ContainsKey(messageID))
_messageCallbacks.Remove(messageID);
}
public void Send(Guid messageID, byte[] data)
{
if (messageID == Guid.Empty)
throw new ArgumentException("messageID is empty !");
// 接收对方的消息
RemotePlayerConnection.Instance.HandleEditorMessage(messageID, data);
}
internal void HandlePlayerMessage(Guid messageID, byte[] data)
{
if (_messageCallbacks.TryGetValue(messageID, out UnityAction<MessageEventArgs> value))
{
var args = new MessageEventArgs();
args.playerId = 0;
args.data = data;
value?.Invoke(args);
}
}
}
}

View File

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

View File

@ -0,0 +1,64 @@
using System;
using System.Collections.Generic;
using UnityEngine.Events;
using UnityEngine.Networking.PlayerConnection;
using UnityEngine;
namespace YooAsset
{
internal class RemotePlayerConnection
{
private static RemotePlayerConnection _instance;
public static RemotePlayerConnection Instance
{
get
{
if (_instance == null)
_instance = new RemotePlayerConnection();
return _instance;
}
}
private readonly Dictionary<Guid, UnityAction<MessageEventArgs>> _messageCallbacks = new Dictionary<Guid, UnityAction<MessageEventArgs>>();
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 !");
if (_messageCallbacks.ContainsKey(messageID) == false)
_messageCallbacks.Add(messageID, callback);
}
public void Unregister(Guid messageID)
{
Debug.LogWarning("X=Unregister");
if (_messageCallbacks.ContainsKey(messageID))
_messageCallbacks.Remove(messageID);
}
public void Send(Guid messageID, byte[] data)
{
if (messageID == Guid.Empty)
throw new ArgumentException("messageID is empty !");
// 接收对方的消息
RemoteEditorConnection.Instance.HandlePlayerMessage(messageID, data);
}
internal void HandleEditorMessage(Guid messageID, byte[] data)
{
if (_messageCallbacks.TryGetValue(messageID, out UnityAction<MessageEventArgs> value))
{
var args = new MessageEventArgs();
args.playerId = 0;
args.data = data;
value?.Invoke(args);
}
}
}
}

View File

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

View File

@ -110,5 +110,9 @@ namespace YooAsset
}
}
}
internal override string InternalGetDesc()
{
return $"PackageVersion : {_packageVersion} PackageHash : {_packageHash}";
}
}
}

View File

@ -100,5 +100,9 @@ namespace YooAsset
}
}
}
internal override string InternalGetDesc()
{
return $"PackageVersion : {_packageVersion} PackageHash : {_packageHash}";
}
}
}

View File

@ -100,5 +100,9 @@ namespace YooAsset
}
}
}
internal override string InternalGetDesc()
{
return $"PackageVersion : {_packageVersion} PackageHash : {_packageHash}";
}
}
}

View File

@ -113,6 +113,10 @@ namespace YooAsset
}
}
}
internal override string InternalGetDesc()
{
return $"PackageVersion : {_packageVersion} PackageHash : {_packageHash}";
}
private string GetWebRequestURL(string fileName)
{

View File

@ -110,5 +110,9 @@ namespace YooAsset
}
}
}
internal override string InternalGetDesc()
{
return $"PackageVersion : {_packageVersion} PackageHash : {_packageHash}";
}
}
}

View File

@ -8,11 +8,15 @@ namespace YooAsset
{
public abstract class AsyncOperationBase : IEnumerator, IComparable<AsyncOperationBase>
{
private readonly List<AsyncOperationBase> _childs = new List<AsyncOperationBase>(10);
private Action<AsyncOperationBase> _callback;
private string _packageName = null;
private int _whileFrame = 1000;
/// <summary>
/// 所有子任务
/// </summary>
internal readonly List<AsyncOperationBase> Childs = new List<AsyncOperationBase>(10);
/// <summary>
/// 等待异步执行完成
/// </summary>
@ -109,6 +113,10 @@ namespace YooAsset
{
throw new System.NotImplementedException(this.GetType().Name);
}
internal virtual string InternalGetDesc()
{
return string.Empty;
}
/// <summary>
/// 设置包裹名称
@ -124,11 +132,19 @@ namespace YooAsset
internal void AddChildOperation(AsyncOperationBase child)
{
#if UNITY_EDITOR
if (_childs.Contains(child))
if (Childs.Contains(child))
throw new Exception($"The child node {child.GetType().Name} already exists !");
#endif
_childs.Add(child);
Childs.Add(child);
}
/// <summary>
/// 获取异步操作说明
/// </summary>
internal string GetOperationDesc()
{
return InternalGetDesc();
}
/// <summary>
@ -185,7 +201,7 @@ namespace YooAsset
/// </summary>
internal void AbortOperation()
{
foreach (var child in _childs)
foreach (var child in Childs)
{
child.AbortOperation();
}

View File

@ -43,6 +43,15 @@ namespace YooAsset
/// </summary>
public static void Update()
{
// 移除已经完成的异步操作
// 注意:移除上一帧完成的异步操作,方便调试器接收到完整的信息!
for (int i = _operations.Count - 1; i >= 0; i--)
{
var operation = _operations[i];
if (operation.IsFinish)
_operations.RemoveAt(i);
}
// 添加新增的异步操作
if (_newList.Count > 0)
{
@ -77,14 +86,6 @@ namespace YooAsset
operation.UpdateOperation();
}
// 移除已经完成的异步操作
for (int i = _operations.Count - 1; i >= 0; i--)
{
var operation = _operations[i];
if (operation.IsFinish)
_operations.RemoveAt(i);
}
}
/// <summary>
@ -141,18 +142,30 @@ namespace YooAsset
{
if (operation.PackageName == packageName)
{
var operationInfo = new DebugOperationInfo();
operationInfo.OperationName = operation.GetType().FullName;
operationInfo.Priority = operation.Priority;
operationInfo.Progress = operation.Progress;
operationInfo.BeginTime = operation.BeginTime;
operationInfo.ProcessTime = operation.ProcessTime;
operationInfo.Status = operation.Status.ToString();
var operationInfo = GetDebugOperationInfo(operation);
result.Add(operationInfo);
}
}
return result;
}
internal static DebugOperationInfo GetDebugOperationInfo(AsyncOperationBase operation)
{
var operationInfo = new DebugOperationInfo();
operationInfo.OperationName = operation.GetType().Name;
operationInfo.OperationDesc = operation.GetOperationDesc();
operationInfo.Priority = operation.Priority;
operationInfo.Progress = operation.Progress;
operationInfo.BeginTime = operation.BeginTime;
operationInfo.ProcessTime = operation.ProcessTime;
operationInfo.Status = operation.Status.ToString();
operationInfo.Childs = new List<DebugOperationInfo>(operation.Childs.Count);
foreach (var child in operation.Childs)
{
var childInfo = GetDebugOperationInfo(child);
operationInfo.Childs.Add(childInfo);
}
return operationInfo;
}
#endregion
}
}

View File

@ -151,6 +151,11 @@ namespace YooAsset
}
}
}
internal override string InternalGetDesc()
{
var assetInfo = _handle.GetAssetInfo();
return $"AssetPath : {assetInfo.AssetPath}";
}
/// <summary>
/// 取消实例化对象操作

View File

@ -116,6 +116,10 @@ namespace YooAsset
}
}
}
internal override string InternalGetDesc()
{
return $"BundleName : {LoadBundleInfo.Bundle.BundleName}";
}
/// <summary>
/// 引用(引用计数递加)

View File

@ -110,5 +110,9 @@ namespace YooAsset
Status = EOperationStatus.Succeed;
}
}
internal override string InternalGetDesc()
{
return $"SceneName : {_provider.SceneName}";
}
}
}

View File

@ -53,6 +53,10 @@ namespace YooAsset
}
}
}
internal override string InternalGetDesc()
{
return $"LoopCount : {_loopCount}";
}
/// <summary>
/// 说明:资源包之间会有深层的依赖链表,需要多次迭代才可以在单帧内卸载!

View File

@ -173,6 +173,10 @@ namespace YooAsset
}
}
}
internal override string InternalGetDesc()
{
return $"AssetPath : {MainAssetInfo.AssetPath}";
}
protected abstract void ProcessBundleResult();
/// <summary>

View File

@ -100,5 +100,9 @@ namespace YooAsset
}
}
}
internal override string InternalGetDesc()
{
return $"ClearMode : {_clearMode}";
}
}
}

View File

@ -98,5 +98,9 @@ namespace YooAsset
Status = EOperationStatus.Succeed;
}
}
internal override string InternalGetDesc()
{
return $"PackageVersion : {_resourcePackage.GetPackageVersion()}";
}
}
}

View File

@ -121,5 +121,9 @@ namespace YooAsset
}
}
}
internal override string InternalGetDesc()
{
return $"PlayMode : {_impl.PlayMode}";
}
}
}

View File

@ -11,7 +11,7 @@ namespace YooAsset
LoadPackageManifest,
Done,
}
private readonly PlayModeImpl _impl;
private readonly string _packageVersion;
private readonly int _timeout;
@ -89,5 +89,9 @@ namespace YooAsset
}
}
}
internal override string InternalGetDesc()
{
return $"PackageVersion : {_packageVersion}";
}
}
}

View File

@ -7,12 +7,13 @@ namespace YooAsset
internal class PlayModeImpl : IPlayMode, IBundleQuery
{
public readonly string PackageName;
public readonly EPlayMode PlayMode;
public readonly List<IFileSystem> FileSystems = new List<IFileSystem>(10);
public PlayModeImpl(string packageName)
public PlayModeImpl(string packageName, EPlayMode playMode)
{
PackageName = packageName;
PlayMode = playMode;
}
/// <summary>

View File

@ -97,7 +97,7 @@ namespace YooAsset
// 创建资源管理器
_resourceManager = new ResourceManager(PackageName);
var playModeImpl = new PlayModeImpl(PackageName);
var playModeImpl = new PlayModeImpl(PackageName, _playMode);
_bundleQuery = playModeImpl;
_playModeImpl = playModeImpl;
_resourceManager.Initialize(_bundleQuery);