mirror of https://github.com/tuyoogame/YooAsset
parent
fbb9bff3c7
commit
32ce99949b
|
@ -45,12 +45,15 @@ namespace YooAsset.Editor
|
|||
|
||||
private Label _playerName;
|
||||
private ToolbarMenu _viewModeMenu;
|
||||
private SliderInt _frameSlider;
|
||||
private DebuggerAssetListViewer _assetListViewer;
|
||||
private DebuggerBundleListViewer _bundleListViewer;
|
||||
|
||||
private EViewMode _viewMode;
|
||||
private DebugReport _debugReport;
|
||||
private string _searchKeyWord;
|
||||
private DebugReport _currentReport;
|
||||
private RemotePlayerSession _currentPlayerSession;
|
||||
private int _rangeIndex = 0;
|
||||
|
||||
|
||||
public void CreateGUI()
|
||||
|
@ -76,14 +79,36 @@ namespace YooAsset.Editor
|
|||
|
||||
// 视口模式菜单
|
||||
_viewModeMenu = root.Q<ToolbarMenu>("ViewModeMenu");
|
||||
_viewModeMenu.menu.AppendAction(EViewMode.AssetView.ToString(), ViewModeMenuAction, ViewModeMenuFun, EViewMode.AssetView);
|
||||
_viewModeMenu.menu.AppendAction(EViewMode.BundleView.ToString(), ViewModeMenuAction, ViewModeMenuFun, EViewMode.BundleView);
|
||||
_viewModeMenu.menu.AppendAction(EViewMode.AssetView.ToString(), OnViewModeMenuChange, OnViewModeMenuStatusUpdate, EViewMode.AssetView);
|
||||
_viewModeMenu.menu.AppendAction(EViewMode.BundleView.ToString(), OnViewModeMenuChange, OnViewModeMenuStatusUpdate, EViewMode.BundleView);
|
||||
_viewModeMenu.text = EViewMode.AssetView.ToString();
|
||||
|
||||
// 搜索栏
|
||||
var searchField = root.Q<ToolbarSearchField>("SearchField");
|
||||
searchField.RegisterValueChangedCallback(OnSearchKeyWordChange);
|
||||
|
||||
// 帧数相关
|
||||
{
|
||||
_frameSlider = root.Q<SliderInt>("FrameSlider");
|
||||
_frameSlider.label = "Frame:";
|
||||
_frameSlider.highValue = 0;
|
||||
_frameSlider.lowValue = 0;
|
||||
_frameSlider.value = 0;
|
||||
_frameSlider.RegisterValueChangedCallback(evt =>
|
||||
{
|
||||
OnFrameSliderChange(evt.newValue);
|
||||
});
|
||||
|
||||
var frameLast = root.Q<ToolbarButton>("FrameLast");
|
||||
frameLast.clicked += OnFrameLast_clicked;
|
||||
|
||||
var frameNext = root.Q<ToolbarButton>("FrameNext");
|
||||
frameNext.clicked += OnFrameNext_clicked;
|
||||
|
||||
var frameClear = root.Q<ToolbarButton>("FrameClear");
|
||||
frameClear.clicked += OnFrameClear_clicked;
|
||||
}
|
||||
|
||||
// 加载视图
|
||||
_assetListViewer = new DebuggerAssetListViewer();
|
||||
_assetListViewer.InitViewer();
|
||||
|
@ -126,7 +151,6 @@ namespace YooAsset.Editor
|
|||
{
|
||||
Debug.Log($"Game player disconnection : {playerId}");
|
||||
_playerName.text = $"Disconneced player : {playerId}";
|
||||
RemovePlayerSession(playerId);
|
||||
}
|
||||
private void OnHandlePlayerMessage(MessageEventArgs args)
|
||||
{
|
||||
|
@ -135,13 +159,53 @@ namespace YooAsset.Editor
|
|||
}
|
||||
private void OnHandleDebugReport(int playerId, DebugReport debugReport)
|
||||
{
|
||||
var playerSession = GetOrCreatePlayerSession(playerId);
|
||||
playerSession.AddDebugReport(debugReport);
|
||||
|
||||
_debugReport = debugReport;
|
||||
_assetListViewer.FillViewData(debugReport, _searchKeyWord);
|
||||
_bundleListViewer.FillViewData(debugReport, _searchKeyWord);
|
||||
Debug.Log($"Handle player {playerId} debug report !");
|
||||
_currentPlayerSession = GetOrCreatePlayerSession(playerId);
|
||||
_currentPlayerSession.AddDebugReport(debugReport);
|
||||
_frameSlider.highValue = _currentPlayerSession.MaxRangeValue;
|
||||
_frameSlider.value = _currentPlayerSession.MaxRangeValue;
|
||||
UpdateFrameView(_currentPlayerSession);
|
||||
}
|
||||
private void OnFrameSliderChange(int sliderValue)
|
||||
{
|
||||
if (_currentPlayerSession != null)
|
||||
{
|
||||
_rangeIndex = _currentPlayerSession.ClampRangeIndex(sliderValue); ;
|
||||
UpdateFrameView(_currentPlayerSession, _rangeIndex);
|
||||
}
|
||||
}
|
||||
private void OnFrameLast_clicked()
|
||||
{
|
||||
if (_currentPlayerSession != null)
|
||||
{
|
||||
_rangeIndex = _currentPlayerSession.ClampRangeIndex(_rangeIndex - 1);
|
||||
_frameSlider.value = _rangeIndex;
|
||||
UpdateFrameView(_currentPlayerSession, _rangeIndex);
|
||||
}
|
||||
}
|
||||
private void OnFrameNext_clicked()
|
||||
{
|
||||
if (_currentPlayerSession != null)
|
||||
{
|
||||
_rangeIndex = _currentPlayerSession.ClampRangeIndex(_rangeIndex + 1);
|
||||
_frameSlider.value = _rangeIndex;
|
||||
UpdateFrameView(_currentPlayerSession, _rangeIndex);
|
||||
}
|
||||
}
|
||||
private void OnFrameClear_clicked()
|
||||
{
|
||||
if (_currentPlayerSession != null)
|
||||
{
|
||||
_frameSlider.label = $"Frame:";
|
||||
_frameSlider.value = 0;
|
||||
_frameSlider.lowValue = 0;
|
||||
_frameSlider.highValue = 0;
|
||||
_currentPlayerSession.ClearDebugReport();
|
||||
_assetListViewer.ClearView();
|
||||
_bundleListViewer.ClearView();
|
||||
}
|
||||
}
|
||||
|
||||
private RemotePlayerSession GetOrCreatePlayerSession(int playerId)
|
||||
{
|
||||
if (_playerSessions.TryGetValue(playerId, out RemotePlayerSession session))
|
||||
|
@ -155,10 +219,26 @@ namespace YooAsset.Editor
|
|||
return newSession;
|
||||
}
|
||||
}
|
||||
private void RemovePlayerSession(int playerId)
|
||||
private void UpdateFrameView(RemotePlayerSession playerSession)
|
||||
{
|
||||
if (_playerSessions.ContainsKey(playerId))
|
||||
_playerSessions.Remove(playerId);
|
||||
if (playerSession != null)
|
||||
{
|
||||
UpdateFrameView(playerSession, playerSession.MaxRangeValue);
|
||||
}
|
||||
}
|
||||
private void UpdateFrameView(RemotePlayerSession playerSession, int rangeIndex)
|
||||
{
|
||||
if (playerSession == null)
|
||||
return;
|
||||
|
||||
var debugReport = playerSession.GetDebugReport(rangeIndex);
|
||||
if (debugReport != null)
|
||||
{
|
||||
_currentReport = debugReport;
|
||||
_frameSlider.label = $"Frame: {debugReport.FrameCount}";
|
||||
_assetListViewer.FillViewData(debugReport, _searchKeyWord);
|
||||
_bundleListViewer.FillViewData(debugReport, _searchKeyWord);
|
||||
}
|
||||
}
|
||||
|
||||
private void SampleBtn_onClick()
|
||||
|
@ -174,13 +254,13 @@ namespace YooAsset.Editor
|
|||
private void OnSearchKeyWordChange(ChangeEvent<string> e)
|
||||
{
|
||||
_searchKeyWord = e.newValue;
|
||||
if (_debugReport != null)
|
||||
if (_currentReport != null)
|
||||
{
|
||||
_assetListViewer.FillViewData(_debugReport, _searchKeyWord);
|
||||
_bundleListViewer.FillViewData(_debugReport, _searchKeyWord);
|
||||
_assetListViewer.FillViewData(_currentReport, _searchKeyWord);
|
||||
_bundleListViewer.FillViewData(_currentReport, _searchKeyWord);
|
||||
}
|
||||
}
|
||||
private void ViewModeMenuAction(DropdownMenuAction action)
|
||||
private void OnViewModeMenuChange(DropdownMenuAction action)
|
||||
{
|
||||
var viewMode = (EViewMode)action.userData;
|
||||
if (_viewMode != viewMode)
|
||||
|
@ -205,7 +285,7 @@ namespace YooAsset.Editor
|
|||
}
|
||||
}
|
||||
}
|
||||
private DropdownMenuAction.Status ViewModeMenuFun(DropdownMenuAction action)
|
||||
private DropdownMenuAction.Status OnViewModeMenuStatusUpdate(DropdownMenuAction action)
|
||||
{
|
||||
var viewMode = (EViewMode)action.userData;
|
||||
if (_viewMode == viewMode)
|
||||
|
|
|
@ -1,8 +1,14 @@
|
|||
<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="Toolbar" style="display: flex;">
|
||||
<uie:Toolbar name="TopToolbar" style="display: flex;">
|
||||
<ui:Label text="Player" display-tooltip-when-elided="true" name="PlayerName" style="width: 200px; -unity-text-align: middle-left; padding-left: 5px;" />
|
||||
<uie:ToolbarMenu display-tooltip-when-elided="true" name="ViewModeMenu" text="ViewMode" style="width: 100px; flex-grow: 0;" />
|
||||
<uie:ToolbarSearchField focusable="true" name="SearchField" style="flex-grow: 1;" />
|
||||
<uie:ToolbarButton text="刷新" 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:Toolbar>
|
||||
<uie:Toolbar name="FrameToolbar">
|
||||
<ui:SliderInt picking-mode="Ignore" label="Frame:" value="42" high-value="100" name="FrameSlider" style="flex-grow: 1;" />
|
||||
<uie:ToolbarButton text=" << " display-tooltip-when-elided="true" name="FrameLast" />
|
||||
<uie:ToolbarButton text=" >> " display-tooltip-when-elided="true" name="FrameNext" />
|
||||
<uie:ToolbarButton text="Clear" display-tooltip-when-elided="true" name="FrameClear" />
|
||||
</uie:Toolbar>
|
||||
</ui:UXML>
|
||||
|
|
|
@ -18,6 +18,24 @@ namespace YooAsset.Editor
|
|||
/// </summary>
|
||||
public int MaxReportCount { private set; get; }
|
||||
|
||||
public int MinRangeValue
|
||||
{
|
||||
get
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
public int MaxRangeValue
|
||||
{
|
||||
get
|
||||
{
|
||||
int index = _reportList.Count - 1;
|
||||
if (index < 0)
|
||||
index = 0;
|
||||
return index;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public RemotePlayerSession(int playerId, int maxReportCount = 1000)
|
||||
{
|
||||
|
@ -25,6 +43,14 @@ namespace YooAsset.Editor
|
|||
MaxReportCount = maxReportCount;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清理缓存数据
|
||||
/// </summary>
|
||||
public void ClearDebugReport()
|
||||
{
|
||||
_reportList.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加一个调试报告
|
||||
/// </summary>
|
||||
|
@ -39,13 +65,29 @@ namespace YooAsset.Editor
|
|||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取最近一次的报告
|
||||
/// 获取调试报告
|
||||
/// </summary>
|
||||
public DebugReport GetLatestReport()
|
||||
public DebugReport GetDebugReport(int rangeIndex)
|
||||
{
|
||||
if (_reportList.Count == 0)
|
||||
return null;
|
||||
return _reportList[_reportList.Count - 1];
|
||||
if (rangeIndex < 0 || rangeIndex >= _reportList.Count)
|
||||
return null;
|
||||
return _reportList[rangeIndex];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 规范索引值
|
||||
/// </summary>
|
||||
public int ClampRangeIndex(int rangeIndex)
|
||||
{
|
||||
if (rangeIndex < 0)
|
||||
return 0;
|
||||
|
||||
if (rangeIndex > MaxRangeValue)
|
||||
return MaxRangeValue;
|
||||
|
||||
return rangeIndex;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -47,6 +47,18 @@ namespace YooAsset.Editor
|
|||
_dependListView.bindItem = BindDependListViewItem;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清空页面
|
||||
/// </summary>
|
||||
public void ClearView()
|
||||
{
|
||||
_debugReport = null;
|
||||
_assetListView.Clear();
|
||||
_assetListView.ClearSelection();
|
||||
_assetListView.itemsSource.Clear();
|
||||
_assetListView.Rebuild();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 填充页面数据
|
||||
/// </summary>
|
||||
|
|
|
@ -46,6 +46,18 @@ namespace YooAsset.Editor
|
|||
_usingListView.makeItem = MakeIncludeListViewItem;
|
||||
_usingListView.bindItem = BindIncludeListViewItem;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 清空页面
|
||||
/// </summary>
|
||||
public void ClearView()
|
||||
{
|
||||
_debugReport = null;
|
||||
_bundleListView.Clear();
|
||||
_bundleListView.ClearSelection();
|
||||
_bundleListView.itemsSource.Clear();
|
||||
_bundleListView.Rebuild();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 填充页面数据
|
||||
|
|
Loading…
Reference in New Issue