refactor : 重构异步操作模块

This commit is contained in:
何冠峰
2026-01-08 17:22:19 +08:00
parent 3dd3d4ef76
commit f375d45bd6
3 changed files with 25 additions and 23 deletions

View File

@@ -224,12 +224,12 @@ namespace YooAsset
InternalAbort();
Status = EOperationStatus.Failed;
Error = "user abort";
YooLogger.Warning($"Async operaiton {this.GetType().Name} has been abort !");
YooLogger.Warning($"Async operation {this.GetType().Name} has been aborted !");
}
}
/// <summary>
/// 结束异步任务
/// 强制结束异步任务
/// </summary>
internal void FinishOperation()
{
@@ -348,6 +348,25 @@ namespace YooAsset
float s = UnityEngine.Mathf.FloorToInt(spawnTime - m * 60f - h * 3600f);
return h.ToString("00") + ":" + m.ToString("00") + ":" + s.ToString("00");
}
internal DebugOperationInfo GetDebugOperationInfo()
{
var operationInfo = new DebugOperationInfo();
operationInfo.OperationName = this.GetType().Name;
operationInfo.OperationDesc = GetOperationDesc();
operationInfo.Priority = Priority;
operationInfo.Progress = Progress;
operationInfo.BeginTime = BeginTime;
operationInfo.ProcessTime = ProcessTime;
operationInfo.Status = Status.ToString();
operationInfo.Childs = new List<DebugOperationInfo>(Childs.Count);
foreach (var child in Childs)
{
var childInfo = child.GetDebugOperationInfo();
operationInfo.Childs.Add(childInfo);
}
return operationInfo;
}
#endregion
#region

View File

@@ -109,6 +109,7 @@ namespace YooAsset
foreach (var operation in _newList)
{
operation.AbortOperation();
operation.FinishOperation(); //注意强制收尾确保Task能完成
}
_newList.Clear();
@@ -116,6 +117,7 @@ namespace YooAsset
foreach (var operation in _operations)
{
operation.AbortOperation();
operation.FinishOperation(); //注意强制收尾确保Task能完成
}
_operations.Clear();
}
@@ -131,14 +133,14 @@ namespace YooAsset
// 包含正在执行的任务
foreach (var operation in _operations)
{
var operationInfo = OperationSystem.GetDebugOperationInfo(operation);
var operationInfo = operation.GetDebugOperationInfo();
result.Add(operationInfo);
}
// 包含待处理的新任务
foreach (var operation in _newList)
{
var operationInfo = OperationSystem.GetDebugOperationInfo(operation);
var operationInfo = operation.GetDebugOperationInfo();
result.Add(operationInfo);
}

View File

@@ -229,25 +229,6 @@ namespace YooAsset
return new List<DebugOperationInfo>();
}
internal static DebugOperationInfo GetDebugOperationInfo(AsyncOperationBase operation)
{
var operationInfo = new DebugOperationInfo();
operationInfo.OperationName = operation.GetType().Name;
operationInfo.OperationDesc = operation.GetOperationDesc();
operationInfo.Priority = operation.Priority;
operationInfo.Progress = operation.Progress;
operationInfo.BeginTime = operation.BeginTime;
operationInfo.ProcessTime = operation.ProcessTime;
operationInfo.Status = operation.Status.ToString();
operationInfo.Childs = new List<DebugOperationInfo>(operation.Childs.Count);
foreach (var child in operation.Childs)
{
var childInfo = GetDebugOperationInfo(child);
operationInfo.Childs.Add(childInfo);
}
return operationInfo;
}
#endregion
}
}