From e58999e484f3239cea787a6cbf86cb7173c105af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=95=E5=86=A0=E5=B3=B0?= Date: Wed, 5 Mar 2025 17:26:58 +0800 Subject: [PATCH] update asset bundle debugger --- .../AssetBundleDebuggerWindow.cs | 118 ++++++++++++------ .../RemotePlayerSession.cs | 21 ++-- .../VisualViewers/DebuggerAssetListViewer.cs | 10 +- .../VisualViewers/DebuggerBundleListViewer.cs | 11 +- .../DebuggerOperationListViewer.cs | 9 +- .../DiagnosticSystem/DebugBundleInfo.cs | 4 +- .../DiagnosticSystem/DebugOperationInfo.cs | 2 +- .../DiagnosticSystem/DebugPackageData.cs | 2 +- .../DiagnosticSystem/DebugProviderInfo.cs | 2 +- .../ResourceManager/ResourceManager.cs | 2 +- 10 files changed, 115 insertions(+), 66 deletions(-) diff --git a/Assets/YooAsset/Editor/AssetBundleDebugger/AssetBundleDebuggerWindow.cs b/Assets/YooAsset/Editor/AssetBundleDebugger/AssetBundleDebuggerWindow.cs index b970b333..cb6e29c1 100644 --- a/Assets/YooAsset/Editor/AssetBundleDebugger/AssetBundleDebuggerWindow.cs +++ b/Assets/YooAsset/Editor/AssetBundleDebugger/AssetBundleDebuggerWindow.cs @@ -59,6 +59,10 @@ namespace YooAsset.Editor private string _searchKeyWord; private DebugReport _currentReport; private RemotePlayerSession _currentPlayerSession; + + private double _lastRepaintTime = 0; + private int _nextRepaintIndex = -1; + private int _lastRepaintIndex = 0; private int _rangeIndex = 0; @@ -161,6 +165,20 @@ namespace YooAsset.Editor RemoteEditorConnection.Instance.Unregister(RemoteDebuggerDefine.kMsgPlayerSendToEditor); _playerSessions.Clear(); } + public void Update() + { + // 每间隔0.5秒绘制一次页面 + if (EditorApplication.timeSinceStartup - _lastRepaintTime > 0.5f) + { + _lastRepaintTime = EditorApplication.timeSinceStartup; + if (_nextRepaintIndex >= 0) + { + RepaintFrame(_nextRepaintIndex); + _lastRepaintIndex = _nextRepaintIndex; + _nextRepaintIndex = -1; + } + } + } private void OnHandleConnectionEvent(int playerId) { @@ -176,19 +194,20 @@ namespace YooAsset.Editor { var debugReport = DebugReport.Deserialize(args.data); int playerId = args.playerId; - Debug.Log($"Handle player {playerId} debug report !"); + + //Debug.Log($"Handle player {playerId} debug report !"); _currentPlayerSession = GetOrCreatePlayerSession(playerId); _currentPlayerSession.AddDebugReport(debugReport); _frameSlider.highValue = _currentPlayerSession.MaxRangeValue; _frameSlider.value = _currentPlayerSession.MaxRangeValue; - UpdateFrameView(_currentPlayerSession); + UpdateRepaintIndex(_currentPlayerSession.MaxRangeValue); } private void OnFrameSliderChange(int sliderValue) { if (_currentPlayerSession != null) { _rangeIndex = _currentPlayerSession.ClampRangeIndex(sliderValue); ; - UpdateFrameView(_currentPlayerSession, _rangeIndex); + UpdateRepaintIndex(_rangeIndex); } } private void OnFrameLast_clicked() @@ -197,7 +216,7 @@ namespace YooAsset.Editor { _rangeIndex = _currentPlayerSession.ClampRangeIndex(_rangeIndex - 1); _frameSlider.value = _rangeIndex; - UpdateFrameView(_currentPlayerSession, _rangeIndex); + UpdateRepaintIndex(_rangeIndex); } } private void OnFrameNext_clicked() @@ -206,7 +225,7 @@ namespace YooAsset.Editor { _rangeIndex = _currentPlayerSession.ClampRangeIndex(_rangeIndex + 1); _frameSlider.value = _rangeIndex; - UpdateFrameView(_currentPlayerSession, _rangeIndex); + UpdateRepaintIndex(_rangeIndex); } } private void OnFrameClear_clicked() @@ -234,42 +253,6 @@ namespace YooAsset.Editor RemoteEditorConnection.Instance.Send(RemoteDebuggerDefine.kMsgEditorSendToPlayer, data); } - private RemotePlayerSession GetOrCreatePlayerSession(int playerId) - { - if (_playerSessions.TryGetValue(playerId, out RemotePlayerSession session)) - { - return session; - } - else - { - RemotePlayerSession newSession = new RemotePlayerSession(playerId); - _playerSessions.Add(playerId, newSession); - return newSession; - } - } - private void UpdateFrameView(RemotePlayerSession playerSession) - { - 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); - _bundleListViewer.FillViewData(debugReport); - _operationListViewer.FillViewData(debugReport); - } - } - private void SampleBtn_onClick() { // 发送采集数据的命令 @@ -347,6 +330,9 @@ namespace YooAsset.Editor { throw new NotImplementedException(viewMode.ToString()); } + + // 重新绘制该帧数据 + RepaintFrame(_lastRepaintIndex); } } private DropdownMenuAction.Status OnViewModeMenuStatusUpdate(DropdownMenuAction action) @@ -357,6 +343,56 @@ namespace YooAsset.Editor else return DropdownMenuAction.Status.Normal; } + + private RemotePlayerSession GetOrCreatePlayerSession(int playerId) + { + if (_playerSessions.TryGetValue(playerId, out RemotePlayerSession session)) + { + return session; + } + else + { + RemotePlayerSession newSession = new RemotePlayerSession(playerId); + _playerSessions.Add(playerId, newSession); + return newSession; + } + } + private void UpdateRepaintIndex(int rangeIndex) + { + _nextRepaintIndex = rangeIndex; + } + private void RepaintFrame(int repaintIndex) + { + var debugReport = _currentPlayerSession.GetDebugReport(repaintIndex); + if (debugReport != null) + { + _currentReport = debugReport; + _frameSlider.label = $"Frame: {debugReport.FrameCount}"; + + if (_viewMode == EViewMode.AssetView) + { + _assetListViewer.FillViewData(debugReport); + _bundleListViewer.ClearView(); + _operationListViewer.ClearView(); + } + else if (_viewMode == EViewMode.BundleView) + { + _assetListViewer.ClearView(); + _bundleListViewer.FillViewData(debugReport); + _operationListViewer.ClearView(); + } + else if (_viewMode == EViewMode.OperationView) + { + _assetListViewer.ClearView(); + _bundleListViewer.ClearView(); + _operationListViewer.FillViewData(debugReport); + } + else + { + throw new System.NotImplementedException(_viewMode.ToString()); + } + } + } } } #endif \ No newline at end of file diff --git a/Assets/YooAsset/Editor/AssetBundleDebugger/RemotePlayerSession.cs b/Assets/YooAsset/Editor/AssetBundleDebugger/RemotePlayerSession.cs index f7ff4fab..68a990ce 100644 --- a/Assets/YooAsset/Editor/AssetBundleDebugger/RemotePlayerSession.cs +++ b/Assets/YooAsset/Editor/AssetBundleDebugger/RemotePlayerSession.cs @@ -1,12 +1,13 @@ using System; using System.Collections.Generic; +using System.Linq; using UnityEngine; namespace YooAsset.Editor { internal class RemotePlayerSession { - private readonly List _reportList = new List(); + private readonly Queue _reports = new Queue(); /// /// 用户ID @@ -29,7 +30,7 @@ namespace YooAsset.Editor { get { - int index = _reportList.Count - 1; + int index = _reports.Count - 1; if (index < 0) index = 0; return index; @@ -37,7 +38,7 @@ namespace YooAsset.Editor } - public RemotePlayerSession(int playerId, int maxReportCount = 1000) + public RemotePlayerSession(int playerId, int maxReportCount = 500) { PlayerId = playerId; MaxReportCount = maxReportCount; @@ -48,7 +49,7 @@ namespace YooAsset.Editor /// public void ClearDebugReport() { - _reportList.Clear(); + _reports.Clear(); } /// @@ -59,9 +60,9 @@ namespace YooAsset.Editor if (report == null) Debug.LogWarning("Invalid debug report data !"); - if (_reportList.Count >= MaxReportCount) - _reportList.RemoveAt(0); - _reportList.Add(report); + if (_reports.Count >= MaxReportCount) + _reports.Dequeue(); + _reports.Enqueue(report); } /// @@ -69,11 +70,11 @@ namespace YooAsset.Editor /// public DebugReport GetDebugReport(int rangeIndex) { - if (_reportList.Count == 0) + if (_reports.Count == 0) return null; - if (rangeIndex < 0 || rangeIndex >= _reportList.Count) + if (rangeIndex < 0 || rangeIndex >= _reports.Count) return null; - return _reportList[rangeIndex]; + return _reports.ElementAt(rangeIndex); } /// diff --git a/Assets/YooAsset/Editor/AssetBundleDebugger/VisualViewers/DebuggerAssetListViewer.cs b/Assets/YooAsset/Editor/AssetBundleDebugger/VisualViewers/DebuggerAssetListViewer.cs index 92def7d1..28c166d2 100644 --- a/Assets/YooAsset/Editor/AssetBundleDebugger/VisualViewers/DebuggerAssetListViewer.cs +++ b/Assets/YooAsset/Editor/AssetBundleDebugger/VisualViewers/DebuggerAssetListViewer.cs @@ -279,7 +279,7 @@ namespace YooAsset.Editor { StyleColor textColor; var dependTableData = data as DependTableData; - if (dependTableData.BundleInfo.Status == EOperationStatus.Failed) + if (dependTableData.BundleInfo.Status == EOperationStatus.Failed.ToString()) textColor = new StyleColor(Color.yellow); else textColor = new StyleColor(Color.white); @@ -332,8 +332,10 @@ namespace YooAsset.Editor public void ClearView() { _providerTableView.ClearAll(false, true); + _providerTableView.RebuildView(); + _dependTableView.ClearAll(false, true); - RebuildView(null); + _dependTableView.RebuildView(); } /// @@ -342,10 +344,12 @@ namespace YooAsset.Editor public void RebuildView(string searchKeyWord) { // 搜索匹配 - DefaultSearchSystem.Search(_sourceDatas, searchKeyWord); + if (_sourceDatas != null) + DefaultSearchSystem.Search(_sourceDatas, searchKeyWord); // 重建视图 _providerTableView.RebuildView(); + _dependTableView.RebuildView(); } /// diff --git a/Assets/YooAsset/Editor/AssetBundleDebugger/VisualViewers/DebuggerBundleListViewer.cs b/Assets/YooAsset/Editor/AssetBundleDebugger/VisualViewers/DebuggerBundleListViewer.cs index 3f91b6c2..1b7287b1 100644 --- a/Assets/YooAsset/Editor/AssetBundleDebugger/VisualViewers/DebuggerBundleListViewer.cs +++ b/Assets/YooAsset/Editor/AssetBundleDebugger/VisualViewers/DebuggerBundleListViewer.cs @@ -151,7 +151,7 @@ namespace YooAsset.Editor { StyleColor textColor; var bundleTableData = data as BundleTableData; - if (bundleTableData.BundleInfo.Status == EOperationStatus.Failed) + if (bundleTableData.BundleInfo.Status == EOperationStatus.Failed.ToString()) textColor = new StyleColor(Color.yellow); else textColor = new StyleColor(Color.white); @@ -341,7 +341,7 @@ namespace YooAsset.Editor { StyleColor textColor; var feferenceTableData = data as ReferenceTableData; - if (feferenceTableData.BundleInfo.Status == EOperationStatus.Failed) + if (feferenceTableData.BundleInfo.Status == EOperationStatus.Failed.ToString()) textColor = new StyleColor(Color.yellow); else textColor = new StyleColor(Color.white); @@ -393,8 +393,10 @@ namespace YooAsset.Editor { _bundleTableView.ClearAll(false, true); _bundleTableView.RebuildView(); + _usingTableView.ClearAll(false, true); _usingTableView.RebuildView(); + _referenceTableView.ClearAll(false, true); _referenceTableView.RebuildView(); } @@ -405,10 +407,13 @@ namespace YooAsset.Editor public void RebuildView(string searchKeyWord) { // 搜索匹配 - DefaultSearchSystem.Search(_sourceDatas, searchKeyWord); + if(_sourceDatas != null) + DefaultSearchSystem.Search(_sourceDatas, searchKeyWord); // 重建视图 _bundleTableView.RebuildView(); + _usingTableView.RebuildView(); + _referenceTableView.RebuildView(); } /// diff --git a/Assets/YooAsset/Editor/AssetBundleDebugger/VisualViewers/DebuggerOperationListViewer.cs b/Assets/YooAsset/Editor/AssetBundleDebugger/VisualViewers/DebuggerOperationListViewer.cs index 78bd8a31..4ea3747a 100644 --- a/Assets/YooAsset/Editor/AssetBundleDebugger/VisualViewers/DebuggerOperationListViewer.cs +++ b/Assets/YooAsset/Editor/AssetBundleDebugger/VisualViewers/DebuggerOperationListViewer.cs @@ -337,8 +337,10 @@ namespace YooAsset.Editor public void ClearView() { _operationTableView.ClearAll(false, true); + _operationTableView.RebuildView(); + _childTreeView.ClearAll(); - RebuildView(null); + _childTreeView.RebuildView(); } /// @@ -347,7 +349,8 @@ namespace YooAsset.Editor public void RebuildView(string searchKeyWord) { // 搜索匹配 - DefaultSearchSystem.Search(_sourceDatas, searchKeyWord); + if(_sourceDatas != null) + DefaultSearchSystem.Search(_sourceDatas, searchKeyWord); // 重建视图 _operationTableView.RebuildView(); @@ -446,7 +449,7 @@ namespace YooAsset.Editor } private void BindTreeViewItem(VisualElement container, object userData) { - var operationInfo = userData as DebugOperationInfo; + var operationInfo = (DebugOperationInfo)userData; // OperationName { diff --git a/Assets/YooAsset/Runtime/DiagnosticSystem/DebugBundleInfo.cs b/Assets/YooAsset/Runtime/DiagnosticSystem/DebugBundleInfo.cs index 685dc4e3..6c0fe654 100644 --- a/Assets/YooAsset/Runtime/DiagnosticSystem/DebugBundleInfo.cs +++ b/Assets/YooAsset/Runtime/DiagnosticSystem/DebugBundleInfo.cs @@ -5,7 +5,7 @@ using System.Collections.Generic; namespace YooAsset { [Serializable] - internal class DebugBundleInfo : IComparer, IComparable + internal struct DebugBundleInfo : IComparer, IComparable { /// /// 资源包名称 @@ -20,7 +20,7 @@ namespace YooAsset /// /// 加载状态 /// - public EOperationStatus Status; + public string Status; /// /// 谁引用了该资源包 diff --git a/Assets/YooAsset/Runtime/DiagnosticSystem/DebugOperationInfo.cs b/Assets/YooAsset/Runtime/DiagnosticSystem/DebugOperationInfo.cs index 17cafc73..18a16aeb 100644 --- a/Assets/YooAsset/Runtime/DiagnosticSystem/DebugOperationInfo.cs +++ b/Assets/YooAsset/Runtime/DiagnosticSystem/DebugOperationInfo.cs @@ -5,7 +5,7 @@ using System.Collections.Generic; namespace YooAsset { [Serializable] - internal class DebugOperationInfo : IComparer, IComparable + internal struct DebugOperationInfo : IComparer, IComparable { /// /// 任务名称 diff --git a/Assets/YooAsset/Runtime/DiagnosticSystem/DebugPackageData.cs b/Assets/YooAsset/Runtime/DiagnosticSystem/DebugPackageData.cs index 3360a165..41be3761 100644 --- a/Assets/YooAsset/Runtime/DiagnosticSystem/DebugPackageData.cs +++ b/Assets/YooAsset/Runtime/DiagnosticSystem/DebugPackageData.cs @@ -47,7 +47,7 @@ namespace YooAsset else { UnityEngine.Debug.LogError($"Can not found {nameof(DebugBundleInfo)} : {bundleName}"); - return null; + return default; } } } diff --git a/Assets/YooAsset/Runtime/DiagnosticSystem/DebugProviderInfo.cs b/Assets/YooAsset/Runtime/DiagnosticSystem/DebugProviderInfo.cs index d80c62e8..691f4ce7 100644 --- a/Assets/YooAsset/Runtime/DiagnosticSystem/DebugProviderInfo.cs +++ b/Assets/YooAsset/Runtime/DiagnosticSystem/DebugProviderInfo.cs @@ -5,7 +5,7 @@ using System.Collections.Generic; namespace YooAsset { [Serializable] - internal class DebugProviderInfo : IComparer, IComparable + internal struct DebugProviderInfo : IComparer, IComparable { /// /// 包裹名 diff --git a/Assets/YooAsset/Runtime/ResourceManager/ResourceManager.cs b/Assets/YooAsset/Runtime/ResourceManager/ResourceManager.cs index 35869aa6..03bf2a10 100644 --- a/Assets/YooAsset/Runtime/ResourceManager/ResourceManager.cs +++ b/Assets/YooAsset/Runtime/ResourceManager/ResourceManager.cs @@ -385,7 +385,7 @@ namespace YooAsset var bundleInfo = new DebugBundleInfo(); bundleInfo.BundleName = packageBundle.BundleName; bundleInfo.RefCount = bundleLoader.RefCount; - bundleInfo.Status = bundleLoader.Status; + bundleInfo.Status = bundleLoader.Status.ToString(); bundleInfo.ReferenceBundles = FilterReferenceBundles(packageBundle); result.Add(bundleInfo); }