update asset system

优化资源对象加载耗时统计逻辑。
pull/82/head
hevinci 2023-03-01 18:23:47 +08:00
parent 4f0f0e54ac
commit 295238cbb6
5 changed files with 15 additions and 14 deletions

View File

@ -13,7 +13,7 @@ namespace YooAsset
} }
public override void Update() public override void Update()
{ {
DebugRecording(); DebugBeginRecording();
if (IsDone) if (IsDone)
return; return;

View File

@ -8,7 +8,7 @@ namespace YooAsset
} }
public override void Update() public override void Update()
{ {
DebugRecording(); DebugBeginRecording();
if (IsDone) if (IsDone)
return; return;

View File

@ -23,7 +23,7 @@ namespace YooAsset
} }
public override void Update() public override void Update()
{ {
DebugRecording(); DebugBeginRecording();
if (IsDone) if (IsDone)
return; return;

View File

@ -13,7 +13,7 @@ namespace YooAsset
} }
public override void Update() public override void Update()
{ {
DebugRecording(); DebugBeginRecording();
if (IsDone) if (IsDone)
return; return;

View File

@ -221,6 +221,8 @@ namespace YooAsset
private TaskCompletionSource<object> _taskCompletionSource; private TaskCompletionSource<object> _taskCompletionSource;
protected void InvokeCompletion() protected void InvokeCompletion()
{ {
DebugEndRecording();
// 进度百分百完成 // 进度百分百完成
Progress = 1f; Progress = 1f;
@ -256,8 +258,7 @@ namespace YooAsset
public long LoadingTime { protected set; get; } public long LoadingTime { protected set; get; }
// 加载耗时统计 // 加载耗时统计
private bool _isRecording = false; private Stopwatch _watch = null;
private Stopwatch _watch;
[Conditional("DEBUG")] [Conditional("DEBUG")]
public void InitSpawnDebugInfo() public void InitSpawnDebugInfo()
@ -274,23 +275,23 @@ namespace YooAsset
} }
[Conditional("DEBUG")] [Conditional("DEBUG")]
protected void DebugRecording() protected void DebugBeginRecording()
{ {
if (_isRecording == false) if (_watch == null)
{ {
_isRecording = true;
_watch = Stopwatch.StartNew(); _watch = Stopwatch.StartNew();
} }
}
if (_watch != null) [Conditional("DEBUG")]
private void DebugEndRecording()
{ {
if (IsDone) if (_watch != null)
{ {
LoadingTime = _watch.ElapsedMilliseconds; LoadingTime = _watch.ElapsedMilliseconds;
_watch = null; _watch = null;
} }
} }
}
#endregion #endregion
} }
} }