diff --git a/Assets/YooAsset/Editor/AssetBundleDebugger/VisualViewers/DebuggerAssetListViewer.cs b/Assets/YooAsset/Editor/AssetBundleDebugger/VisualViewers/DebuggerAssetListViewer.cs
index edc150b..b509fd2 100644
--- a/Assets/YooAsset/Editor/AssetBundleDebugger/VisualViewers/DebuggerAssetListViewer.cs
+++ b/Assets/YooAsset/Editor/AssetBundleDebugger/VisualViewers/DebuggerAssetListViewer.cs
@@ -224,7 +224,7 @@ namespace YooAsset.Editor
// Status
StyleColor textColor;
- if (providerInfo.Status == ProviderBase.EStatus.Failed.ToString())
+ if (providerInfo.Status == EOperationStatus.Failed.ToString())
textColor = new StyleColor(Color.yellow);
else
textColor = label1.style.color;
diff --git a/Assets/YooAsset/Runtime/InitializeParameters.cs b/Assets/YooAsset/Runtime/InitializeParameters.cs
index a13d556..fb2cbce 100644
--- a/Assets/YooAsset/Runtime/InitializeParameters.cs
+++ b/Assets/YooAsset/Runtime/InitializeParameters.cs
@@ -80,12 +80,6 @@ namespace YooAsset
///
public bool AutoDestroyAssetProvider = false;
- ///
- /// 资源加载每帧处理的最大时间片段
- /// 注意:默认值为MaxValue
- ///
- public long LoadingMaxTimeSlice = long.MaxValue;
-
///
/// 启用断点续传参数
/// 说明:当文件的大小大于设置的字节数时启用断点续传下载器
diff --git a/Assets/YooAsset/Runtime/OperationSystem/AsyncOperationBase.cs b/Assets/YooAsset/Runtime/OperationSystem/AsyncOperationBase.cs
index f0f8fee..b09522d 100644
--- a/Assets/YooAsset/Runtime/OperationSystem/AsyncOperationBase.cs
+++ b/Assets/YooAsset/Runtime/OperationSystem/AsyncOperationBase.cs
@@ -5,16 +5,24 @@ using System.Threading.Tasks;
namespace YooAsset
{
- public abstract class AsyncOperationBase : IEnumerator
+ public abstract class AsyncOperationBase : IEnumerator, IComparable
{
// 用户请求的回调
private Action _callback;
+ // 是否已经完成
+ internal bool IsFinish = false;
+
///
/// 所属包裹
///
public string PackageName { private set; get; }
+ ///
+ /// 优先级
+ ///
+ public uint Priority { set; get; } = 0;
+
///
/// 状态
///
@@ -80,7 +88,7 @@ namespace YooAsset
internal abstract void InternalOnUpdate();
internal virtual void InternalOnAbort() { }
- internal void SetPackageName(string packageName)
+ internal void Init(string packageName)
{
PackageName = packageName;
}
@@ -91,8 +99,14 @@ namespace YooAsset
}
internal void SetFinish()
{
+ IsFinish = true;
+
+ // 进度百分百完成
Progress = 1f;
- _callback?.Invoke(this); //注意:如果完成回调内发生异常,会导致Task无限期等待
+
+ //注意:如果完成回调内发生异常,会导致Task无限期等待
+ _callback?.Invoke(this);
+
if (_taskCompletionSource != null)
_taskCompletionSource.TrySetResult(null);
}
@@ -115,6 +129,13 @@ namespace YooAsset
_callback = null;
}
+ #region 排序接口实现
+ public int CompareTo(AsyncOperationBase other)
+ {
+ return other.Priority.CompareTo(this.Priority);
+ }
+ #endregion
+
#region 异步编程相关
bool IEnumerator.MoveNext()
{
diff --git a/Assets/YooAsset/Runtime/OperationSystem/OperationSystem.cs b/Assets/YooAsset/Runtime/OperationSystem/OperationSystem.cs
index 3a3df1f..1638b9b 100644
--- a/Assets/YooAsset/Runtime/OperationSystem/OperationSystem.cs
+++ b/Assets/YooAsset/Runtime/OperationSystem/OperationSystem.cs
@@ -45,29 +45,50 @@ namespace YooAsset
{
_frameTime = _watch.ElapsedMilliseconds;
- // 添加新的异步操作
+ // 添加新增的异步操作
if (_newList.Count > 0)
{
+ bool sorting = false;
+ foreach (var operation in _newList)
+ {
+ if (operation.Priority > 0)
+ {
+ sorting = true;
+ break;
+ }
+ }
+
_operations.AddRange(_newList);
_newList.Clear();
+
+ // 重新排序优先级
+ if (sorting)
+ _operations.Sort();
}
- // 更新所有的异步操作
- for (int i = _operations.Count - 1; i >= 0; i--)
+ // 更新进行中的异步操作
+ for (int i = 0; i < _operations.Count; i++)
{
if (IsBusy)
break;
var operation = _operations[i];
+ if (operation.IsFinish)
+ continue;
+
if (operation.IsDone == false)
operation.InternalOnUpdate();
if (operation.IsDone)
- {
- // 注意:如果业务端发生异常,保证异步操作提前移除。
- _operations.RemoveAt(i);
operation.SetFinish();
- }
+ }
+
+ // 移除已经完成的异步操作
+ for (int i = _operations.Count - 1; i >= 0; i--)
+ {
+ var operation = _operations[i];
+ if (operation.IsFinish)
+ _operations.RemoveAt(i);
}
}
@@ -113,7 +134,7 @@ namespace YooAsset
public static void StartOperation(string packageName, AsyncOperationBase operation)
{
_newList.Add(operation);
- operation.SetPackageName(packageName);
+ operation.Init(packageName);
operation.SetStart();
}
}
diff --git a/Assets/YooAsset/Runtime/ResourceManager/Handle/HandleBase.cs b/Assets/YooAsset/Runtime/ResourceManager/Handle/HandleBase.cs
index 1c1233c..f78b0d8 100644
--- a/Assets/YooAsset/Runtime/ResourceManager/Handle/HandleBase.cs
+++ b/Assets/YooAsset/Runtime/ResourceManager/Handle/HandleBase.cs
@@ -45,15 +45,7 @@ namespace YooAsset
if (IsValidWithWarning == false)
return EOperationStatus.None;
- var status = Provider.Status;
- if (status == ProviderBase.EStatus.None)
- return EOperationStatus.None;
- else if (status == ProviderBase.EStatus.Succeed)
- return EOperationStatus.Succeed;
- else if (status == ProviderBase.EStatus.Failed)
- return EOperationStatus.Failed;
- else
- return EOperationStatus.Processing;
+ return Provider.Status;
}
}
@@ -66,7 +58,7 @@ namespace YooAsset
{
if (IsValidWithWarning == false)
return string.Empty;
- return Provider.LastError;
+ return Provider.Error;
}
}
diff --git a/Assets/YooAsset/Runtime/ResourceManager/Loader/BundleLoaderBase.cs b/Assets/YooAsset/Runtime/ResourceManager/Loader/BundleLoaderBase.cs
index 5ba111b..35a1c6d 100644
--- a/Assets/YooAsset/Runtime/ResourceManager/Loader/BundleLoaderBase.cs
+++ b/Assets/YooAsset/Runtime/ResourceManager/Loader/BundleLoaderBase.cs
@@ -110,12 +110,6 @@ namespace YooAsset
///
public void TryDestroyProviders()
{
- // TODO 不用等待资源包加载完成
- /*
- if (IsDone() == false)
- return;
- */
-
// 获取移除列表
_removeList.Clear();
foreach (var provider in _providers)
diff --git a/Assets/YooAsset/Runtime/ResourceManager/Provider/BundledAllAssetsProvider.cs b/Assets/YooAsset/Runtime/ResourceManager/Provider/BundledAllAssetsProvider.cs
index 6491bed..82bd6a1 100644
--- a/Assets/YooAsset/Runtime/ResourceManager/Provider/BundledAllAssetsProvider.cs
+++ b/Assets/YooAsset/Runtime/ResourceManager/Provider/BundledAllAssetsProvider.cs
@@ -7,24 +7,26 @@ namespace YooAsset
internal sealed class BundledAllAssetsProvider : ProviderBase
{
private AssetBundleRequest _cacheRequest;
-
- public BundledAllAssetsProvider(ResourceManager manager, string providerGUID, uint providerPriority, AssetInfo assetInfo) : base(manager, providerGUID, providerPriority, assetInfo)
+
+ public BundledAllAssetsProvider(ResourceManager manager, string providerGUID, AssetInfo assetInfo) : base(manager, providerGUID, assetInfo)
{
}
- public override void Update()
+ internal override void InternalOnStart()
{
DebugBeginRecording();
-
+ }
+ internal override void InternalOnUpdate()
+ {
if (IsDone)
return;
- if (Status == EStatus.None)
+ if (_steps == ESteps.None)
{
- Status = EStatus.CheckBundle;
+ _steps = ESteps.CheckBundle;
}
// 1. 检测资源包
- if (Status == EStatus.CheckBundle)
+ if (_steps == ESteps.CheckBundle)
{
if (IsWaitForAsyncComplete)
{
@@ -39,17 +41,15 @@ namespace YooAsset
if (DependBundles.IsSucceed() == false)
{
- Status = EStatus.Failed;
- LastError = DependBundles.GetLastError();
- InvokeCompletion();
+ string error = DependBundles.GetLastError();
+ InvokeCompletion(error, EOperationStatus.Failed);
return;
}
if (OwnerBundle.Status != BundleLoaderBase.EStatus.Succeed)
{
- Status = EStatus.Failed;
- LastError = OwnerBundle.LastError;
- InvokeCompletion();
+ string error = OwnerBundle.LastError;
+ InvokeCompletion(error, EOperationStatus.Failed);
return;
}
@@ -59,11 +59,11 @@ namespace YooAsset
return;
}
- Status = EStatus.Loading;
+ _steps = ESteps.Loading;
}
// 2. 加载资源对象
- if (Status == EStatus.Loading)
+ if (_steps == ESteps.Loading)
{
if (IsWaitForAsyncComplete || IsForceDestroyComplete)
{
@@ -79,11 +79,11 @@ namespace YooAsset
else
_cacheRequest = OwnerBundle.CacheBundle.LoadAllAssetsAsync(MainAssetInfo.AssetType);
}
- Status = EStatus.Checking;
+ _steps = ESteps.Checking;
}
// 3. 检测加载结果
- if (Status == EStatus.Checking)
+ if (_steps == ESteps.Checking)
{
if (_cacheRequest != null)
{
@@ -102,16 +102,20 @@ namespace YooAsset
}
}
- Status = AllAssetObjects == null ? EStatus.Failed : EStatus.Succeed;
- if (Status == EStatus.Failed)
+ if (AllAssetObjects == null)
{
+ string error;
if (MainAssetInfo.AssetType == null)
- LastError = $"Failed to load all assets : {MainAssetInfo.AssetPath} AssetType : null AssetBundle : {OwnerBundle.MainBundleInfo.Bundle.BundleName}";
+ error = $"Failed to load all assets : {MainAssetInfo.AssetPath} AssetType : null AssetBundle : {OwnerBundle.MainBundleInfo.Bundle.BundleName}";
else
- LastError = $"Failed to load all assets : {MainAssetInfo.AssetPath} AssetType : {MainAssetInfo.AssetType} AssetBundle : {OwnerBundle.MainBundleInfo.Bundle.BundleName}";
- YooLogger.Error(LastError);
+ error = $"Failed to load all assets : {MainAssetInfo.AssetPath} AssetType : {MainAssetInfo.AssetType} AssetBundle : {OwnerBundle.MainBundleInfo.Bundle.BundleName}";
+ YooLogger.Error(error);
+ InvokeCompletion(error, EOperationStatus.Failed);
+ }
+ else
+ {
+ InvokeCompletion(string.Empty, EOperationStatus.Succeed);
}
- InvokeCompletion();
}
}
}
diff --git a/Assets/YooAsset/Runtime/ResourceManager/Provider/BundledAssetProvider.cs b/Assets/YooAsset/Runtime/ResourceManager/Provider/BundledAssetProvider.cs
index 25be93d..72dc1ab 100644
--- a/Assets/YooAsset/Runtime/ResourceManager/Provider/BundledAssetProvider.cs
+++ b/Assets/YooAsset/Runtime/ResourceManager/Provider/BundledAssetProvider.cs
@@ -8,23 +8,25 @@ namespace YooAsset
{
private AssetBundleRequest _cacheRequest;
- public BundledAssetProvider(ResourceManager manager, string providerGUID, uint providerPriority, AssetInfo assetInfo) : base(manager, providerGUID, providerPriority, assetInfo)
+ public BundledAssetProvider(ResourceManager manager, string providerGUID, AssetInfo assetInfo) : base(manager, providerGUID, assetInfo)
{
}
- public override void Update()
+ internal override void InternalOnStart()
{
DebugBeginRecording();
-
+ }
+ internal override void InternalOnUpdate()
+ {
if (IsDone)
return;
- if (Status == EStatus.None)
+ if (_steps == ESteps.None)
{
- Status = EStatus.CheckBundle;
+ _steps = ESteps.CheckBundle;
}
// 1. 检测资源包
- if (Status == EStatus.CheckBundle)
+ if (_steps == ESteps.CheckBundle)
{
if (IsWaitForAsyncComplete)
{
@@ -39,17 +41,15 @@ namespace YooAsset
if (DependBundles.IsSucceed() == false)
{
- Status = EStatus.Failed;
- LastError = DependBundles.GetLastError();
- InvokeCompletion();
+ string error = DependBundles.GetLastError();
+ InvokeCompletion(error, EOperationStatus.Failed);
return;
}
if (OwnerBundle.Status != BundleLoaderBase.EStatus.Succeed)
{
- Status = EStatus.Failed;
- LastError = OwnerBundle.LastError;
- InvokeCompletion();
+ string error = OwnerBundle.LastError;
+ InvokeCompletion(error, EOperationStatus.Failed);
return;
}
@@ -59,11 +59,11 @@ namespace YooAsset
return;
}
- Status = EStatus.Loading;
+ _steps = ESteps.Loading;
}
// 2. 加载资源对象
- if (Status == EStatus.Loading)
+ if (_steps == ESteps.Loading)
{
if (IsWaitForAsyncComplete || IsForceDestroyComplete)
{
@@ -79,11 +79,11 @@ namespace YooAsset
else
_cacheRequest = OwnerBundle.CacheBundle.LoadAssetAsync(MainAssetInfo.AssetPath, MainAssetInfo.AssetType);
}
- Status = EStatus.Checking;
+ _steps = ESteps.Checking;
}
// 3. 检测加载结果
- if (Status == EStatus.Checking)
+ if (_steps == ESteps.Checking)
{
if (_cacheRequest != null)
{
@@ -102,16 +102,20 @@ namespace YooAsset
}
}
- Status = AssetObject == null ? EStatus.Failed : EStatus.Succeed;
- if (Status == EStatus.Failed)
+ if (AssetObject == null)
{
+ string error;
if (MainAssetInfo.AssetType == null)
- LastError = $"Failed to load asset : {MainAssetInfo.AssetPath} AssetType : null AssetBundle : {OwnerBundle.MainBundleInfo.Bundle.BundleName}";
+ error = $"Failed to load asset : {MainAssetInfo.AssetPath} AssetType : null AssetBundle : {OwnerBundle.MainBundleInfo.Bundle.BundleName}";
else
- LastError = $"Failed to load asset : {MainAssetInfo.AssetPath} AssetType : {MainAssetInfo.AssetType} AssetBundle : {OwnerBundle.MainBundleInfo.Bundle.BundleName}";
- YooLogger.Error(LastError);
+ error = $"Failed to load asset : {MainAssetInfo.AssetPath} AssetType : {MainAssetInfo.AssetType} AssetBundle : {OwnerBundle.MainBundleInfo.Bundle.BundleName}";
+ YooLogger.Error(error);
+ InvokeCompletion(error, EOperationStatus.Failed);
+ }
+ else
+ {
+ InvokeCompletion(string.Empty, EOperationStatus.Succeed);
}
- InvokeCompletion();
}
}
}
diff --git a/Assets/YooAsset/Runtime/ResourceManager/Provider/BundledRawFileProvider.cs b/Assets/YooAsset/Runtime/ResourceManager/Provider/BundledRawFileProvider.cs
index 90d1f35..dfd0042 100644
--- a/Assets/YooAsset/Runtime/ResourceManager/Provider/BundledRawFileProvider.cs
+++ b/Assets/YooAsset/Runtime/ResourceManager/Provider/BundledRawFileProvider.cs
@@ -3,23 +3,25 @@ namespace YooAsset
{
internal class BundledRawFileProvider : ProviderBase
{
- public BundledRawFileProvider(ResourceManager manager, string providerGUID, uint providerPriority, AssetInfo assetInfo) : base(manager, providerGUID, providerPriority, assetInfo)
+ public BundledRawFileProvider(ResourceManager manager, string providerGUID, AssetInfo assetInfo) : base(manager, providerGUID, assetInfo)
{
}
- public override void Update()
+ internal override void InternalOnStart()
{
DebugBeginRecording();
-
+ }
+ internal override void InternalOnUpdate()
+ {
if (IsDone)
return;
- if (Status == EStatus.None)
+ if (_steps == ESteps.None)
{
- Status = EStatus.CheckBundle;
+ _steps = ESteps.CheckBundle;
}
// 1. 检测资源包
- if (Status == EStatus.CheckBundle)
+ if (_steps == ESteps.CheckBundle)
{
if (IsWaitForAsyncComplete)
{
@@ -31,21 +33,19 @@ namespace YooAsset
if (OwnerBundle.Status != BundleLoaderBase.EStatus.Succeed)
{
- Status = EStatus.Failed;
- LastError = OwnerBundle.LastError;
- InvokeCompletion();
+ string error = OwnerBundle.LastError;
+ InvokeCompletion(error, EOperationStatus.Failed);
return;
}
- Status = EStatus.Checking;
+ _steps = ESteps.Checking;
}
// 2. 检测加载结果
- if (Status == EStatus.Checking)
+ if (_steps == ESteps.Checking)
{
RawFilePath = OwnerBundle.FileLoadPath;
- Status = EStatus.Succeed;
- InvokeCompletion();
+ InvokeCompletion(string.Empty, EOperationStatus.Succeed);
}
}
}
diff --git a/Assets/YooAsset/Runtime/ResourceManager/Provider/BundledSceneProvider.cs b/Assets/YooAsset/Runtime/ResourceManager/Provider/BundledSceneProvider.cs
index 4c2e67c..0e313dc 100644
--- a/Assets/YooAsset/Runtime/ResourceManager/Provider/BundledSceneProvider.cs
+++ b/Assets/YooAsset/Runtime/ResourceManager/Provider/BundledSceneProvider.cs
@@ -12,26 +12,28 @@ namespace YooAsset
private readonly bool _suspendLoad;
private AsyncOperation _asyncOperation;
- public BundledSceneProvider(ResourceManager manager, string providerGUID, uint providerPriority, AssetInfo assetInfo, LoadSceneMode sceneMode, bool suspendLoad) : base(manager, providerGUID, providerPriority, assetInfo)
+ public BundledSceneProvider(ResourceManager manager, string providerGUID, AssetInfo assetInfo, LoadSceneMode sceneMode, bool suspendLoad) : base(manager, providerGUID, assetInfo)
{
SceneMode = sceneMode;
SceneName = Path.GetFileNameWithoutExtension(assetInfo.AssetPath);
_suspendLoad = suspendLoad;
}
- public override void Update()
+ internal override void InternalOnStart()
{
DebugBeginRecording();
-
+ }
+ internal override void InternalOnUpdate()
+ {
if (IsDone)
return;
- if (Status == EStatus.None)
+ if (_steps == ESteps.None)
{
- Status = EStatus.CheckBundle;
+ _steps = ESteps.CheckBundle;
}
// 1. 检测资源包
- if (Status == EStatus.CheckBundle)
+ if (_steps == ESteps.CheckBundle)
{
if (DependBundles.IsDone() == false)
return;
@@ -40,57 +42,57 @@ namespace YooAsset
if (DependBundles.IsSucceed() == false)
{
- Status = EStatus.Failed;
- LastError = DependBundles.GetLastError();
- InvokeCompletion();
+ string error = DependBundles.GetLastError();
+ InvokeCompletion(error, EOperationStatus.Failed);
return;
}
if (OwnerBundle.Status != BundleLoaderBase.EStatus.Succeed)
{
- Status = EStatus.Failed;
- LastError = OwnerBundle.LastError;
- InvokeCompletion();
+ string error = OwnerBundle.LastError;
+ InvokeCompletion(error, EOperationStatus.Failed);
return;
}
- Status = EStatus.Loading;
+ _steps = ESteps.Loading;
}
// 2. 加载场景
- if (Status == EStatus.Loading)
+ if (_steps == ESteps.Loading)
{
// 注意:如果场景不存在则返回NULL
_asyncOperation = SceneManager.LoadSceneAsync(MainAssetInfo.AssetPath, SceneMode);
if (_asyncOperation != null)
{
_asyncOperation.allowSceneActivation = !_suspendLoad;
- _asyncOperation.priority = (int)ProviderPriority;
+ _asyncOperation.priority = 100;
SceneObject = SceneManager.GetSceneAt(SceneManager.sceneCount - 1);
- Status = EStatus.Checking;
+ _steps = ESteps.Checking;
}
else
{
- Status = EStatus.Failed;
- LastError = $"Failed to load scene : {MainAssetInfo.AssetPath}";
- YooLogger.Error(LastError);
- InvokeCompletion();
+ string error = $"Failed to load scene : {MainAssetInfo.AssetPath}";
+ YooLogger.Error(error);
+ InvokeCompletion(error, EOperationStatus.Failed);
}
}
// 3. 检测加载结果
- if (Status == EStatus.Checking)
+ if (_steps == ESteps.Checking)
{
Progress = _asyncOperation.progress;
if (_asyncOperation.isDone)
{
- Status = SceneObject.IsValid() ? EStatus.Succeed : EStatus.Failed;
- if (Status == EStatus.Failed)
+ if (SceneObject.IsValid())
{
- LastError = $"The load scene is invalid : {MainAssetInfo.AssetPath}";
- YooLogger.Error(LastError);
+ InvokeCompletion(string.Empty, EOperationStatus.Succeed);
+ }
+ else
+ {
+ string error = $"The load scene is invalid : {MainAssetInfo.AssetPath}";
+ YooLogger.Error(error);
+ InvokeCompletion(error, EOperationStatus.Failed);
}
- InvokeCompletion();
}
}
}
diff --git a/Assets/YooAsset/Runtime/ResourceManager/Provider/BundledSubAssetsProvider.cs b/Assets/YooAsset/Runtime/ResourceManager/Provider/BundledSubAssetsProvider.cs
index 496f8fa..c33612f 100644
--- a/Assets/YooAsset/Runtime/ResourceManager/Provider/BundledSubAssetsProvider.cs
+++ b/Assets/YooAsset/Runtime/ResourceManager/Provider/BundledSubAssetsProvider.cs
@@ -8,23 +8,25 @@ namespace YooAsset
{
private AssetBundleRequest _cacheRequest;
- public BundledSubAssetsProvider(ResourceManager manager, string providerGUID, uint providerPriority, AssetInfo assetInfo) : base(manager, providerGUID, providerPriority, assetInfo)
+ public BundledSubAssetsProvider(ResourceManager manager, string providerGUID, AssetInfo assetInfo) : base(manager, providerGUID, assetInfo)
{
}
- public override void Update()
+ internal override void InternalOnStart()
{
DebugBeginRecording();
-
+ }
+ internal override void InternalOnUpdate()
+ {
if (IsDone)
return;
- if (Status == EStatus.None)
+ if (_steps == ESteps.None)
{
- Status = EStatus.CheckBundle;
+ _steps = ESteps.CheckBundle;
}
// 1. 检测资源包
- if (Status == EStatus.CheckBundle)
+ if (_steps == ESteps.CheckBundle)
{
if (IsWaitForAsyncComplete)
{
@@ -39,17 +41,15 @@ namespace YooAsset
if (DependBundles.IsSucceed() == false)
{
- Status = EStatus.Failed;
- LastError = DependBundles.GetLastError();
- InvokeCompletion();
+ string error = DependBundles.GetLastError();
+ InvokeCompletion(error, EOperationStatus.Failed);
return;
}
if (OwnerBundle.Status != BundleLoaderBase.EStatus.Succeed)
{
- Status = EStatus.Failed;
- LastError = OwnerBundle.LastError;
- InvokeCompletion();
+ string error = OwnerBundle.LastError;
+ InvokeCompletion(error, EOperationStatus.Failed);
return;
}
@@ -59,11 +59,11 @@ namespace YooAsset
return;
}
- Status = EStatus.Loading;
+ _steps = ESteps.Loading;
}
// 2. 加载资源对象
- if (Status == EStatus.Loading)
+ if (_steps == ESteps.Loading)
{
if (IsWaitForAsyncComplete || IsForceDestroyComplete)
{
@@ -79,11 +79,11 @@ namespace YooAsset
else
_cacheRequest = OwnerBundle.CacheBundle.LoadAssetWithSubAssetsAsync(MainAssetInfo.AssetPath, MainAssetInfo.AssetType);
}
- Status = EStatus.Checking;
+ _steps = ESteps.Checking;
}
// 3. 检测加载结果
- if (Status == EStatus.Checking)
+ if (_steps == ESteps.Checking)
{
if (_cacheRequest != null)
{
@@ -102,16 +102,20 @@ namespace YooAsset
}
}
- Status = AllAssetObjects == null ? EStatus.Failed : EStatus.Succeed;
- if (Status == EStatus.Failed)
+ if (AllAssetObjects == null)
{
+ string error;
if (MainAssetInfo.AssetType == null)
- LastError = $"Failed to load sub assets : {MainAssetInfo.AssetPath} AssetType : null AssetBundle : {OwnerBundle.MainBundleInfo.Bundle.BundleName}";
+ error = $"Failed to load sub assets : {MainAssetInfo.AssetPath} AssetType : null AssetBundle : {OwnerBundle.MainBundleInfo.Bundle.BundleName}";
else
- LastError = $"Failed to load sub assets : {MainAssetInfo.AssetPath} AssetType : {MainAssetInfo.AssetType} AssetBundle : {OwnerBundle.MainBundleInfo.Bundle.BundleName}";
- YooLogger.Error(LastError);
+ error = $"Failed to load sub assets : {MainAssetInfo.AssetPath} AssetType : {MainAssetInfo.AssetType} AssetBundle : {OwnerBundle.MainBundleInfo.Bundle.BundleName}";
+ YooLogger.Error(error);
+ InvokeCompletion(error, EOperationStatus.Failed);
+ }
+ else
+ {
+ InvokeCompletion(string.Empty, EOperationStatus.Succeed);
}
- InvokeCompletion();
}
}
}
diff --git a/Assets/YooAsset/Runtime/ResourceManager/Provider/CompletedProvider.cs b/Assets/YooAsset/Runtime/ResourceManager/Provider/CompletedProvider.cs
index e674215..fa495ef 100644
--- a/Assets/YooAsset/Runtime/ResourceManager/Provider/CompletedProvider.cs
+++ b/Assets/YooAsset/Runtime/ResourceManager/Provider/CompletedProvider.cs
@@ -3,19 +3,22 @@ namespace YooAsset
{
internal sealed class CompletedProvider : ProviderBase
{
- public CompletedProvider(AssetInfo assetInfo) : base(null, string.Empty, 0, assetInfo)
+ public CompletedProvider(AssetInfo assetInfo) : base(null, string.Empty, assetInfo)
{
}
- public override void Update()
+
+ internal override void InternalOnStart()
{
}
+ internal override void InternalOnUpdate()
+ {
+ }
+
public void SetCompleted(string error)
{
- if (Status == EStatus.None)
+ if (_steps == ESteps.None)
{
- Status = EStatus.Failed;
- LastError = error;
- InvokeCompletion();
+ InvokeCompletion(error, EOperationStatus.Failed);
}
}
}
diff --git a/Assets/YooAsset/Runtime/ResourceManager/Provider/DatabaseAllAssetsProvider.cs b/Assets/YooAsset/Runtime/ResourceManager/Provider/DatabaseAllAssetsProvider.cs
index 4dd1c48..174d665 100644
--- a/Assets/YooAsset/Runtime/ResourceManager/Provider/DatabaseAllAssetsProvider.cs
+++ b/Assets/YooAsset/Runtime/ResourceManager/Provider/DatabaseAllAssetsProvider.cs
@@ -6,29 +6,32 @@ namespace YooAsset
{
internal sealed class DatabaseAllAssetsProvider : ProviderBase
{
- public DatabaseAllAssetsProvider(ResourceManager manager, string providerGUID, uint providerPriority, AssetInfo assetInfo) : base(manager, providerGUID, providerPriority, assetInfo)
+ public DatabaseAllAssetsProvider(ResourceManager manager, string providerGUID, AssetInfo assetInfo) : base(manager, providerGUID, assetInfo)
{
}
- public override void Update()
+ internal override void InternalOnStart()
+ {
+ DebugBeginRecording();
+ }
+ internal override void InternalOnUpdate()
{
#if UNITY_EDITOR
if (IsDone)
return;
- if (Status == EStatus.None)
+ if (_steps == ESteps.None)
{
// 检测资源文件是否存在
string guid = UnityEditor.AssetDatabase.AssetPathToGUID(MainAssetInfo.AssetPath);
if (string.IsNullOrEmpty(guid))
{
- Status = EStatus.Failed;
- LastError = $"Not found asset : {MainAssetInfo.AssetPath}";
- YooLogger.Error(LastError);
- InvokeCompletion();
+ string error = $"Not found asset : {MainAssetInfo.AssetPath}";
+ YooLogger.Error(error);
+ InvokeCompletion(error, EOperationStatus.Failed);
return;
}
- Status = EStatus.CheckBundle;
+ _steps = ESteps.CheckBundle;
// 注意:模拟异步加载效果提前返回
if (IsWaitForAsyncComplete == false)
@@ -36,7 +39,7 @@ namespace YooAsset
}
// 1. 检测资源包
- if (Status == EStatus.CheckBundle)
+ if (_steps == ESteps.CheckBundle)
{
if (IsWaitForAsyncComplete)
{
@@ -48,17 +51,16 @@ namespace YooAsset
if (OwnerBundle.Status != BundleLoaderBase.EStatus.Succeed)
{
- Status = EStatus.Failed;
- LastError = OwnerBundle.LastError;
- InvokeCompletion();
+ string error = OwnerBundle.LastError;
+ InvokeCompletion(error, EOperationStatus.Failed);
return;
}
- Status = EStatus.Loading;
+ _steps = ESteps.Loading;
}
// 2. 加载资源对象
- if (Status == EStatus.Loading)
+ if (_steps == ESteps.Loading)
{
if (MainAssetInfo.AssetType == null)
{
@@ -82,22 +84,26 @@ namespace YooAsset
}
AllAssetObjects = result.ToArray();
}
- Status = EStatus.Checking;
+ _steps = ESteps.Checking;
}
// 3. 检测加载结果
- if (Status == EStatus.Checking)
+ if (_steps == ESteps.Checking)
{
- Status = AllAssetObjects == null ? EStatus.Failed : EStatus.Succeed;
- if (Status == EStatus.Failed)
+ if (AllAssetObjects == null)
{
+ string error;
if (MainAssetInfo.AssetType == null)
- LastError = $"Failed to load all assets : {MainAssetInfo.AssetPath} AssetType : null";
+ error = $"Failed to load all assets : {MainAssetInfo.AssetPath} AssetType : null";
else
- LastError = $"Failed to load all assets : {MainAssetInfo.AssetPath} AssetType : {MainAssetInfo.AssetType}";
- YooLogger.Error(LastError);
+ error = $"Failed to load all assets : {MainAssetInfo.AssetPath} AssetType : {MainAssetInfo.AssetType}";
+ YooLogger.Error(error);
+ InvokeCompletion(error, EOperationStatus.Failed);
+ }
+ else
+ {
+ InvokeCompletion(string.Empty, EOperationStatus.Succeed);
}
- InvokeCompletion();
}
#endif
}
diff --git a/Assets/YooAsset/Runtime/ResourceManager/Provider/DatabaseAssetProvider.cs b/Assets/YooAsset/Runtime/ResourceManager/Provider/DatabaseAssetProvider.cs
index 89b526c..96f790f 100644
--- a/Assets/YooAsset/Runtime/ResourceManager/Provider/DatabaseAssetProvider.cs
+++ b/Assets/YooAsset/Runtime/ResourceManager/Provider/DatabaseAssetProvider.cs
@@ -6,29 +6,32 @@ namespace YooAsset
{
internal sealed class DatabaseAssetProvider : ProviderBase
{
- public DatabaseAssetProvider(ResourceManager manager, string providerGUID, uint providerPriority, AssetInfo assetInfo) : base(manager, providerGUID, providerPriority, assetInfo)
+ public DatabaseAssetProvider(ResourceManager manager, string providerGUID, AssetInfo assetInfo) : base(manager, providerGUID, assetInfo)
{
}
- public override void Update()
+ internal override void InternalOnStart()
+ {
+ DebugBeginRecording();
+ }
+ internal override void InternalOnUpdate()
{
#if UNITY_EDITOR
if (IsDone)
return;
- if (Status == EStatus.None)
+ if (_steps == ESteps.None)
{
// 检测资源文件是否存在
string guid = UnityEditor.AssetDatabase.AssetPathToGUID(MainAssetInfo.AssetPath);
if (string.IsNullOrEmpty(guid))
{
- Status = EStatus.Failed;
- LastError = $"Not found asset : {MainAssetInfo.AssetPath}";
- YooLogger.Error(LastError);
- InvokeCompletion();
+ string error = $"Not found asset : {MainAssetInfo.AssetPath}";
+ YooLogger.Error(error);
+ InvokeCompletion(error, EOperationStatus.Failed);
return;
}
- Status = EStatus.CheckBundle;
+ _steps = ESteps.CheckBundle;
// 注意:模拟异步加载效果提前返回
if (IsWaitForAsyncComplete == false)
@@ -36,7 +39,7 @@ namespace YooAsset
}
// 1. 检测资源包
- if (Status == EStatus.CheckBundle)
+ if (_steps == ESteps.CheckBundle)
{
if (IsWaitForAsyncComplete)
{
@@ -48,38 +51,41 @@ namespace YooAsset
if (OwnerBundle.Status != BundleLoaderBase.EStatus.Succeed)
{
- Status = EStatus.Failed;
- LastError = OwnerBundle.LastError;
- InvokeCompletion();
+ string error = OwnerBundle.LastError;
+ InvokeCompletion(error, EOperationStatus.Failed);
return;
}
- Status = EStatus.Loading;
+ _steps = ESteps.Loading;
}
// 2. 加载资源对象
- if (Status == EStatus.Loading)
+ if (_steps == ESteps.Loading)
{
if (MainAssetInfo.AssetType == null)
AssetObject = UnityEditor.AssetDatabase.LoadMainAssetAtPath(MainAssetInfo.AssetPath);
else
AssetObject = UnityEditor.AssetDatabase.LoadAssetAtPath(MainAssetInfo.AssetPath, MainAssetInfo.AssetType);
- Status = EStatus.Checking;
+ _steps = ESteps.Checking;
}
// 3. 检测加载结果
- if (Status == EStatus.Checking)
+ if (_steps == ESteps.Checking)
{
- Status = AssetObject == null ? EStatus.Failed : EStatus.Succeed;
- if (Status == EStatus.Failed)
+ if (AssetObject == null)
{
+ string error;
if (MainAssetInfo.AssetType == null)
- LastError = $"Failed to load asset object : {MainAssetInfo.AssetPath} AssetType : null";
+ error = $"Failed to load asset object : {MainAssetInfo.AssetPath} AssetType : null";
else
- LastError = $"Failed to load asset object : {MainAssetInfo.AssetPath} AssetType : {MainAssetInfo.AssetType}";
- YooLogger.Error(LastError);
+ error = $"Failed to load asset object : {MainAssetInfo.AssetPath} AssetType : {MainAssetInfo.AssetType}";
+ YooLogger.Error(error);
+ InvokeCompletion(error, EOperationStatus.Failed);
+ }
+ else
+ {
+ InvokeCompletion(string.Empty, EOperationStatus.Succeed);
}
- InvokeCompletion();
}
#endif
}
diff --git a/Assets/YooAsset/Runtime/ResourceManager/Provider/DatabaseRawFileProvider.cs b/Assets/YooAsset/Runtime/ResourceManager/Provider/DatabaseRawFileProvider.cs
index 3d9de80..a674524 100644
--- a/Assets/YooAsset/Runtime/ResourceManager/Provider/DatabaseRawFileProvider.cs
+++ b/Assets/YooAsset/Runtime/ResourceManager/Provider/DatabaseRawFileProvider.cs
@@ -3,29 +3,32 @@ namespace YooAsset
{
internal class DatabaseRawFileProvider : ProviderBase
{
- public DatabaseRawFileProvider(ResourceManager manager, string providerGUID, uint providerPriority, AssetInfo assetInfo) : base(manager, providerGUID, providerPriority, assetInfo)
+ public DatabaseRawFileProvider(ResourceManager manager, string providerGUID, AssetInfo assetInfo) : base(manager, providerGUID, assetInfo)
{
}
- public override void Update()
+ internal override void InternalOnStart()
+ {
+ DebugBeginRecording();
+ }
+ internal override void InternalOnUpdate()
{
#if UNITY_EDITOR
if (IsDone)
return;
- if (Status == EStatus.None)
+ if (_steps == ESteps.None)
{
// 检测资源文件是否存在
string guid = UnityEditor.AssetDatabase.AssetPathToGUID(MainAssetInfo.AssetPath);
if (string.IsNullOrEmpty(guid))
{
- Status = EStatus.Failed;
- LastError = $"Not found asset : {MainAssetInfo.AssetPath}";
- YooLogger.Error(LastError);
- InvokeCompletion();
+ string error = $"Not found asset : {MainAssetInfo.AssetPath}";
+ YooLogger.Error(error);
+ InvokeCompletion(error, EOperationStatus.Failed);
return;
}
- Status = EStatus.CheckBundle;
+ _steps = ESteps.CheckBundle;
// 注意:模拟异步加载效果提前返回
if (IsWaitForAsyncComplete == false)
@@ -33,7 +36,7 @@ namespace YooAsset
}
// 1. 检测资源包
- if (Status == EStatus.CheckBundle)
+ if (_steps == ESteps.CheckBundle)
{
if (IsWaitForAsyncComplete)
{
@@ -45,21 +48,19 @@ namespace YooAsset
if (OwnerBundle.Status != BundleLoaderBase.EStatus.Succeed)
{
- Status = EStatus.Failed;
- LastError = OwnerBundle.LastError;
- InvokeCompletion();
+ string error = OwnerBundle.LastError;
+ InvokeCompletion(error, EOperationStatus.Failed);
return;
}
- Status = EStatus.Checking;
+ _steps = ESteps.Checking;
}
// 2. 检测加载结果
- if (Status == EStatus.Checking)
+ if (_steps == ESteps.Checking)
{
RawFilePath = MainAssetInfo.AssetPath;
- Status = EStatus.Succeed;
- InvokeCompletion();
+ InvokeCompletion(string.Empty, EOperationStatus.Succeed);
}
#endif
}
diff --git a/Assets/YooAsset/Runtime/ResourceManager/Provider/DatabaseSceneProvider.cs b/Assets/YooAsset/Runtime/ResourceManager/Provider/DatabaseSceneProvider.cs
index 2619f94..49e5d66 100644
--- a/Assets/YooAsset/Runtime/ResourceManager/Provider/DatabaseSceneProvider.cs
+++ b/Assets/YooAsset/Runtime/ResourceManager/Provider/DatabaseSceneProvider.cs
@@ -12,25 +12,29 @@ namespace YooAsset
private readonly bool _suspendLoad;
private AsyncOperation _asyncOperation;
- public DatabaseSceneProvider(ResourceManager manager, string providerGUID, uint providerPriority, AssetInfo assetInfo, LoadSceneMode sceneMode, bool suspendLoad) : base(manager, providerGUID, providerPriority, assetInfo)
+ public DatabaseSceneProvider(ResourceManager manager, string providerGUID, AssetInfo assetInfo, LoadSceneMode sceneMode, bool suspendLoad) : base(manager, providerGUID, assetInfo)
{
SceneMode = sceneMode;
SceneName = Path.GetFileNameWithoutExtension(assetInfo.AssetPath);
_suspendLoad = suspendLoad;
}
- public override void Update()
+ internal override void InternalOnStart()
+ {
+ DebugBeginRecording();
+ }
+ internal override void InternalOnUpdate()
{
#if UNITY_EDITOR
if (IsDone)
return;
- if (Status == EStatus.None)
+ if (_steps == ESteps.None)
{
- Status = EStatus.CheckBundle;
+ _steps = ESteps.CheckBundle;
}
// 1. 检测资源包
- if (Status == EStatus.CheckBundle)
+ if (_steps == ESteps.CheckBundle)
{
if (IsWaitForAsyncComplete)
{
@@ -42,17 +46,16 @@ namespace YooAsset
if (OwnerBundle.Status != BundleLoaderBase.EStatus.Succeed)
{
- Status = EStatus.Failed;
- LastError = OwnerBundle.LastError;
- InvokeCompletion();
+ string error = OwnerBundle.LastError;
+ InvokeCompletion(error, EOperationStatus.Failed);
return;
}
- Status = EStatus.Loading;
+ _steps = ESteps.Loading;
}
// 2. 加载资源对象
- if (Status == EStatus.Loading)
+ if (_steps == ESteps.Loading)
{
LoadSceneParameters loadSceneParameters = new LoadSceneParameters();
loadSceneParameters.loadSceneMode = SceneMode;
@@ -60,32 +63,34 @@ namespace YooAsset
if (_asyncOperation != null)
{
_asyncOperation.allowSceneActivation = !_suspendLoad;
- _asyncOperation.priority = (int)ProviderPriority;
+ _asyncOperation.priority = 100;
SceneObject = SceneManager.GetSceneAt(SceneManager.sceneCount - 1);
- Status = EStatus.Checking;
+ _steps = ESteps.Checking;
}
else
{
- Status = EStatus.Failed;
- LastError = $"Failed to load scene : {MainAssetInfo.AssetPath}";
- YooLogger.Error(LastError);
- InvokeCompletion();
+ string error = $"Failed to load scene : {MainAssetInfo.AssetPath}";
+ YooLogger.Error(error);
+ InvokeCompletion(error, EOperationStatus.Failed);
}
}
// 3. 检测加载结果
- if (Status == EStatus.Checking)
+ if (_steps == ESteps.Checking)
{
Progress = _asyncOperation.progress;
if (_asyncOperation.isDone)
{
- Status = SceneObject.IsValid() ? EStatus.Succeed : EStatus.Failed;
- if (Status == EStatus.Failed)
+ if (SceneObject.IsValid())
{
- LastError = $"The loaded scene is invalid : {MainAssetInfo.AssetPath}";
- YooLogger.Error(LastError);
+ InvokeCompletion(string.Empty, EOperationStatus.Succeed);
+ }
+ else
+ {
+ string error = $"The loaded scene is invalid : {MainAssetInfo.AssetPath}";
+ YooLogger.Error(error);
+ InvokeCompletion(error, EOperationStatus.Failed);
}
- InvokeCompletion();
}
}
#endif
diff --git a/Assets/YooAsset/Runtime/ResourceManager/Provider/DatabaseSubAssetsProvider.cs b/Assets/YooAsset/Runtime/ResourceManager/Provider/DatabaseSubAssetsProvider.cs
index 6c1e2a0..5f97102 100644
--- a/Assets/YooAsset/Runtime/ResourceManager/Provider/DatabaseSubAssetsProvider.cs
+++ b/Assets/YooAsset/Runtime/ResourceManager/Provider/DatabaseSubAssetsProvider.cs
@@ -6,29 +6,32 @@ namespace YooAsset
{
internal sealed class DatabaseSubAssetsProvider : ProviderBase
{
- public DatabaseSubAssetsProvider(ResourceManager manager, string providerGUID, uint providerPriority, AssetInfo assetInfo) : base(manager, providerGUID, providerPriority, assetInfo)
+ public DatabaseSubAssetsProvider(ResourceManager manager, string providerGUID, AssetInfo assetInfo) : base(manager, providerGUID, assetInfo)
{
}
- public override void Update()
+ internal override void InternalOnStart()
+ {
+ DebugBeginRecording();
+ }
+ internal override void InternalOnUpdate()
{
#if UNITY_EDITOR
if (IsDone)
return;
- if (Status == EStatus.None)
+ if (_steps == ESteps.None)
{
// 检测资源文件是否存在
string guid = UnityEditor.AssetDatabase.AssetPathToGUID(MainAssetInfo.AssetPath);
if (string.IsNullOrEmpty(guid))
{
- Status = EStatus.Failed;
- LastError = $"Not found asset : {MainAssetInfo.AssetPath}";
- YooLogger.Error(LastError);
- InvokeCompletion();
+ string error = $"Not found asset : {MainAssetInfo.AssetPath}";
+ YooLogger.Error(error);
+ InvokeCompletion(error, EOperationStatus.Failed);
return;
}
- Status = EStatus.CheckBundle;
+ _steps = ESteps.CheckBundle;
// 注意:模拟异步加载效果提前返回
if (IsWaitForAsyncComplete == false)
@@ -36,7 +39,7 @@ namespace YooAsset
}
// 1. 检测资源包
- if (Status == EStatus.CheckBundle)
+ if (_steps == ESteps.CheckBundle)
{
if (IsWaitForAsyncComplete)
{
@@ -48,17 +51,16 @@ namespace YooAsset
if (OwnerBundle.Status != BundleLoaderBase.EStatus.Succeed)
{
- Status = EStatus.Failed;
- LastError = OwnerBundle.LastError;
- InvokeCompletion();
+ string error = OwnerBundle.LastError;
+ InvokeCompletion(error, EOperationStatus.Failed);
return;
}
- Status = EStatus.Loading;
+ _steps = ESteps.Loading;
}
// 2. 加载资源对象
- if (Status == EStatus.Loading)
+ if (_steps == ESteps.Loading)
{
if (MainAssetInfo.AssetType == null)
{
@@ -75,22 +77,26 @@ namespace YooAsset
}
AllAssetObjects = result.ToArray();
}
- Status = EStatus.Checking;
+ _steps = ESteps.Checking;
}
// 3. 检测加载结果
- if (Status == EStatus.Checking)
+ if (_steps == ESteps.Checking)
{
- Status = AllAssetObjects == null ? EStatus.Failed : EStatus.Succeed;
- if (Status == EStatus.Failed)
+ if (AllAssetObjects == null)
{
+ string error;
if (MainAssetInfo.AssetType == null)
- LastError = $"Failed to load sub assets : {MainAssetInfo.AssetPath} AssetType : null";
+ error = $"Failed to load sub assets : {MainAssetInfo.AssetPath} AssetType : null";
else
- LastError = $"Failed to load sub assets : {MainAssetInfo.AssetPath} AssetType : {MainAssetInfo.AssetType}";
- YooLogger.Error(LastError);
+ error = $"Failed to load sub assets : {MainAssetInfo.AssetPath} AssetType : {MainAssetInfo.AssetType}";
+ YooLogger.Error(error);
+ InvokeCompletion(error, EOperationStatus.Failed);
+ }
+ else
+ {
+ InvokeCompletion(string.Empty, EOperationStatus.Succeed);
}
- InvokeCompletion();
}
#endif
}
diff --git a/Assets/YooAsset/Runtime/ResourceManager/Provider/ProviderBase.cs b/Assets/YooAsset/Runtime/ResourceManager/Provider/ProviderBase.cs
index 0364ad3..0421d70 100644
--- a/Assets/YooAsset/Runtime/ResourceManager/Provider/ProviderBase.cs
+++ b/Assets/YooAsset/Runtime/ResourceManager/Provider/ProviderBase.cs
@@ -6,16 +6,15 @@ using System;
namespace YooAsset
{
- internal abstract class ProviderBase : IComparable
+ internal abstract class ProviderBase : AsyncOperationBase
{
- public enum EStatus
+ protected enum ESteps
{
None = 0,
CheckBundle,
Loading,
Checking,
- Succeed,
- Failed,
+ Done,
}
///
@@ -23,11 +22,6 @@ namespace YooAsset
///
public string ProviderGUID { private set; get; }
- ///
- /// 资源加载的优先级
- ///
- public uint ProviderPriority { private set; get; }
-
///
/// 所属资源系统
///
@@ -63,22 +57,6 @@ namespace YooAsset
///
public string RawFilePath { protected set; get; }
-
- ///
- /// 当前的加载状态
- ///
- public EStatus Status { protected set; get; } = EStatus.None;
-
- ///
- /// 最近的错误信息
- ///
- public string LastError { protected set; get; } = string.Empty;
-
- ///
- /// 加载进度
- ///
- public float Progress { protected set; get; } = 0f;
-
///
/// 引用计数
///
@@ -89,18 +67,8 @@ namespace YooAsset
///
public bool IsDestroyed { private set; get; } = false;
- ///
- /// 是否完毕(成功或失败)
- ///
- public bool IsDone
- {
- get
- {
- return Status == EStatus.Succeed || Status == EStatus.Failed;
- }
- }
-
+ protected ESteps _steps = ESteps.None;
protected BundleLoaderBase OwnerBundle { private set; get; }
protected DependAssetBundles DependBundles { private set; get; }
protected bool IsWaitForAsyncComplete { private set; get; } = false;
@@ -108,11 +76,10 @@ namespace YooAsset
private readonly List _handles = new List();
- public ProviderBase(ResourceManager manager, string providerGUID, uint providerPriority, AssetInfo assetInfo)
+ public ProviderBase(ResourceManager manager, string providerGUID, AssetInfo assetInfo)
{
ResourceMgr = manager;
ProviderGUID = providerGUID;
- ProviderPriority = providerPriority;
MainAssetInfo = assetInfo;
// 创建资源包加载器
@@ -128,11 +95,6 @@ namespace YooAsset
}
}
- ///
- /// 轮询更新方法
- ///
- public abstract void Update();
-
///
/// 销毁资源提供者
///
@@ -140,6 +102,13 @@ namespace YooAsset
{
IsDestroyed = true;
+ // 检测是否为正常销毁
+ if (IsDone == false)
+ {
+ Error = "User abort !";
+ Status = EOperationStatus.Failed;
+ }
+
// 释放资源包加载器
if (OwnerBundle != null)
{
@@ -159,7 +128,7 @@ namespace YooAsset
public bool CanDestroy()
{
// 注意:在进行资源加载过程时不可以销毁
- if (Status == EStatus.Loading || Status == EStatus.Checking)
+ if (_steps == ESteps.Loading || _steps == ESteps.Checking)
return false;
return RefCount <= 0;
@@ -226,7 +195,7 @@ namespace YooAsset
IsWaitForAsyncComplete = true;
// 注意:主动轮询更新完成同步加载
- Update();
+ InternalOnUpdate();
// 验证结果
if (IsDone == false)
@@ -244,7 +213,7 @@ namespace YooAsset
// 注意:主动轮询更新完成同步加载
// 说明:如果资源包未准备完毕也可以放心销毁。
- Update();
+ InternalOnUpdate();
}
///
@@ -255,44 +224,21 @@ namespace YooAsset
if (OwnerBundle.IsDestroyed)
throw new System.Exception("Should never get here !");
- Status = EStatus.Failed;
- LastError = $"The bundle {OwnerBundle.MainBundleInfo.Bundle.BundleName} has been destroyed by unity bugs !";
- YooLogger.Error(LastError);
- InvokeCompletion();
+ string error = $"The bundle {OwnerBundle.MainBundleInfo.Bundle.BundleName} has been destroyed by unity bugs !";
+ YooLogger.Error(error);
+ InvokeCompletion(Error, EOperationStatus.Failed);
}
///
- /// 异步操作任务
+ /// 结束流程
///
- public Task Task
- {
- get
- {
- if (_taskCompletionSource == null)
- {
- _taskCompletionSource = new TaskCompletionSource
/// 资源信息
+ /// 加载的优先级
public AssetHandle LoadAssetAsync(AssetInfo assetInfo, uint priority = 0)
{
DebugCheckInitialize();
@@ -688,6 +684,7 @@ namespace YooAsset
///
/// 资源类型
/// 资源的定位地址
+ /// 加载的优先级
public AssetHandle LoadAssetAsync(string location, uint priority = 0) where TObject : UnityEngine.Object
{
DebugCheckInitialize();
@@ -700,6 +697,7 @@ namespace YooAsset
///
/// 资源的定位地址
/// 资源类型
+ /// 加载的优先级
public AssetHandle LoadAssetAsync(string location, System.Type type, uint priority = 0)
{
DebugCheckInitialize();
@@ -711,6 +709,7 @@ namespace YooAsset
/// 异步加载资源对象
///
/// 资源的定位地址
+ /// 加载的优先级
public AssetHandle LoadAssetAsync(string location, uint priority = 0)
{
DebugCheckInitialize();
@@ -783,6 +782,7 @@ namespace YooAsset
/// 异步加载子资源对象
///
/// 资源信息
+ /// 加载的优先级
public SubAssetsHandle LoadSubAssetsAsync(AssetInfo assetInfo, uint priority = 0)
{
DebugCheckInitialize();
@@ -794,6 +794,7 @@ namespace YooAsset
///
/// 资源类型
/// 资源的定位地址
+ /// 加载的优先级
public SubAssetsHandle LoadSubAssetsAsync(string location, uint priority = 0) where TObject : UnityEngine.Object
{
DebugCheckInitialize();
@@ -806,6 +807,7 @@ namespace YooAsset
///
/// 资源的定位地址
/// 子对象类型
+ /// 加载的优先级
public SubAssetsHandle LoadSubAssetsAsync(string location, System.Type type, uint priority = 0)
{
DebugCheckInitialize();
@@ -817,6 +819,7 @@ namespace YooAsset
/// 异步加载子资源对象
///
/// 资源的定位地址
+ /// 加载的优先级
public SubAssetsHandle LoadSubAssetsAsync(string location, uint priority = 0)
{
DebugCheckInitialize();
@@ -889,6 +892,7 @@ namespace YooAsset
/// 异步加载资源包内所有资源对象
///
/// 资源信息
+ /// 加载的优先级
public AllAssetsHandle LoadAllAssetsAsync(AssetInfo assetInfo, uint priority = 0)
{
DebugCheckInitialize();
@@ -900,6 +904,7 @@ namespace YooAsset
///
/// 资源类型
/// 资源的定位地址
+ /// 加载的优先级
public AllAssetsHandle LoadAllAssetsAsync(string location, uint priority = 0) where TObject : UnityEngine.Object
{
DebugCheckInitialize();
@@ -912,6 +917,7 @@ namespace YooAsset
///
/// 资源的定位地址
/// 子对象类型
+ /// 加载的优先级
public AllAssetsHandle LoadAllAssetsAsync(string location, System.Type type, uint priority = 0)
{
DebugCheckInitialize();
@@ -923,6 +929,7 @@ namespace YooAsset
/// 异步加载资源包内所有资源对象
///
/// 资源的定位地址
+ /// 加载的优先级
public AllAssetsHandle LoadAllAssetsAsync(string location, uint priority = 0)
{
DebugCheckInitialize();