update asset bundle debugger

pull/497/head
何冠峰 2025-03-05 17:26:58 +08:00
parent ed9692574c
commit e58999e484
10 changed files with 115 additions and 66 deletions

View File

@ -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

View File

@ -1,12 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
namespace YooAsset.Editor
{
internal class RemotePlayerSession
{
private readonly List<DebugReport> _reportList = new List<DebugReport>();
private readonly Queue<DebugReport> _reports = new Queue<DebugReport>();
/// <summary>
/// 用户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
/// </summary>
public void ClearDebugReport()
{
_reportList.Clear();
_reports.Clear();
}
/// <summary>
@ -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);
}
/// <summary>
@ -69,11 +70,11 @@ namespace YooAsset.Editor
/// </summary>
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);
}
/// <summary>

View File

@ -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();
}
/// <summary>
@ -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();
}
/// <summary>

View File

@ -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();
}
/// <summary>

View File

@ -337,8 +337,10 @@ namespace YooAsset.Editor
public void ClearView()
{
_operationTableView.ClearAll(false, true);
_operationTableView.RebuildView();
_childTreeView.ClearAll();
RebuildView(null);
_childTreeView.RebuildView();
}
/// <summary>
@ -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
{

View File

@ -5,7 +5,7 @@ using System.Collections.Generic;
namespace YooAsset
{
[Serializable]
internal class DebugBundleInfo : IComparer<DebugBundleInfo>, IComparable<DebugBundleInfo>
internal struct DebugBundleInfo : IComparer<DebugBundleInfo>, IComparable<DebugBundleInfo>
{
/// <summary>
/// 资源包名称
@ -20,7 +20,7 @@ namespace YooAsset
/// <summary>
/// 加载状态
/// </summary>
public EOperationStatus Status;
public string Status;
/// <summary>
/// 谁引用了该资源包

View File

@ -5,7 +5,7 @@ using System.Collections.Generic;
namespace YooAsset
{
[Serializable]
internal class DebugOperationInfo : IComparer<DebugOperationInfo>, IComparable<DebugOperationInfo>
internal struct DebugOperationInfo : IComparer<DebugOperationInfo>, IComparable<DebugOperationInfo>
{
/// <summary>
/// 任务名称

View File

@ -47,7 +47,7 @@ namespace YooAsset
else
{
UnityEngine.Debug.LogError($"Can not found {nameof(DebugBundleInfo)} : {bundleName}");
return null;
return default;
}
}
}

View File

@ -5,7 +5,7 @@ using System.Collections.Generic;
namespace YooAsset
{
[Serializable]
internal class DebugProviderInfo : IComparer<DebugProviderInfo>, IComparable<DebugProviderInfo>
internal struct DebugProviderInfo : IComparer<DebugProviderInfo>, IComparable<DebugProviderInfo>
{
/// <summary>
/// 包裹名

View File

@ -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);
}