Added debugging information

新增调试信息,出生场景和出生时间。
pull/4/head
hevinci 2022-04-22 16:22:09 +08:00
parent 7683746032
commit e6422445a6
7 changed files with 134 additions and 25 deletions

View File

@ -114,7 +114,7 @@ namespace YooAsset.Editor
label.style.unityTextAlign = TextAnchor.MiddleLeft;
label.style.marginLeft = 3f;
//label.style.flexGrow = 1f;
label.style.width = 100;
label.style.width = 150;
element.Add(label);
}
@ -124,6 +124,26 @@ namespace YooAsset.Editor
label.style.unityTextAlign = TextAnchor.MiddleLeft;
label.style.marginLeft = 3f;
//label.style.flexGrow = 1f;
label.style.width = 150;
element.Add(label);
}
{
var label = new Label();
label.name = "Label4";
label.style.unityTextAlign = TextAnchor.MiddleLeft;
label.style.marginLeft = 3f;
//label.style.flexGrow = 1f;
label.style.width = 100;
element.Add(label);
}
{
var label = new Label();
label.name = "Label5";
label.style.unityTextAlign = TextAnchor.MiddleLeft;
label.style.marginLeft = 3f;
//label.style.flexGrow = 1f;
label.style.width = 120;
element.Add(label);
}
@ -139,9 +159,17 @@ namespace YooAsset.Editor
var label1 = element.Q<Label>("Label1");
label1.text = providerInfo.AssetPath;
// Ref Count
// Spawn Scene
var label2 = element.Q<Label>("Label2");
label2.text = providerInfo.RefCount.ToString();
label2.text = providerInfo.SpawnScene;
// Spawn Time
var label3 = element.Q<Label>("Label3");
label3.text = providerInfo.SpawnTime;
// Ref Count
var label4 = element.Q<Label>("Label4");
label4.text = providerInfo.RefCount.ToString();
// Status
StyleColor textColor;
@ -149,9 +177,9 @@ namespace YooAsset.Editor
textColor = new StyleColor(Color.yellow);
else
textColor = label1.style.color;
var label3 = element.Q<Label>("Label3");
label3.text = providerInfo.Status.ToString();
label3.style.color = textColor;
var label5 = element.Q<Label>("Label5");
label5.text = providerInfo.Status.ToString();
label5.style.color = textColor;
}
private void AssetListView_onSelectionChange(IEnumerable<object> objs)
{

View File

@ -2,8 +2,10 @@
<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;">
<uie:Toolbar name="TopBar" style="height: 25px; margin-left: 1px; margin-right: 1px;">
<uie:ToolbarButton text="Asset Path" display-tooltip-when-elided="true" name="TopBar1" style="width: 280px; -unity-text-align: middle-left; flex-grow: 1;" />
<uie:ToolbarButton text="Ref Count" display-tooltip-when-elided="true" name="TopBar2" style="width: 100px; -unity-text-align: middle-left; flex-grow: 0;" />
<uie:ToolbarButton text="Status" display-tooltip-when-elided="true" name="TopBar3" style="width: 120px; -unity-text-align: middle-left;" />
<uie:ToolbarButton text="Spawn Scene" display-tooltip-when-elided="true" name="TopBar2" style="width: 150px; -unity-text-align: middle-left; flex-grow: 0;" />
<uie:ToolbarButton text="Spawn Time" display-tooltip-when-elided="true" name="TopBar3" style="width: 150px; -unity-text-align: middle-left; flex-grow: 0;" />
<uie:ToolbarButton text="Ref Count" display-tooltip-when-elided="true" name="TopBar4" style="width: 100px; -unity-text-align: middle-left; flex-grow: 0;" />
<uie:ToolbarButton text="Status" display-tooltip-when-elided="true" name="TopBar5" style="width: 120px; -unity-text-align: middle-left;" />
</uie:Toolbar>
<ui:ListView focusable="true" name="TopListView" item-height="18" style="flex-grow: 1;" />
</ui:VisualElement>

View File

@ -65,14 +65,14 @@ namespace YooAsset.Editor
Dictionary<string, DebugBundleInfo> result = new Dictionary<string, DebugBundleInfo>(debugReport.ProviderInfos.Count);
foreach (var providerInfo in debugReport.ProviderInfos)
{
foreach(var bundleInfo in providerInfo.BundleInfos)
foreach (var bundleInfo in providerInfo.BundleInfos)
{
if (string.IsNullOrEmpty(searchKeyWord) == false)
{
if (bundleInfo.BundleName.Contains(searchKeyWord) == false)
continue;
}
if(result.ContainsKey(bundleInfo.BundleName) == false)
if (result.ContainsKey(bundleInfo.BundleName) == false)
result.Add(bundleInfo.BundleName, bundleInfo);
}
}
@ -95,7 +95,7 @@ namespace YooAsset.Editor
_root.RemoveFromHierarchy();
}
// 顶部列表相关
private VisualElement MakeAssetListViewItem()
{
@ -188,7 +188,7 @@ namespace YooAsset.Editor
label.style.unityTextAlign = TextAnchor.MiddleLeft;
label.style.marginLeft = 3f;
//label.style.flexGrow = 1f;
label.style.width = 100;
label.style.width = 150;
element.Add(label);
}
@ -198,10 +198,30 @@ namespace YooAsset.Editor
label.style.unityTextAlign = TextAnchor.MiddleLeft;
label.style.marginLeft = 3f;
//label.style.flexGrow = 1f;
label.style.width = 150;
element.Add(label);
}
{
var label = new Label();
label.name = "Label4";
label.style.unityTextAlign = TextAnchor.MiddleLeft;
label.style.marginLeft = 3f;
//label.style.flexGrow = 1f;
label.style.width = 100;
element.Add(label);
}
{
var label = new Label();
label.name = "Label5";
label.style.unityTextAlign = TextAnchor.MiddleLeft;
label.style.marginLeft = 3f;
//label.style.flexGrow = 1f;
label.style.width = 120;
element.Add(label);
}
return element;
}
private void BindIncludeListViewItem(VisualElement element, int index)
@ -213,29 +233,37 @@ namespace YooAsset.Editor
var label1 = element.Q<Label>("Label1");
label1.text = providerInfo.AssetPath;
// Ref Count
// Spawn Scene
var label2 = element.Q<Label>("Label2");
label2.text = providerInfo.RefCount.ToString();
label2.text = providerInfo.SpawnScene;
// Spawn Time
var label3 = element.Q<Label>("Label3");
label3.text = providerInfo.SpawnTime;
// Ref Count
var label4 = element.Q<Label>("Label4");
label4.text = providerInfo.RefCount.ToString();
// Status
var label3 = element.Q<Label>("Label3");
label3.text = providerInfo.Status.ToString();
var label5 = element.Q<Label>("Label5");
label5.text = providerInfo.Status.ToString();
}
private void FillUsingListView(string bundleName)
{
_usingListView.Clear();
_usingListView.ClearSelection();
List<DebugProviderInfo> source = new List<DebugProviderInfo>();
foreach(var providerInfo in _debugReport.ProviderInfos)
List<DebugProviderInfo> source = new List<DebugProviderInfo>();
foreach (var providerInfo in _debugReport.ProviderInfos)
{
foreach(var bundleInfo in providerInfo.BundleInfos)
foreach (var bundleInfo in providerInfo.BundleInfos)
{
if (bundleInfo.BundleName == bundleName)
{
source.Add(providerInfo);
continue;
}
}
}
}
_usingListView.itemsSource = source;

View File

@ -10,8 +10,10 @@
<ui:VisualElement name="BottomGroup" style="height: 200px; 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: 1px; margin-bottom: 1px; display: flex;">
<uie:Toolbar name="BottomBar" style="height: 25px; margin-left: 1px; margin-right: 1px;">
<uie:ToolbarButton text="Using Assets" display-tooltip-when-elided="true" name="BottomBar1" style="width: 280px; -unity-text-align: middle-left; flex-grow: 1;" />
<uie:ToolbarButton text="Ref Count" display-tooltip-when-elided="true" name="BottomBar3" style="width: 100px; -unity-text-align: middle-left;" />
<uie:ToolbarButton text="Status" display-tooltip-when-elided="true" name="BottomBar4" style="width: 120px; -unity-text-align: middle-left;" />
<uie:ToolbarButton text="Spawn Scene" display-tooltip-when-elided="true" name="BottomBar2" style="width: 150px; -unity-text-align: middle-left;" />
<uie:ToolbarButton text="Spawn Time" display-tooltip-when-elided="true" name="BottomBar3" style="width: 150px; -unity-text-align: middle-left;" />
<uie:ToolbarButton text="Ref Count" display-tooltip-when-elided="true" name="BottomBar4" style="width: 100px; -unity-text-align: middle-left;" />
<uie:ToolbarButton text="Status" display-tooltip-when-elided="true" name="BottomBar5" style="width: 120px; -unity-text-align: middle-left;" />
</uie:Toolbar>
<ui:ListView focusable="true" name="BottomListView" item-height="18" style="flex-grow: 1;" />
</ui:VisualElement>

View File

@ -1,6 +1,7 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using UnityEngine.SceneManagement;
@ -11,7 +12,8 @@ namespace YooAsset
private static readonly List<AssetBundleLoaderBase> _loaders = new List<AssetBundleLoaderBase>(1000);
private static readonly List<ProviderBase> _providers = new List<ProviderBase>(1000);
private static readonly Dictionary<string, SceneOperationHandle> _sceneHandles = new Dictionary<string, SceneOperationHandle>(100);
private static string _mainSceneName = string.Empty;
/// <summary>
/// 在编辑器下模拟运行
/// </summary>
@ -36,6 +38,7 @@ namespace YooAsset
AssetLoadingMaxNumber = assetLoadingMaxNumber;
DecryptionServices = decryptionServices;
BundleServices = bundleServices;
_mainSceneName = SceneManager.GetActiveScene().name;
}
/// <summary>
@ -139,7 +142,10 @@ namespace YooAsset
// 如果加载的是主场景,则卸载所有缓存的场景
if (sceneMode == LoadSceneMode.Single)
{
UnloadAllScene();
_mainSceneName = Path.GetFileName(scenePath);
}
ProviderBase provider = TryGetProvider(scenePath);
if (provider == null)
@ -148,8 +154,10 @@ namespace YooAsset
provider = new DatabaseSceneProvider(scenePath, sceneMode, activateOnLoad, priority);
else
provider = new BundledSceneProvider(scenePath, sceneMode, activateOnLoad, priority);
provider.SetSpawnDebugInfo(_mainSceneName);
_providers.Add(provider);
}
var handle = provider.CreateHandle() as SceneOperationHandle;
_sceneHandles.Add(scenePath, handle);
return handle;
@ -167,6 +175,7 @@ namespace YooAsset
provider = new DatabaseAssetProvider(assetPath, assetType);
else
provider = new BundledAssetProvider(assetPath, assetType);
provider.SetSpawnDebugInfo(_mainSceneName);
_providers.Add(provider);
}
return provider.CreateHandle() as AssetOperationHandle;
@ -184,6 +193,7 @@ namespace YooAsset
provider = new DatabaseSubAssetsProvider(assetPath, assetType);
else
provider = new BundledSubAssetsProvider(assetPath, assetType);
provider.SetSpawnDebugInfo(_mainSceneName);
_providers.Add(provider);
}
return provider.CreateHandle() as SubAssetsOperationHandle;
@ -319,6 +329,8 @@ namespace YooAsset
{
DebugProviderInfo providerInfo = new DebugProviderInfo();
providerInfo.AssetPath = provider.AssetPath;
providerInfo.SpawnScene = provider.SpawnScene;
providerInfo.SpawnTime = provider.SpawnTime;
providerInfo.RefCount = provider.RefCount;
providerInfo.Status = provider.Status;
providerInfo.BundleInfos.Clear();

View File

@ -1,5 +1,6 @@
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading.Tasks;
namespace YooAsset
@ -202,7 +203,7 @@ namespace YooAsset
{
get
{
if(_taskCompletionSource == null)
if (_taskCompletionSource == null)
{
_taskCompletionSource = new TaskCompletionSource<object>();
if (IsDone)
@ -226,9 +227,35 @@ namespace YooAsset
}
}
if(_taskCompletionSource != null)
if (_taskCompletionSource != null)
_taskCompletionSource.TrySetResult(null);
}
#endregion
#region 调试信息相关
/// <summary>
/// 出生的场景
/// </summary>
public string SpawnScene = string.Empty;
/// <summary>
/// 出生的时间
/// </summary>
public string SpawnTime = string.Empty;
[Conditional("DEBUG")]
public void SetSpawnDebugInfo(string spawnScene)
{
SpawnScene = spawnScene;
SpawnTime = SpawnTimeToString(UnityEngine.Time.realtimeSinceStartup);
}
private string SpawnTimeToString(float spawnTime)
{
float h = UnityEngine.Mathf.FloorToInt(spawnTime / 3600f);
float m = UnityEngine.Mathf.FloorToInt(spawnTime / 60f - h * 60f);
float s = UnityEngine.Mathf.FloorToInt(spawnTime - m * 60f - h * 3600f);
return h.ToString("00") + ":" + m.ToString("00") + ":" + s.ToString("00");
}
#endregion
}
}

View File

@ -11,6 +11,16 @@ namespace YooAsset
/// </summary>
public string AssetPath { set; get; }
/// <summary>
/// 资源出生的场景
/// </summary>
public string SpawnScene { set; get; }
/// <summary>
/// 资源出生的时间
/// </summary>
public string SpawnTime { set; get; }
/// <summary>
/// 引用计数
/// </summary>