mirror of
https://github.com/tuyoogame/YooAsset.git
synced 2026-05-24 17:50:15 +00:00
update diagnostic system
调试窗口增加异步操作视图
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
[Serializable]
|
||||
internal class DebugOperationInfo : IComparer<DebugOperationInfo>, IComparable<DebugOperationInfo>
|
||||
{
|
||||
/// <summary>
|
||||
/// 任务名称
|
||||
/// </summary>
|
||||
public string OperationName;
|
||||
|
||||
/// <summary>
|
||||
/// 优先级
|
||||
/// </summary>
|
||||
public uint Priority;
|
||||
|
||||
/// <summary>
|
||||
/// 任务进度
|
||||
/// </summary>
|
||||
public float Progress;
|
||||
|
||||
/// <summary>
|
||||
/// 任务开始的时间
|
||||
/// </summary>
|
||||
public string BeginTime;
|
||||
|
||||
/// <summary>
|
||||
/// 处理耗时(单位:毫秒)
|
||||
/// </summary>
|
||||
public long ProcessTime;
|
||||
|
||||
/// <summary>
|
||||
/// 任务状态
|
||||
/// </summary>
|
||||
public string Status;
|
||||
|
||||
public int CompareTo(DebugOperationInfo other)
|
||||
{
|
||||
return Compare(this, other);
|
||||
}
|
||||
public int Compare(DebugOperationInfo a, DebugOperationInfo b)
|
||||
{
|
||||
return string.CompareOrdinal(a.OperationName, b.OperationName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 942ce6ad7b4427d4d87a8a29c8b9371f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -13,15 +13,9 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public string PackageName;
|
||||
|
||||
/// <summary>
|
||||
/// 调试数据列表
|
||||
/// </summary>
|
||||
public List<DebugProviderInfo> ProviderInfos = new List<DebugProviderInfo>(1000);
|
||||
|
||||
/// <summary>
|
||||
/// 调试数据列表
|
||||
/// </summary>
|
||||
public List<DebugBundleInfo> BundleInfos = new List<DebugBundleInfo>(1000);
|
||||
public List<DebugOperationInfo> OperationInfos = new List<DebugOperationInfo>(1000);
|
||||
|
||||
|
||||
[NonSerialized]
|
||||
|
||||
@@ -23,9 +23,9 @@ namespace YooAsset
|
||||
public string SpawnScene;
|
||||
|
||||
/// <summary>
|
||||
/// 资源出生的时间
|
||||
/// 资源加载开始时间
|
||||
/// </summary>
|
||||
public string SpawnTime;
|
||||
public string BeginTime;
|
||||
|
||||
/// <summary>
|
||||
/// 加载耗时(单位:毫秒)
|
||||
|
||||
@@ -24,12 +24,12 @@ namespace YooAsset
|
||||
internal bool IsFinish { private set; get; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// 优先级
|
||||
/// 任务优先级
|
||||
/// </summary>
|
||||
public uint Priority { set; get; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 状态
|
||||
/// 任务状态
|
||||
/// </summary>
|
||||
public EOperationStatus Status { get; protected set; } = EOperationStatus.None;
|
||||
|
||||
@@ -139,6 +139,11 @@ namespace YooAsset
|
||||
if (Status == EOperationStatus.None)
|
||||
{
|
||||
Status = EOperationStatus.Processing;
|
||||
|
||||
// 开始记录
|
||||
DebugBeginRecording();
|
||||
|
||||
// 开始任务
|
||||
InternalStart();
|
||||
}
|
||||
}
|
||||
@@ -149,7 +154,13 @@ namespace YooAsset
|
||||
internal void UpdateOperation()
|
||||
{
|
||||
if (IsDone == false)
|
||||
{
|
||||
// 更新记录
|
||||
DebugUpdateRecording();
|
||||
|
||||
// 更新任务
|
||||
InternalUpdate();
|
||||
}
|
||||
|
||||
if (IsDone && IsFinish == false)
|
||||
{
|
||||
@@ -158,6 +169,9 @@ namespace YooAsset
|
||||
// 进度百分百完成
|
||||
Progress = 1f;
|
||||
|
||||
// 结束记录
|
||||
DebugEndRecording();
|
||||
|
||||
//注意:如果完成回调内发生异常,会导致Task无限期等待
|
||||
_callback?.Invoke(this);
|
||||
|
||||
@@ -235,6 +249,55 @@ namespace YooAsset
|
||||
}
|
||||
|
||||
#region 调试信息
|
||||
/// <summary>
|
||||
/// 开始的时间
|
||||
/// </summary>
|
||||
public string BeginTime = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 处理耗时(单位:毫秒)
|
||||
/// </summary>
|
||||
public long ProcessTime { protected set; get; }
|
||||
|
||||
// 加载耗时统计
|
||||
private Stopwatch _watch = null;
|
||||
|
||||
[Conditional("DEBUG")]
|
||||
private void DebugBeginRecording()
|
||||
{
|
||||
if (_watch == null)
|
||||
{
|
||||
BeginTime = SpawnTimeToString(UnityEngine.Time.realtimeSinceStartup);
|
||||
_watch = Stopwatch.StartNew();
|
||||
}
|
||||
}
|
||||
|
||||
[Conditional("DEBUG")]
|
||||
private void DebugUpdateRecording()
|
||||
{
|
||||
if (_watch != null)
|
||||
{
|
||||
ProcessTime = _watch.ElapsedMilliseconds;
|
||||
}
|
||||
}
|
||||
|
||||
[Conditional("DEBUG")]
|
||||
private void DebugEndRecording()
|
||||
{
|
||||
if (_watch != null)
|
||||
{
|
||||
ProcessTime = _watch.ElapsedMilliseconds;
|
||||
_watch = null;
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
#region 排序接口实现
|
||||
|
||||
@@ -132,5 +132,27 @@ namespace YooAsset
|
||||
operation.SetPackageName(packageName);
|
||||
operation.StartOperation();
|
||||
}
|
||||
|
||||
#region 调试信息
|
||||
internal static List<DebugOperationInfo> GetDebugOperationInfos(string packageName)
|
||||
{
|
||||
List<DebugOperationInfo> result = new List<DebugOperationInfo>(_operations.Count);
|
||||
foreach (var operation in _operations)
|
||||
{
|
||||
if (operation.PackageName == packageName)
|
||||
{
|
||||
var operationInfo = new DebugOperationInfo();
|
||||
operationInfo.OperationName = operation.GetType().FullName;
|
||||
operationInfo.Priority = operation.Priority;
|
||||
operationInfo.Progress = operation.Progress;
|
||||
operationInfo.BeginTime = operation.BeginTime;
|
||||
operationInfo.ProcessTime = operation.ProcessTime;
|
||||
operationInfo.Status = operation.Status.ToString();
|
||||
result.Add(operationInfo);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -99,7 +99,6 @@ namespace YooAsset
|
||||
}
|
||||
internal override void InternalStart()
|
||||
{
|
||||
DebugBeginRecording();
|
||||
_steps = ESteps.StartBundleLoader;
|
||||
}
|
||||
internal override void InternalUpdate()
|
||||
@@ -267,8 +266,6 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
protected void InvokeCompletion(string error, EOperationStatus status)
|
||||
{
|
||||
DebugEndRecording();
|
||||
|
||||
_steps = ESteps.Done;
|
||||
Error = error;
|
||||
Status = status;
|
||||
@@ -311,50 +308,10 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public string SpawnScene = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 出生的时间
|
||||
/// </summary>
|
||||
public string SpawnTime = string.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// 加载耗时(单位:毫秒)
|
||||
/// </summary>
|
||||
public long LoadingTime { protected set; get; }
|
||||
|
||||
// 加载耗时统计
|
||||
private Stopwatch _watch = null;
|
||||
|
||||
[Conditional("DEBUG")]
|
||||
public void InitSpawnDebugInfo()
|
||||
public void InitProviderDebugInfo()
|
||||
{
|
||||
SpawnScene = UnityEngine.SceneManagement.SceneManager.GetActiveScene().name; ;
|
||||
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");
|
||||
}
|
||||
|
||||
[Conditional("DEBUG")]
|
||||
private void DebugBeginRecording()
|
||||
{
|
||||
if (_watch == null)
|
||||
{
|
||||
_watch = Stopwatch.StartNew();
|
||||
}
|
||||
}
|
||||
|
||||
[Conditional("DEBUG")]
|
||||
private void DebugEndRecording()
|
||||
{
|
||||
if (_watch != null)
|
||||
{
|
||||
LoadingTime = _watch.ElapsedMilliseconds;
|
||||
_watch = null;
|
||||
}
|
||||
SpawnScene = UnityEngine.SceneManagement.SceneManager.GetActiveScene().name;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -119,7 +119,7 @@ namespace YooAsset
|
||||
ProviderOperation provider;
|
||||
{
|
||||
provider = new SceneProvider(this, providerGUID, assetInfo, loadSceneParams, suspendLoad);
|
||||
provider.InitSpawnDebugInfo();
|
||||
provider.InitProviderDebugInfo();
|
||||
ProviderDic.Add(providerGUID, provider);
|
||||
OperationSystem.StartOperation(PackageName, provider);
|
||||
}
|
||||
@@ -158,7 +158,7 @@ namespace YooAsset
|
||||
if (provider == null)
|
||||
{
|
||||
provider = new AssetProvider(this, providerGUID, assetInfo);
|
||||
provider.InitSpawnDebugInfo();
|
||||
provider.InitProviderDebugInfo();
|
||||
ProviderDic.Add(providerGUID, provider);
|
||||
OperationSystem.StartOperation(PackageName, provider);
|
||||
}
|
||||
@@ -194,7 +194,7 @@ namespace YooAsset
|
||||
if (provider == null)
|
||||
{
|
||||
provider = new SubAssetsProvider(this, providerGUID, assetInfo);
|
||||
provider.InitSpawnDebugInfo();
|
||||
provider.InitProviderDebugInfo();
|
||||
ProviderDic.Add(providerGUID, provider);
|
||||
OperationSystem.StartOperation(PackageName, provider);
|
||||
}
|
||||
@@ -230,7 +230,7 @@ namespace YooAsset
|
||||
if (provider == null)
|
||||
{
|
||||
provider = new AllAssetsProvider(this, providerGUID, assetInfo);
|
||||
provider.InitSpawnDebugInfo();
|
||||
provider.InitProviderDebugInfo();
|
||||
ProviderDic.Add(providerGUID, provider);
|
||||
OperationSystem.StartOperation(PackageName, provider);
|
||||
}
|
||||
@@ -266,7 +266,7 @@ namespace YooAsset
|
||||
if (provider == null)
|
||||
{
|
||||
provider = new RawFileProvider(this, providerGUID, assetInfo);
|
||||
provider.InitSpawnDebugInfo();
|
||||
provider.InitProviderDebugInfo();
|
||||
ProviderDic.Add(providerGUID, provider);
|
||||
OperationSystem.StartOperation(PackageName, provider);
|
||||
}
|
||||
@@ -359,14 +359,6 @@ namespace YooAsset
|
||||
}
|
||||
|
||||
#region 调试信息
|
||||
internal DebugPackageData GetDebugPackageData()
|
||||
{
|
||||
DebugPackageData data = new DebugPackageData();
|
||||
data.PackageName = PackageName;
|
||||
data.ProviderInfos = GetDebugProviderInfos();
|
||||
data.BundleInfos = GetDebugBundleInfos();
|
||||
return data;
|
||||
}
|
||||
internal List<DebugProviderInfo> GetDebugProviderInfos()
|
||||
{
|
||||
List<DebugProviderInfo> result = new List<DebugProviderInfo>(ProviderDic.Count);
|
||||
@@ -375,8 +367,8 @@ namespace YooAsset
|
||||
DebugProviderInfo providerInfo = new DebugProviderInfo();
|
||||
providerInfo.AssetPath = provider.MainAssetInfo.AssetPath;
|
||||
providerInfo.SpawnScene = provider.SpawnScene;
|
||||
providerInfo.SpawnTime = provider.SpawnTime;
|
||||
providerInfo.LoadingTime = provider.LoadingTime;
|
||||
providerInfo.BeginTime = provider.BeginTime;
|
||||
providerInfo.LoadingTime = provider.ProcessTime;
|
||||
providerInfo.RefCount = provider.RefCount;
|
||||
providerInfo.Status = provider.Status.ToString();
|
||||
providerInfo.DependBundles = provider.GetDebugDependBundles();
|
||||
|
||||
@@ -1166,7 +1166,12 @@ namespace YooAsset
|
||||
#region 调试信息
|
||||
internal DebugPackageData GetDebugPackageData()
|
||||
{
|
||||
return _resourceManager.GetDebugPackageData();
|
||||
DebugPackageData data = new DebugPackageData();
|
||||
data.PackageName = PackageName;
|
||||
data.ProviderInfos = _resourceManager.GetDebugProviderInfos();
|
||||
data.BundleInfos = _resourceManager.GetDebugBundleInfos();
|
||||
data.OperationInfos = OperationSystem.GetDebugOperationInfos(PackageName);
|
||||
return data;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user