Operation handles support error queries

操作句柄支持错误信息查询。
pull/5/head
hevinci 2022-04-24 18:30:35 +08:00
parent cbf142dbf8
commit 9bf22f2c79
19 changed files with 170 additions and 45 deletions

View File

@ -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();

View File

@ -32,6 +32,19 @@ namespace YooAsset
}
}
/// <summary>
/// 最近的错误信息
/// </summary>
public string LastError
{
get
{
if (IsValid == false)
return string.Empty;
return _provider.LastError;
}
}
/// <summary>
/// 加载进度
/// </summary>

View File

@ -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
{

View File

@ -29,6 +29,11 @@ namespace YooAsset
/// </summary>
public EStatus Status { protected set; get; }
/// <summary>
/// 最近的错误信息
/// </summary>
public string LastError { protected set; get; }
/// <summary>
/// 是否已经销毁
/// </summary>
@ -139,7 +144,7 @@ namespace YooAsset
// 销毁所有Providers
foreach (var provider in _providers)
{
provider.Destory();
provider.Destroy();
}
// 从列表里移除Providers

View File

@ -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
{

View File

@ -11,6 +11,7 @@ namespace YooAsset
/// </summary>
private readonly List<AssetBundleLoaderBase> _dependBundles;
public DependAssetBundleGrouper(string assetPath)
{
_dependBundles = AssetSystem.CreateDependAssetBundleLoaders(assetPath);
@ -29,6 +30,36 @@ namespace YooAsset
return true;
}
/// <summary>
/// 依赖资源包是否全部加载成功
/// </summary>
public bool IsSucceed()
{
foreach (var loader in _dependBundles)
{
if (loader.Status != AssetBundleLoaderBase.EStatus.Succeed)
{
return false;
}
}
return true;
}
/// <summary>
/// 获取某个加载失败的资源包错误信息
/// </summary>
public string GetLastError()
{
foreach (var loader in _dependBundles)
{
if (loader.Status != AssetBundleLoaderBase.EStatus.Succeed)
{
return loader.LastError;
}
}
return string.Empty;
}
/// <summary>
/// 主线程等待异步操作完毕
/// </summary>

View File

@ -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();
}
}

View File

@ -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)

View File

@ -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();
}
}

View File

@ -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();
}
}

View File

@ -34,6 +34,8 @@ namespace YooAsset
if (string.IsNullOrEmpty(guid))
{
Status = EStatus.Fail;
LastError = $"Not found asset : {AssetPath}";
YooLogger.Error(LastError);
InvokeCompletion();
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

View File

@ -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();
}
}

View File

@ -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

View File

@ -53,6 +53,11 @@ namespace YooAsset
/// </summary>
public EStatus Status { protected set; get; } = EStatus.None;
/// <summary>
/// 最近的错误信息
/// </summary>
public string LastError { protected set; get; } = string.Empty;
/// <summary>
/// 引用计数
/// </summary>
@ -105,7 +110,7 @@ namespace YooAsset
/// <summary>
/// 销毁资源对象
/// </summary>
public virtual void Destory()
public virtual void Destroy()
{
IsDestroyed = true;
}

View File

@ -98,19 +98,27 @@ namespace YooAsset
}
/// <summary>
/// 报告错误信息
/// 按照错误级别打印错误
/// </summary>
public void ReportError()
{
YooLogger.Error($"Failed to download : {_requestURL} Error : {_lastError}");
YooLogger.Error(GetLastError());
}
/// <summary>
/// 获取最近一条错误日志
/// 按照警告级别打印错误
/// </summary>
public void ReportWarning()
{
YooLogger.Warning(GetLastError());
}
/// <summary>
/// 获取最近发生的错误信息
/// </summary>
public string GetLastError()
{
return _lastError;
return $"Failed to download : {_requestURL} Error : {_lastError}";
}
}
}

View File

@ -95,18 +95,22 @@ 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;
}
}
// 释放下载器
DisposeWebRequest();

View File

@ -211,14 +211,19 @@ namespace YooAsset
if (_threadDownloader.HasError())
{
_lastError = _threadDownloader.Error;
ReportError();
// 失败后重新尝试
if (_failedTryAgain > 0)
{
ReportWarning();
_steps = ESteps.TryAgain;
}
else
{
ReportError();
_steps = ESteps.Failed;
}
}
else
{
DownloadSystem.CacheVerifyFile(_bundleInfo.Hash, _bundleInfo.BundleName);
@ -240,7 +245,7 @@ namespace YooAsset
}
public override void Abort()
{
if(IsDone() == false)
if (IsDone() == false)
{
_steps = ESteps.Failed;
_lastError = "user abort";

View File

@ -105,7 +105,6 @@ namespace YooAsset
// 检测是否下载失败
if (downloader.HasError())
{
downloader.ReportError();
_removeList.Add(downloader);
_loadFailedList.Add(bundleInfo);
continue;

View File

@ -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