diff --git a/Assets/YooAsset/Runtime/AssetSystem/AssetSystem.cs b/Assets/YooAsset/Runtime/AssetSystem/AssetSystem.cs
index 56bc1e2..a80e830 100644
--- a/Assets/YooAsset/Runtime/AssetSystem/AssetSystem.cs
+++ b/Assets/YooAsset/Runtime/AssetSystem/AssetSystem.cs
@@ -83,7 +83,7 @@ namespace YooAsset
{
if (_providers[i].CanDestroy())
{
- _providers[i].Destory();
+ _providers[i].Destroy();
_providers.RemoveAt(i);
}
}
@@ -114,7 +114,7 @@ namespace YooAsset
{
foreach (var provider in _providers)
{
- provider.Destory();
+ provider.Destroy();
}
_providers.Clear();
diff --git a/Assets/YooAsset/Runtime/AssetSystem/Handles/OperationHandleBase.cs b/Assets/YooAsset/Runtime/AssetSystem/Handles/OperationHandleBase.cs
index 38f01ae..9baa391 100644
--- a/Assets/YooAsset/Runtime/AssetSystem/Handles/OperationHandleBase.cs
+++ b/Assets/YooAsset/Runtime/AssetSystem/Handles/OperationHandleBase.cs
@@ -32,6 +32,19 @@ namespace YooAsset
}
}
+ ///
+ /// 最近的错误信息
+ ///
+ public string LastError
+ {
+ get
+ {
+ if (IsValid == false)
+ return string.Empty;
+ return _provider.LastError;
+ }
+ }
+
///
/// 加载进度
///
diff --git a/Assets/YooAsset/Runtime/AssetSystem/Loader/AssetBundleFileLoader.cs b/Assets/YooAsset/Runtime/AssetSystem/Loader/AssetBundleFileLoader.cs
index 13b6790..20dff8e 100644
--- a/Assets/YooAsset/Runtime/AssetSystem/Loader/AssetBundleFileLoader.cs
+++ b/Assets/YooAsset/Runtime/AssetSystem/Loader/AssetBundleFileLoader.cs
@@ -43,10 +43,10 @@ namespace YooAsset
{
_steps = ESteps.Done;
Status = EStatus.Failed;
- return;
+ LastError = $"Invalid load mode : {BundleFileInfo.BundleName}";
+ YooLogger.Error(LastError);
}
-
- if (BundleFileInfo.LoadMode == BundleInfo.ELoadMode.LoadFromRemote)
+ else if (BundleFileInfo.LoadMode == BundleInfo.ELoadMode.LoadFromRemote)
{
_steps = ESteps.Download;
_fileLoadPath = BundleFileInfo.GetCacheLoadPath();
@@ -83,9 +83,9 @@ namespace YooAsset
if (_downloader.HasError())
{
- _downloader.ReportError();
_steps = ESteps.Done;
Status = EStatus.Failed;
+ LastError = _downloader.GetLastError();
}
else
{
@@ -100,9 +100,10 @@ namespace YooAsset
// 注意:Unity2017.4编辑器模式下,如果AssetBundle文件不存在会导致编辑器崩溃,这里做了预判。
if (System.IO.File.Exists(_fileLoadPath) == false)
{
- YooLogger.Warning($"Not found assetBundle file : {_fileLoadPath}");
_steps = ESteps.Done;
Status = EStatus.Failed;
+ LastError = $"Not found assetBundle file : {_fileLoadPath}";
+ YooLogger.Error(LastError);
return;
}
#endif
@@ -151,9 +152,10 @@ namespace YooAsset
// Check error
if (CacheBundle == null)
{
- YooLogger.Error($"Failed to load assetBundle file : {BundleFileInfo.BundleName}");
_steps = ESteps.Done;
Status = EStatus.Failed;
+ LastError = $"Failed to load assetBundle : {BundleFileInfo.BundleName}";
+ YooLogger.Error(LastError);
}
else
{
diff --git a/Assets/YooAsset/Runtime/AssetSystem/Loader/AssetBundleLoaderBase.cs b/Assets/YooAsset/Runtime/AssetSystem/Loader/AssetBundleLoaderBase.cs
index 495a062..f8c07f6 100644
--- a/Assets/YooAsset/Runtime/AssetSystem/Loader/AssetBundleLoaderBase.cs
+++ b/Assets/YooAsset/Runtime/AssetSystem/Loader/AssetBundleLoaderBase.cs
@@ -29,6 +29,11 @@ namespace YooAsset
///
public EStatus Status { protected set; get; }
+ ///
+ /// 最近的错误信息
+ ///
+ public string LastError { protected set; get; }
+
///
/// 是否已经销毁
///
@@ -139,7 +144,7 @@ namespace YooAsset
// 销毁所有Providers
foreach (var provider in _providers)
{
- provider.Destory();
+ provider.Destroy();
}
// 从列表里移除Providers
diff --git a/Assets/YooAsset/Runtime/AssetSystem/Loader/AssetBundleWebLoader.cs b/Assets/YooAsset/Runtime/AssetSystem/Loader/AssetBundleWebLoader.cs
index 8eb8d8c..cfb51d3 100644
--- a/Assets/YooAsset/Runtime/AssetSystem/Loader/AssetBundleWebLoader.cs
+++ b/Assets/YooAsset/Runtime/AssetSystem/Loader/AssetBundleWebLoader.cs
@@ -41,10 +41,10 @@ namespace YooAsset
{
_steps = ESteps.Done;
Status = EStatus.Failed;
- return;
+ LastError = $"Invalid load mode : {BundleFileInfo.BundleName}";
+ YooLogger.Error(LastError);
}
-
- if (BundleFileInfo.LoadMode == BundleInfo.ELoadMode.LoadFromStreaming)
+ else if (BundleFileInfo.LoadMode == BundleInfo.ELoadMode.LoadFromStreaming)
{
_steps = ESteps.LoadFile;
_webURL = BundleFileInfo.GetStreamingLoadPath();
@@ -76,7 +76,7 @@ namespace YooAsset
if (_webRequest.isNetworkError || _webRequest.isHttpError)
#endif
{
- Debug.LogWarning($"Failed to get asset bundle form web : {_webURL} Error : {_webRequest.error}");
+ YooLogger.Warning($"Failed to get asset bundle form web : {_webURL} Error : {_webRequest.error}");
_steps = ESteps.TryLoad;
_tryTimer = 0;
}
@@ -85,9 +85,10 @@ namespace YooAsset
CacheBundle = DownloadHandlerAssetBundle.GetContent(_webRequest);
if (CacheBundle == null)
{
- Debug.LogError($"Get asset bundle error : {_webRequest.error}");
_steps = ESteps.Done;
Status = EStatus.Failed;
+ LastError = $"AssetBundle file is invalid : {BundleFileInfo.BundleName}";
+ YooLogger.Error(LastError);
}
else
{
diff --git a/Assets/YooAsset/Runtime/AssetSystem/Loader/DependAssetBundleGrouper.cs b/Assets/YooAsset/Runtime/AssetSystem/Loader/DependAssetBundleGrouper.cs
index b44d02a..551490a 100644
--- a/Assets/YooAsset/Runtime/AssetSystem/Loader/DependAssetBundleGrouper.cs
+++ b/Assets/YooAsset/Runtime/AssetSystem/Loader/DependAssetBundleGrouper.cs
@@ -11,6 +11,7 @@ namespace YooAsset
///
private readonly List _dependBundles;
+
public DependAssetBundleGrouper(string assetPath)
{
_dependBundles = AssetSystem.CreateDependAssetBundleLoaders(assetPath);
@@ -29,6 +30,36 @@ namespace YooAsset
return true;
}
+ ///
+ /// 依赖资源包是否全部加载成功
+ ///
+ public bool IsSucceed()
+ {
+ foreach (var loader in _dependBundles)
+ {
+ if (loader.Status != AssetBundleLoaderBase.EStatus.Succeed)
+ {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ ///
+ /// 获取某个加载失败的资源包错误信息
+ ///
+ public string GetLastError()
+ {
+ foreach (var loader in _dependBundles)
+ {
+ if (loader.Status != AssetBundleLoaderBase.EStatus.Succeed)
+ {
+ return loader.LastError;
+ }
+ }
+ return string.Empty;
+ }
+
///
/// 主线程等待异步操作完毕
///
diff --git a/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledAssetProvider.cs b/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledAssetProvider.cs
index ca2c521..fcffcbc 100644
--- a/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledAssetProvider.cs
+++ b/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledAssetProvider.cs
@@ -45,15 +45,23 @@ namespace YooAsset
if (OwnerBundle.IsDone() == false)
return;
- if (OwnerBundle.CacheBundle == null)
+ if (DependBundles.IsSucceed() == false)
{
Status = EStatus.Fail;
+ LastError = DependBundles.GetLastError();
InvokeCompletion();
+ return;
}
- else
+
+ if (OwnerBundle.Status != AssetBundleLoaderBase.EStatus.Succeed)
{
- Status = EStatus.Loading;
+ Status = EStatus.Fail;
+ LastError = OwnerBundle.LastError;
+ InvokeCompletion();
+ return;
}
+
+ Status = EStatus.Loading;
}
// 2. 加载资源对象
@@ -97,7 +105,10 @@ namespace YooAsset
Status = AssetObject == null ? EStatus.Fail : EStatus.Success;
if (Status == EStatus.Fail)
- YooLogger.Warning($"Failed to load asset : {AssetName} from bundle : {OwnerBundle.BundleFileInfo.BundleName}");
+ {
+ LastError = $"Failed to load asset : {AssetName} from bundle : {OwnerBundle.BundleFileInfo.BundleName}";
+ YooLogger.Error(LastError);
+ }
InvokeCompletion();
}
}
diff --git a/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledProvider.cs b/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledProvider.cs
index bbf7877..cc64347 100644
--- a/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledProvider.cs
+++ b/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledProvider.cs
@@ -16,9 +16,9 @@ namespace YooAsset
DependBundles = new DependAssetBundleGrouper(assetPath);
DependBundles.Reference();
}
- public override void Destory()
+ public override void Destroy()
{
- base.Destory();
+ base.Destroy();
// 释放资源包
if (OwnerBundle != null)
diff --git a/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledSceneProvider.cs b/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledSceneProvider.cs
index 7e8ec5e..3a4d905 100644
--- a/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledSceneProvider.cs
+++ b/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledSceneProvider.cs
@@ -46,15 +46,23 @@ namespace YooAsset
if (OwnerBundle.IsDone() == false)
return;
- if (OwnerBundle.CacheBundle == null)
+ if (DependBundles.IsSucceed() == false)
{
Status = EStatus.Fail;
+ LastError = DependBundles.GetLastError();
InvokeCompletion();
+ return;
}
- else
+
+ if (OwnerBundle.Status != AssetBundleLoaderBase.EStatus.Succeed)
{
- Status = EStatus.Loading;
+ Status = EStatus.Fail;
+ LastError = OwnerBundle.LastError;
+ InvokeCompletion();
+ return;
}
+
+ Status = EStatus.Loading;
}
// 2. 加载场景
@@ -69,8 +77,9 @@ namespace YooAsset
}
else
{
- YooLogger.Warning($"Failed to load scene : {AssetName}");
Status = EStatus.Fail;
+ LastError = $"Failed to load scene : {AssetName}";
+ YooLogger.Error(LastError);
InvokeCompletion();
}
}
@@ -85,6 +94,11 @@ namespace YooAsset
SceneManager.SetActiveScene(SceneObject);
Status = SceneObject.IsValid() ? EStatus.Success : EStatus.Fail;
+ if(Status == EStatus.Fail)
+ {
+ LastError = $"The load scene is invalid : {AssetPath}";
+ YooLogger.Error(LastError);
+ }
InvokeCompletion();
}
}
diff --git a/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledSubAssetsProvider.cs b/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledSubAssetsProvider.cs
index e70d94a..321d875 100644
--- a/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledSubAssetsProvider.cs
+++ b/Assets/YooAsset/Runtime/AssetSystem/Provider/BundledSubAssetsProvider.cs
@@ -45,15 +45,23 @@ namespace YooAsset
if (OwnerBundle.IsDone() == false)
return;
- if (OwnerBundle.CacheBundle == null)
+ if (DependBundles.IsSucceed() == false)
{
Status = EStatus.Fail;
+ LastError = DependBundles.GetLastError();
InvokeCompletion();
+ return;
}
- else
+
+ if (OwnerBundle.Status != AssetBundleLoaderBase.EStatus.Succeed)
{
- Status = EStatus.Loading;
+ Status = EStatus.Fail;
+ LastError = OwnerBundle.LastError;
+ InvokeCompletion();
+ return;
}
+
+ Status = EStatus.Loading;
}
// 2. 加载资源对象
@@ -97,7 +105,10 @@ namespace YooAsset
Status = AllAssetObjects == null ? EStatus.Fail : EStatus.Success;
if (Status == EStatus.Fail)
- YooLogger.Warning($"Failed to load sub assets : {AssetName} from bundle : {OwnerBundle.BundleFileInfo.BundleName}");
+ {
+ LastError = $"Failed to load sub assets : {AssetName} from bundle : {OwnerBundle.BundleFileInfo.BundleName}";
+ YooLogger.Error(LastError);
+ }
InvokeCompletion();
}
}
diff --git a/Assets/YooAsset/Runtime/AssetSystem/Provider/DatabaseAssetProvider.cs b/Assets/YooAsset/Runtime/AssetSystem/Provider/DatabaseAssetProvider.cs
index 9dfb1a4..660fd3f 100644
--- a/Assets/YooAsset/Runtime/AssetSystem/Provider/DatabaseAssetProvider.cs
+++ b/Assets/YooAsset/Runtime/AssetSystem/Provider/DatabaseAssetProvider.cs
@@ -34,6 +34,8 @@ namespace YooAsset
if (string.IsNullOrEmpty(guid))
{
Status = EStatus.Fail;
+ LastError = $"Not found asset : {AssetPath}";
+ YooLogger.Error(LastError);
InvokeCompletion();
return;
}
@@ -41,7 +43,7 @@ namespace YooAsset
{
Status = EStatus.Loading;
}
-
+
// 注意:模拟异步加载效果提前返回
if (IsWaitForAsyncComplete == false)
return;
@@ -59,7 +61,10 @@ namespace YooAsset
{
Status = AssetObject == null ? EStatus.Fail : EStatus.Success;
if (Status == EStatus.Fail)
- YooLogger.Warning($"Failed to load asset object : {AssetPath}");
+ {
+ LastError = $"Failed to load asset object : {AssetPath}";
+ YooLogger.Error(LastError);
+ }
InvokeCompletion();
}
#endif
diff --git a/Assets/YooAsset/Runtime/AssetSystem/Provider/DatabaseSceneProvider.cs b/Assets/YooAsset/Runtime/AssetSystem/Provider/DatabaseSceneProvider.cs
index 1112753..f60fcba 100644
--- a/Assets/YooAsset/Runtime/AssetSystem/Provider/DatabaseSceneProvider.cs
+++ b/Assets/YooAsset/Runtime/AssetSystem/Provider/DatabaseSceneProvider.cs
@@ -51,8 +51,9 @@ namespace YooAsset
}
else
{
- YooLogger.Warning($"Failed to load scene : {AssetName}");
Status = EStatus.Fail;
+ LastError = $"Failed to load scene : {AssetPath}";
+ YooLogger.Error(LastError);
InvokeCompletion();
}
}
@@ -67,6 +68,11 @@ namespace YooAsset
SceneManager.SetActiveScene(SceneObject);
Status = SceneObject.IsValid() ? EStatus.Success : EStatus.Fail;
+ if (Status == EStatus.Fail)
+ {
+ LastError = $"The load scene is invalid : {AssetPath}";
+ YooLogger.Error(LastError);
+ }
InvokeCompletion();
}
}
diff --git a/Assets/YooAsset/Runtime/AssetSystem/Provider/DatabaseSubAssetsProvider.cs b/Assets/YooAsset/Runtime/AssetSystem/Provider/DatabaseSubAssetsProvider.cs
index 9b1fd54..216f210 100644
--- a/Assets/YooAsset/Runtime/AssetSystem/Provider/DatabaseSubAssetsProvider.cs
+++ b/Assets/YooAsset/Runtime/AssetSystem/Provider/DatabaseSubAssetsProvider.cs
@@ -34,6 +34,8 @@ namespace YooAsset
if (string.IsNullOrEmpty(guid))
{
Status = EStatus.Fail;
+ LastError = $"Not found asset : {AssetPath}";
+ YooLogger.Error(LastError);
InvokeCompletion();
return;
}
@@ -73,7 +75,10 @@ namespace YooAsset
{
Status = AllAssetObjects == null ? EStatus.Fail : EStatus.Success;
if (Status == EStatus.Fail)
- YooLogger.Warning($"Failed to load sub assets : {AssetName}");
+ {
+ LastError = $"Failed to load sub assets : {nameof(AssetType)} in {AssetPath}";
+ YooLogger.Error(LastError);
+ }
InvokeCompletion();
}
#endif
diff --git a/Assets/YooAsset/Runtime/AssetSystem/Provider/ProviderBase.cs b/Assets/YooAsset/Runtime/AssetSystem/Provider/ProviderBase.cs
index cce422f..ab1ce1d 100644
--- a/Assets/YooAsset/Runtime/AssetSystem/Provider/ProviderBase.cs
+++ b/Assets/YooAsset/Runtime/AssetSystem/Provider/ProviderBase.cs
@@ -53,6 +53,11 @@ namespace YooAsset
///
public EStatus Status { protected set; get; } = EStatus.None;
+ ///
+ /// 最近的错误信息
+ ///
+ public string LastError { protected set; get; } = string.Empty;
+
///
/// 引用计数
///
@@ -105,7 +110,7 @@ namespace YooAsset
///
/// 销毁资源对象
///
- public virtual void Destory()
+ public virtual void Destroy()
{
IsDestroyed = true;
}
diff --git a/Assets/YooAsset/Runtime/DownloadSystem/Downloader/DownloaderBase.cs b/Assets/YooAsset/Runtime/DownloadSystem/Downloader/DownloaderBase.cs
index bdd34bd..1011134 100644
--- a/Assets/YooAsset/Runtime/DownloadSystem/Downloader/DownloaderBase.cs
+++ b/Assets/YooAsset/Runtime/DownloadSystem/Downloader/DownloaderBase.cs
@@ -98,19 +98,27 @@ namespace YooAsset
}
///
- /// 报告错误信息
+ /// 按照错误级别打印错误
///
public void ReportError()
{
- YooLogger.Error($"Failed to download : {_requestURL} Error : {_lastError}");
+ YooLogger.Error(GetLastError());
}
///
- /// 获取最近一条错误日志
+ /// 按照警告级别打印错误
+ ///
+ public void ReportWarning()
+ {
+ YooLogger.Warning(GetLastError());
+ }
+
+ ///
+ /// 获取最近发生的错误信息
///
public string GetLastError()
{
- return _lastError;
+ return $"Failed to download : {_requestURL} Error : {_lastError}";
}
}
}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/DownloadSystem/Downloader/FileDownloader.cs b/Assets/YooAsset/Runtime/DownloadSystem/Downloader/FileDownloader.cs
index e8edeae..55ef042 100644
--- a/Assets/YooAsset/Runtime/DownloadSystem/Downloader/FileDownloader.cs
+++ b/Assets/YooAsset/Runtime/DownloadSystem/Downloader/FileDownloader.cs
@@ -95,17 +95,21 @@ namespace YooAsset
}
else
{
- ReportError();
-
string cacheFilePath = _bundleInfo.GetCacheLoadPath();
if (File.Exists(cacheFilePath))
File.Delete(cacheFilePath);
// 失败后重新尝试
if (_failedTryAgain > 0)
+ {
+ ReportWarning();
_steps = ESteps.TryAgain;
+ }
else
+ {
+ ReportError();
_steps = ESteps.Failed;
+ }
}
// 释放下载器
diff --git a/Assets/YooAsset/Runtime/DownloadSystem/Downloader/HttpDownloader.cs b/Assets/YooAsset/Runtime/DownloadSystem/Downloader/HttpDownloader.cs
index a7c3a00..73a2cb4 100644
--- a/Assets/YooAsset/Runtime/DownloadSystem/Downloader/HttpDownloader.cs
+++ b/Assets/YooAsset/Runtime/DownloadSystem/Downloader/HttpDownloader.cs
@@ -211,13 +211,18 @@ namespace YooAsset
if (_threadDownloader.HasError())
{
_lastError = _threadDownloader.Error;
- ReportError();
// 失败后重新尝试
if (_failedTryAgain > 0)
+ {
+ ReportWarning();
_steps = ESteps.TryAgain;
+ }
else
+ {
+ ReportError();
_steps = ESteps.Failed;
+ }
}
else
{
@@ -240,7 +245,7 @@ namespace YooAsset
}
public override void Abort()
{
- if(IsDone() == false)
+ if (IsDone() == false)
{
_steps = ESteps.Failed;
_lastError = "user abort";
diff --git a/Assets/YooAsset/Runtime/PatchSystem/Operations/DownloaderOperation.cs b/Assets/YooAsset/Runtime/PatchSystem/Operations/DownloaderOperation.cs
index 5bb89ad..1a99adc 100644
--- a/Assets/YooAsset/Runtime/PatchSystem/Operations/DownloaderOperation.cs
+++ b/Assets/YooAsset/Runtime/PatchSystem/Operations/DownloaderOperation.cs
@@ -105,7 +105,6 @@ namespace YooAsset
// 检测是否下载失败
if (downloader.HasError())
{
- downloader.ReportError();
_removeList.Add(downloader);
_loadFailedList.Add(bundleInfo);
continue;
diff --git a/Assets/YooAsset/Runtime/Services/DefaultLocationServices.cs b/Assets/YooAsset/Runtime/Services/DefaultLocationServices.cs
index a021da4..dd9789e 100644
--- a/Assets/YooAsset/Runtime/Services/DefaultLocationServices.cs
+++ b/Assets/YooAsset/Runtime/Services/DefaultLocationServices.cs
@@ -84,7 +84,7 @@ namespace YooAsset
{
if (string.IsNullOrEmpty(location))
{
- Debug.LogError("location param is null or empty!");
+ YooLogger.Error("location param is null or empty!");
}
else
{
@@ -93,11 +93,11 @@ namespace YooAsset
if (index != -1)
{
if (location.Length == index + 1)
- Debug.LogWarning($"Found blank character in location : \"{location}\"");
+ YooLogger.Warning($"Found blank character in location : \"{location}\"");
}
if (location.IndexOfAny(Path.GetInvalidPathChars()) >= 0)
- Debug.LogWarning($"Found illegal character in location : \"{location}\"");
+ YooLogger.Warning($"Found illegal character in location : \"{location}\"");
}
}
#endif