diff --git a/Assets/YooAsset/Runtime/OperationSystem/AsyncOperationBase.cs b/Assets/YooAsset/Runtime/OperationSystem/AsyncOperationBase.cs
index 9bef8795..debf5fa3 100644
--- a/Assets/YooAsset/Runtime/OperationSystem/AsyncOperationBase.cs
+++ b/Assets/YooAsset/Runtime/OperationSystem/AsyncOperationBase.cs
@@ -297,7 +297,7 @@ namespace YooAsset
try
{
- //TODO 单个回调异常会阻断后续回调
+ //TODO 单个回调异常会阻断后续订阅者
_callback?.Invoke(this);
}
catch (Exception ex)
@@ -350,6 +350,7 @@ namespace YooAsset
///
/// 无限次数的执行更新逻辑,直到任务完成
+ /// 注意:该方法会阻塞主线程
///
/// 休眠时长
protected void RunUntilCompletion(int sleepMS = 1)
@@ -482,6 +483,10 @@ namespace YooAsset
return false;
}
+ ///
+ /// 获取调试信息
+ /// 注意:递归构建子树存在深度风险
+ ///
internal DebugOperationInfo GetDebugOperationInfo()
{
var operationInfo = new DebugOperationInfo();
diff --git a/Assets/YooAsset/Runtime/OperationSystem/GameAsyncOperation.cs b/Assets/YooAsset/Runtime/OperationSystem/GameAsyncOperation.cs
deleted file mode 100644
index 806bbac9..00000000
--- a/Assets/YooAsset/Runtime/OperationSystem/GameAsyncOperation.cs
+++ /dev/null
@@ -1,25 +0,0 @@
-
-namespace YooAsset
-{
- public abstract class GameAsyncOperation : AsyncOperationBase
- {
- internal override void InternalStart()
- {
- OnStart();
- }
- internal override void InternalUpdate()
- {
- OnUpdate();
- }
-
- ///
- /// 异步操作开始
- ///
- protected abstract void OnStart();
-
- ///
- /// 异步操作更新
- ///
- protected abstract void OnUpdate();
- }
-}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/OperationSystem/OperationSystem.cs b/Assets/YooAsset/Runtime/OperationSystem/OperationSystem.cs
index ea2439da..e686ea35 100644
--- a/Assets/YooAsset/Runtime/OperationSystem/OperationSystem.cs
+++ b/Assets/YooAsset/Runtime/OperationSystem/OperationSystem.cs
@@ -26,11 +26,26 @@ namespace YooAsset
// 计时器相关
private static Stopwatch _watch;
private static long _frameTime;
+ private static long _maxTimeSlice = long.MaxValue;
///
/// 异步操作系统的每帧最大执行预算(毫秒)
///
- public static long MaxTimeSlice { set; get; } = long.MaxValue;
+ public static long MaxTimeSlice
+ {
+ set
+ {
+ if (value < 10)
+ {
+ _maxTimeSlice = 10;
+ YooLogger.Warning($"MaxTimeSlice minimum value is 10 milliseconds.");
+ }
+ else
+ {
+ _maxTimeSlice = value;
+ }
+ }
+ }
///
/// 异步操作系统是否繁忙
@@ -42,11 +57,11 @@ namespace YooAsset
if (_watch == null)
return false;
- if (MaxTimeSlice == long.MaxValue)
+ if (_maxTimeSlice == long.MaxValue)
return false;
// 注意 : 单次调用开销约1微秒
- return _watch.ElapsedMilliseconds - _frameTime >= MaxTimeSlice;
+ return _watch.ElapsedMilliseconds - _frameTime >= _maxTimeSlice;
}
}
diff --git a/Assets/YooAsset/Runtime/YooAssets.cs b/Assets/YooAsset/Runtime/YooAssets.cs
index eee3a65d..c4203c22 100644
--- a/Assets/YooAsset/Runtime/YooAssets.cs
+++ b/Assets/YooAsset/Runtime/YooAssets.cs
@@ -207,17 +207,6 @@ namespace YooAsset
return package != null;
}
- ///
- /// 开启一个异步操作
- ///
- /// 异步操作对象
- public static void StartOperation(GameAsyncOperation operation)
- {
- // 注意:游戏业务逻辑的包裹填写为空
- OperationSystem.StartOperation(OperationSystem.GLOBAL_SCHEDULER_NAME, operation);
- }
-
-
private static ResourcePackage GetPackageInternal(string packageName)
{
foreach (var package in _packages)
@@ -259,11 +248,6 @@ namespace YooAsset
///
public static void SetOperationSystemMaxTimeSlice(long milliseconds)
{
- if (milliseconds < 10)
- {
- milliseconds = 10;
- YooLogger.Warning($"MaxTimeSlice minimum value is 10 milliseconds.");
- }
OperationSystem.MaxTimeSlice = milliseconds;
}
#endregion
diff --git a/Assets/YooAsset/Samples~/Extension Sample/Runtime/ExtensionOperation/CopyBuildinManifestOperation.cs b/Assets/YooAsset/Samples~/Extension Sample/Runtime/ExtensionOperation/CopyBuildinManifestOperation.cs
index 4ad500a0..2d0d688c 100644
--- a/Assets/YooAsset/Samples~/Extension Sample/Runtime/ExtensionOperation/CopyBuildinManifestOperation.cs
+++ b/Assets/YooAsset/Samples~/Extension Sample/Runtime/ExtensionOperation/CopyBuildinManifestOperation.cs
@@ -7,7 +7,7 @@ using YooAsset;
///
/// 拷贝内置清单文件到沙盒目录
///
-public class CopyBuildinManifestOperation : GameAsyncOperation
+public class CopyBuildinManifestOperation : AsyncOperationBase
{
private enum ESteps
{
@@ -32,11 +32,11 @@ public class CopyBuildinManifestOperation : GameAsyncOperation
_packageVersion = packageVersion;
_backend = new UnityWebRequestBackend();
}
- protected override void OnStart()
+ internal override void InternalStart()
{
_steps = ESteps.CheckHashFile;
}
- protected override void OnUpdate()
+ internal override void InternalUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
@@ -121,9 +121,6 @@ public class CopyBuildinManifestOperation : GameAsyncOperation
}
}
}
- protected override void OnAbort()
- {
- }
private string GetBuildinYooRoot()
{
diff --git a/Assets/YooAsset/Samples~/Extension Sample/Runtime/ExtensionOperation/GetBuildinPackageVersionOperation.cs b/Assets/YooAsset/Samples~/Extension Sample/Runtime/ExtensionOperation/GetBuildinPackageVersionOperation.cs
index 6217dca9..f7a1109d 100644
--- a/Assets/YooAsset/Samples~/Extension Sample/Runtime/ExtensionOperation/GetBuildinPackageVersionOperation.cs
+++ b/Assets/YooAsset/Samples~/Extension Sample/Runtime/ExtensionOperation/GetBuildinPackageVersionOperation.cs
@@ -7,7 +7,7 @@ using YooAsset;
///
/// 获取包体里的内置资源清单版本
///
-public class GetBuildinPackageVersionOperation : GameAsyncOperation
+public class GetBuildinPackageVersionOperation : AsyncOperationBase
{
private enum ESteps
{
@@ -31,11 +31,11 @@ public class GetBuildinPackageVersionOperation : GameAsyncOperation
_packageName = packageName;
_backend = new UnityWebRequestBackend();
}
- protected override void OnStart()
+ internal override void InternalStart()
{
_steps = ESteps.GetPackageVersion;
}
- protected override void OnUpdate()
+ internal override void InternalUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
@@ -68,9 +68,6 @@ public class GetBuildinPackageVersionOperation : GameAsyncOperation
}
}
}
- protected override void OnAbort()
- {
- }
private string GetBuildinYooRoot()
{
diff --git a/Assets/YooAsset/Samples~/Extension Sample/Runtime/ExtensionOperation/GetCacheBundleSizeOperation.cs b/Assets/YooAsset/Samples~/Extension Sample/Runtime/ExtensionOperation/GetCacheBundleSizeOperation.cs
index 6eb9b501..5459a32a 100644
--- a/Assets/YooAsset/Samples~/Extension Sample/Runtime/ExtensionOperation/GetCacheBundleSizeOperation.cs
+++ b/Assets/YooAsset/Samples~/Extension Sample/Runtime/ExtensionOperation/GetCacheBundleSizeOperation.cs
@@ -7,7 +7,7 @@ using YooAsset;
///
/// 获取沙盒目录里缓存文件大小
///
-public class GetCacheBundleSizeOperation : GameAsyncOperation
+public class GetCacheBundleSizeOperation : AsyncOperationBase
{
private enum ESteps
{
@@ -29,11 +29,11 @@ public class GetCacheBundleSizeOperation : GameAsyncOperation
{
_packageName = packageName;
}
- protected override void OnStart()
+ internal override void InternalStart()
{
_steps = ESteps.GetCacheFiles;
}
- protected override void OnUpdate()
+ internal override void InternalUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
@@ -57,9 +57,6 @@ public class GetCacheBundleSizeOperation : GameAsyncOperation
Status = EOperationStatus.Succeed;
}
}
- protected override void OnAbort()
- {
- }
private string GetCacheDirectoryRoot()
{
diff --git a/Assets/YooAsset/Samples~/Extension Sample/Runtime/ExtensionOperation/LoadAssetsByTagOperation.cs b/Assets/YooAsset/Samples~/Extension Sample/Runtime/ExtensionOperation/LoadAssetsByTagOperation.cs
index 2e275c08..46931c1b 100644
--- a/Assets/YooAsset/Samples~/Extension Sample/Runtime/ExtensionOperation/LoadAssetsByTagOperation.cs
+++ b/Assets/YooAsset/Samples~/Extension Sample/Runtime/ExtensionOperation/LoadAssetsByTagOperation.cs
@@ -4,7 +4,7 @@ using System.Collections.Generic;
using UnityEngine;
using YooAsset;
-public class LoadAssetsByTagOperation : GameAsyncOperation where TObject : UnityEngine.Object
+public class LoadAssetsByTagOperation : AsyncOperationBase where TObject : UnityEngine.Object
{
private enum ESteps
{
@@ -28,11 +28,11 @@ public class LoadAssetsByTagOperation : GameAsyncOperation where TObjec
{
_tag = tag;
}
- protected override void OnStart()
+ internal override void InternalStart()
{
_steps = ESteps.LoadAssets;
}
- protected override void OnUpdate()
+ internal override void InternalUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
@@ -53,7 +53,7 @@ public class LoadAssetsByTagOperation : GameAsyncOperation where TObjec
{
int index = 0;
foreach (var handle in _handles)
- {
+ {
if (handle.IsDone == false)
{
Progress = (float)index / _handles.Count;
@@ -77,7 +77,7 @@ public class LoadAssetsByTagOperation : GameAsyncOperation where TObjec
string error = $"资源类型转换失败:{handle.AssetObject.name}";
Debug.LogError($"{error}");
AssetObjects.Clear();
- SetFinish(false, error);
+ SetFailed(error);
return;
}
}
@@ -85,21 +85,23 @@ public class LoadAssetsByTagOperation : GameAsyncOperation where TObjec
{
Debug.LogError($"{handle.LastError}");
AssetObjects.Clear();
- SetFinish(false, handle.LastError);
+ SetFailed(handle.LastError);
return;
}
}
- SetFinish(true);
+ SetSucceed();
}
}
- protected override void OnAbort()
+ private void SetSucceed()
{
+ Status = EOperationStatus.Succeed;
+ _steps = ESteps.Done;
}
- private void SetFinish(bool succeed, string error = "")
+ private void SetFailed(string error)
{
Error = error;
- Status = succeed ? EOperationStatus.Succeed : EOperationStatus.Failed;
+ Status = EOperationStatus.Failed;
_steps = ESteps.Done;
}
diff --git a/Assets/YooAsset/Samples~/Extension Sample/Runtime/ExtensionOperation/LoadGameObjectOperation.cs b/Assets/YooAsset/Samples~/Extension Sample/Runtime/ExtensionOperation/LoadGameObjectOperation.cs
index fa4ef821..08719f12 100644
--- a/Assets/YooAsset/Samples~/Extension Sample/Runtime/ExtensionOperation/LoadGameObjectOperation.cs
+++ b/Assets/YooAsset/Samples~/Extension Sample/Runtime/ExtensionOperation/LoadGameObjectOperation.cs
@@ -9,12 +9,12 @@ public static class YooAssetsExtension
public static LoadGameObjectOperation LoadGameObjectAsync(this ResourcePackage resourcePackage, string location, Vector3 position, Quaternion rotation, Transform parent, bool destroyGoOnRelease = false)
{
var operation = new LoadGameObjectOperation(location, position, rotation, parent, destroyGoOnRelease);
- YooAssets.StartOperation(operation);
+ OperationSystem.StartOperation(OperationSystem.GLOBAL_SCHEDULER_NAME, operation);
return operation;
}
}
-public class LoadGameObjectOperation : GameAsyncOperation
+public class LoadGameObjectOperation : AsyncOperationBase
{
private enum ESteps
{
@@ -36,7 +36,7 @@ public class LoadGameObjectOperation : GameAsyncOperation
///
public GameObject Go { private set; get; }
-
+
public LoadGameObjectOperation(string location, Vector3 position, Quaternion rotation, Transform parent, bool destroyGoOnRelease = false)
{
_location = location;
@@ -45,11 +45,11 @@ public class LoadGameObjectOperation : GameAsyncOperation
_parent = parent;
_destroyGoOnRelease = destroyGoOnRelease;
}
- protected override void OnStart()
+ internal override void InternalStart()
{
_steps = ESteps.LoadAsset;
}
- protected override void OnUpdate()
+ internal override void InternalUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
@@ -79,9 +79,6 @@ public class LoadGameObjectOperation : GameAsyncOperation
}
}
}
- protected override void OnAbort()
- {
- }
///
/// 释放资源句柄
diff --git a/Assets/YooAsset/Samples~/Extension Sample/Runtime/ExtensionOperation/OperationHelper.cs b/Assets/YooAsset/Samples~/Extension Sample/Runtime/ExtensionOperation/OperationHelper.cs
new file mode 100644
index 00000000..36b77b13
--- /dev/null
+++ b/Assets/YooAsset/Samples~/Extension Sample/Runtime/ExtensionOperation/OperationHelper.cs
@@ -0,0 +1,16 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using System.IO;
+using YooAsset;
+
+public class OperationHelper
+{
+ ///
+ /// 开始一个业务实现的自定义异步任务
+ ///
+ public static void StartOperation(AsyncOperationBase operation)
+ {
+ OperationSystem.StartOperation(OperationSystem.GLOBAL_SCHEDULER_NAME, operation);
+ }
+}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/OperationSystem/GameAsyncOperation.cs.meta b/Assets/YooAsset/Samples~/Extension Sample/Runtime/ExtensionOperation/OperationHelper.cs.meta
similarity index 83%
rename from Assets/YooAsset/Runtime/OperationSystem/GameAsyncOperation.cs.meta
rename to Assets/YooAsset/Samples~/Extension Sample/Runtime/ExtensionOperation/OperationHelper.cs.meta
index 90cbe4b2..98379f7f 100644
--- a/Assets/YooAsset/Runtime/OperationSystem/GameAsyncOperation.cs.meta
+++ b/Assets/YooAsset/Samples~/Extension Sample/Runtime/ExtensionOperation/OperationHelper.cs.meta
@@ -1,5 +1,5 @@
fileFormatVersion: 2
-guid: ff8a96dd005f55346986f8a98aff8c99
+guid: fd52bc7cb896369498d42a12081816ee
MonoImporter:
externalObjects: {}
serializedVersion: 2
diff --git a/Assets/YooAsset/Samples~/Extension Sample/Runtime/OperationMonitor/OperationMonitor.cs b/Assets/YooAsset/Samples~/Extension Sample/Runtime/OperationMonitor/OperationMonitor.cs
index bda79d71..049ebd70 100644
--- a/Assets/YooAsset/Samples~/Extension Sample/Runtime/OperationMonitor/OperationMonitor.cs
+++ b/Assets/YooAsset/Samples~/Extension Sample/Runtime/OperationMonitor/OperationMonitor.cs
@@ -6,8 +6,6 @@ public static class OperationMonitor
{
public static void RegisterOperationCallback()
{
- OperationSystem.RegisterStartCallback(OperationStartCallback);
- OperationSystem.RegisterFinishCallback(OperationFinishCallback);
}
private static void OperationStartCallback(string packageName, AsyncOperationBase operation)