Update AssetSystem

加载方法容错提示。
pull/40/head
hevinci 2022-09-05 15:31:26 +08:00
parent ec25af8517
commit 53b53eb0a0
3 changed files with 33 additions and 7 deletions

View File

@ -141,7 +141,7 @@ namespace YooAsset
if (assetInfo.IsInvalid) if (assetInfo.IsInvalid)
{ {
CompletedProvider completedProvider = new CompletedProvider(assetInfo); CompletedProvider completedProvider = new CompletedProvider(assetInfo);
completedProvider.SetCompleted(); completedProvider.SetCompleted(assetInfo.Error);
return completedProvider.CreateHandle<SceneOperationHandle>(); return completedProvider.CreateHandle<SceneOperationHandle>();
} }
@ -176,7 +176,7 @@ namespace YooAsset
if (assetInfo.IsInvalid) if (assetInfo.IsInvalid)
{ {
CompletedProvider completedProvider = new CompletedProvider(assetInfo); CompletedProvider completedProvider = new CompletedProvider(assetInfo);
completedProvider.SetCompleted(); completedProvider.SetCompleted(assetInfo.Error);
return completedProvider.CreateHandle<AssetOperationHandle>(); return completedProvider.CreateHandle<AssetOperationHandle>();
} }
@ -202,7 +202,7 @@ namespace YooAsset
if (assetInfo.IsInvalid) if (assetInfo.IsInvalid)
{ {
CompletedProvider completedProvider = new CompletedProvider(assetInfo); CompletedProvider completedProvider = new CompletedProvider(assetInfo);
completedProvider.SetCompleted(); completedProvider.SetCompleted(assetInfo.Error);
return completedProvider.CreateHandle<SubAssetsOperationHandle>(); return completedProvider.CreateHandle<SubAssetsOperationHandle>();
} }

View File

@ -20,12 +20,12 @@ namespace YooAsset
public override void Update() public override void Update()
{ {
} }
public void SetCompleted() public void SetCompleted(string error)
{ {
if (Status == EStatus.None) if (Status == EStatus.None)
{ {
Status = EStatus.Fail; Status = EStatus.Fail;
LastError = MainAssetInfo.Error; LastError = error;
InvokeCompletion(); InvokeCompletion();
} }
} }

View File

@ -522,15 +522,17 @@ namespace YooAsset
return operation; return operation;
} }
#if UNITY_EDITOR
BundleInfo bundleInfo = _bundleServices.GetBundleInfo(assetInfo); BundleInfo bundleInfo = _bundleServices.GetBundleInfo(assetInfo);
if (bundleInfo.Bundle.IsRawFile == false) if (bundleInfo.Bundle.IsRawFile == false)
{ {
string error = $"Cannot load asset bundle file using {nameof(GetRawFileAsync)} interfaces !"; string error = $"Cannot load asset bundle file using {nameof(GetRawFileAsync)} method !";
YooLogger.Warning(error); YooLogger.Error(error);
RawFileOperation operation = new CompletedRawFileOperation(error, copyPath); RawFileOperation operation = new CompletedRawFileOperation(error, copyPath);
OperationSystem.StartOperation(operation); OperationSystem.StartOperation(operation);
return operation; return operation;
} }
#endif
if (_playMode == EPlayMode.EditorSimulateMode) if (_playMode == EPlayMode.EditorSimulateMode)
{ {
@ -667,6 +669,18 @@ namespace YooAsset
private static AssetOperationHandle LoadAssetInternal(AssetInfo assetInfo, bool waitForAsyncComplete) private static AssetOperationHandle LoadAssetInternal(AssetInfo assetInfo, bool waitForAsyncComplete)
{ {
#if UNITY_EDITOR
BundleInfo bundleInfo = _bundleServices.GetBundleInfo(assetInfo);
if (bundleInfo.Bundle.IsRawFile)
{
string error = $"Cannot load raw file using LoadAsset method !";
YooLogger.Error(error);
CompletedProvider completedProvider = new CompletedProvider(assetInfo);
completedProvider.SetCompleted(error);
return completedProvider.CreateHandle<AssetOperationHandle>();
}
#endif
var handle = AssetSystem.LoadAssetAsync(assetInfo); var handle = AssetSystem.LoadAssetAsync(assetInfo);
if (waitForAsyncComplete) if (waitForAsyncComplete)
handle.WaitForAsyncComplete(); handle.WaitForAsyncComplete();
@ -751,6 +765,18 @@ namespace YooAsset
private static SubAssetsOperationHandle LoadSubAssetsInternal(AssetInfo assetInfo, bool waitForAsyncComplete) private static SubAssetsOperationHandle LoadSubAssetsInternal(AssetInfo assetInfo, bool waitForAsyncComplete)
{ {
#if UNITY_EDITOR
BundleInfo bundleInfo = _bundleServices.GetBundleInfo(assetInfo);
if (bundleInfo.Bundle.IsRawFile)
{
string error = $"Cannot load raw file using LoadSubAssets method !";
YooLogger.Error(error);
CompletedProvider completedProvider = new CompletedProvider(assetInfo);
completedProvider.SetCompleted(error);
return completedProvider.CreateHandle<SubAssetsOperationHandle>();
}
#endif
var handle = AssetSystem.LoadSubAssetsAsync(assetInfo); var handle = AssetSystem.LoadSubAssetsAsync(assetInfo);
if (waitForAsyncComplete) if (waitForAsyncComplete)
handle.WaitForAsyncComplete(); handle.WaitForAsyncComplete();