From 32ce99949b6e9207d1f22601803c864e71082c81 Mon Sep 17 00:00:00 2001 From: hevinci Date: Sat, 25 Jun 2022 17:56:49 +0800 Subject: [PATCH] Update AssetBundleDebugger MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 完善调试器窗口,增加帧数控制。 --- .../AssetBundleDebuggerWindow.cs | 116 +++++++++++++++--- .../AssetBundleDebuggerWindow.uxml | 8 +- .../RemotePlayerSession.cs | 48 +++++++- .../VisualViewers/DebuggerAssetListViewer.cs | 12 ++ .../VisualViewers/DebuggerBundleListViewer.cs | 12 ++ 5 files changed, 174 insertions(+), 22 deletions(-) diff --git a/Assets/YooAsset/Editor/AssetBundleDebugger/AssetBundleDebuggerWindow.cs b/Assets/YooAsset/Editor/AssetBundleDebugger/AssetBundleDebuggerWindow.cs index 38f83cf..0f91b25 100644 --- a/Assets/YooAsset/Editor/AssetBundleDebugger/AssetBundleDebuggerWindow.cs +++ b/Assets/YooAsset/Editor/AssetBundleDebugger/AssetBundleDebuggerWindow.cs @@ -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("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("SearchField"); searchField.RegisterValueChangedCallback(OnSearchKeyWordChange); + // 帧数相关 + { + _frameSlider = root.Q("FrameSlider"); + _frameSlider.label = "Frame:"; + _frameSlider.highValue = 0; + _frameSlider.lowValue = 0; + _frameSlider.value = 0; + _frameSlider.RegisterValueChangedCallback(evt => + { + OnFrameSliderChange(evt.newValue); + }); + + var frameLast = root.Q("FrameLast"); + frameLast.clicked += OnFrameLast_clicked; + + var frameNext = root.Q("FrameNext"); + frameNext.clicked += OnFrameNext_clicked; + + var frameClear = root.Q("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 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) diff --git a/Assets/YooAsset/Editor/AssetBundleDebugger/AssetBundleDebuggerWindow.uxml b/Assets/YooAsset/Editor/AssetBundleDebugger/AssetBundleDebuggerWindow.uxml index 5714c93..f01af09 100644 --- a/Assets/YooAsset/Editor/AssetBundleDebugger/AssetBundleDebuggerWindow.uxml +++ b/Assets/YooAsset/Editor/AssetBundleDebugger/AssetBundleDebuggerWindow.uxml @@ -1,8 +1,14 @@ - + + + + + + + diff --git a/Assets/YooAsset/Editor/AssetBundleDebugger/RemotePlayerSession.cs b/Assets/YooAsset/Editor/AssetBundleDebugger/RemotePlayerSession.cs index 23e111d..2daf715 100644 --- a/Assets/YooAsset/Editor/AssetBundleDebugger/RemotePlayerSession.cs +++ b/Assets/YooAsset/Editor/AssetBundleDebugger/RemotePlayerSession.cs @@ -18,6 +18,24 @@ namespace YooAsset.Editor /// 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; } + /// + /// 清理缓存数据 + /// + public void ClearDebugReport() + { + _reportList.Clear(); + } + /// /// 添加一个调试报告 /// @@ -39,13 +65,29 @@ namespace YooAsset.Editor } /// - /// 获取最近一次的报告 + /// 获取调试报告 /// - 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]; + } + + /// + /// 规范索引值 + /// + public int ClampRangeIndex(int rangeIndex) + { + if (rangeIndex < 0) + return 0; + + if (rangeIndex > MaxRangeValue) + return MaxRangeValue; + + return rangeIndex; } } } \ No newline at end of file diff --git a/Assets/YooAsset/Editor/AssetBundleDebugger/VisualViewers/DebuggerAssetListViewer.cs b/Assets/YooAsset/Editor/AssetBundleDebugger/VisualViewers/DebuggerAssetListViewer.cs index 09ea941..b28dfe7 100644 --- a/Assets/YooAsset/Editor/AssetBundleDebugger/VisualViewers/DebuggerAssetListViewer.cs +++ b/Assets/YooAsset/Editor/AssetBundleDebugger/VisualViewers/DebuggerAssetListViewer.cs @@ -47,6 +47,18 @@ namespace YooAsset.Editor _dependListView.bindItem = BindDependListViewItem; } + /// + /// 清空页面 + /// + public void ClearView() + { + _debugReport = null; + _assetListView.Clear(); + _assetListView.ClearSelection(); + _assetListView.itemsSource.Clear(); + _assetListView.Rebuild(); + } + /// /// 填充页面数据 /// diff --git a/Assets/YooAsset/Editor/AssetBundleDebugger/VisualViewers/DebuggerBundleListViewer.cs b/Assets/YooAsset/Editor/AssetBundleDebugger/VisualViewers/DebuggerBundleListViewer.cs index 2d8eb82..3b46ab2 100644 --- a/Assets/YooAsset/Editor/AssetBundleDebugger/VisualViewers/DebuggerBundleListViewer.cs +++ b/Assets/YooAsset/Editor/AssetBundleDebugger/VisualViewers/DebuggerBundleListViewer.cs @@ -46,6 +46,18 @@ namespace YooAsset.Editor _usingListView.makeItem = MakeIncludeListViewItem; _usingListView.bindItem = BindIncludeListViewItem; } + + /// + /// 清空页面 + /// + public void ClearView() + { + _debugReport = null; + _bundleListView.Clear(); + _bundleListView.ClearSelection(); + _bundleListView.itemsSource.Clear(); + _bundleListView.Rebuild(); + } /// /// 填充页面数据