2022-03-01 10:44:12 +08:00
|
|
|
|
using System.Collections;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
|
|
namespace YooAsset
|
|
|
|
|
|
{
|
2023-03-24 18:33:36 +08:00
|
|
|
|
internal sealed class BundledAssetProvider : ProviderBase
|
2022-03-01 10:44:12 +08:00
|
|
|
|
{
|
|
|
|
|
|
private AssetBundleRequest _cacheRequest;
|
|
|
|
|
|
|
2022-09-29 18:40:43 +08:00
|
|
|
|
public BundledAssetProvider(AssetSystemImpl impl, string providerGUID, AssetInfo assetInfo) : base(impl, providerGUID, assetInfo)
|
2022-03-01 10:44:12 +08:00
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
public override void Update()
|
|
|
|
|
|
{
|
2023-03-01 18:23:47 +08:00
|
|
|
|
DebugBeginRecording();
|
2022-10-22 17:46:46 +08:00
|
|
|
|
|
2022-03-01 10:44:12 +08:00
|
|
|
|
if (IsDone)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
2022-03-09 23:57:04 +08:00
|
|
|
|
if (Status == EStatus.None)
|
2022-03-01 10:44:12 +08:00
|
|
|
|
{
|
2022-03-09 23:57:04 +08:00
|
|
|
|
Status = EStatus.CheckBundle;
|
2022-03-01 10:44:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 1. 检测资源包
|
2022-03-09 23:57:04 +08:00
|
|
|
|
if (Status == EStatus.CheckBundle)
|
2022-03-01 10:44:12 +08:00
|
|
|
|
{
|
|
|
|
|
|
if (IsWaitForAsyncComplete)
|
|
|
|
|
|
{
|
2023-06-27 10:28:16 +08:00
|
|
|
|
DependBundles.WaitForAsyncComplete();
|
2022-03-01 10:44:12 +08:00
|
|
|
|
OwnerBundle.WaitForAsyncComplete();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-06-27 10:28:16 +08:00
|
|
|
|
if (DependBundles.IsDone() == false)
|
2022-03-01 10:44:12 +08:00
|
|
|
|
return;
|
|
|
|
|
|
if (OwnerBundle.IsDone() == false)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
2023-06-27 10:28:16 +08:00
|
|
|
|
if (DependBundles.IsSucceed() == false)
|
2022-03-01 10:44:12 +08:00
|
|
|
|
{
|
2022-11-26 15:31:35 +08:00
|
|
|
|
Status = EStatus.Failed;
|
2023-06-27 10:28:16 +08:00
|
|
|
|
LastError = DependBundles.GetLastError();
|
2022-03-01 10:44:12 +08:00
|
|
|
|
InvokeCompletion();
|
2022-04-24 18:30:35 +08:00
|
|
|
|
return;
|
2022-03-01 10:44:12 +08:00
|
|
|
|
}
|
2022-04-24 18:30:35 +08:00
|
|
|
|
|
2022-11-19 17:54:09 +08:00
|
|
|
|
if (OwnerBundle.Status != BundleLoaderBase.EStatus.Succeed)
|
2022-03-01 10:44:12 +08:00
|
|
|
|
{
|
2022-11-26 15:31:35 +08:00
|
|
|
|
Status = EStatus.Failed;
|
2022-04-24 18:30:35 +08:00
|
|
|
|
LastError = OwnerBundle.LastError;
|
|
|
|
|
|
InvokeCompletion();
|
|
|
|
|
|
return;
|
2022-03-01 10:44:12 +08:00
|
|
|
|
}
|
2022-04-24 18:30:35 +08:00
|
|
|
|
|
2022-08-12 14:30:23 +08:00
|
|
|
|
if (OwnerBundle.CacheBundle == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (OwnerBundle.IsDestroyed)
|
|
|
|
|
|
throw new System.Exception("Should never get here !");
|
2022-11-26 15:31:35 +08:00
|
|
|
|
Status = EStatus.Failed;
|
2022-08-15 11:55:13 +08:00
|
|
|
|
LastError = $"The bundle {OwnerBundle.MainBundleInfo.Bundle.BundleName} has been destroyed by unity bugs !";
|
2022-10-24 15:39:04 +08:00
|
|
|
|
YooLogger.Error(LastError);
|
2022-08-12 14:30:23 +08:00
|
|
|
|
InvokeCompletion();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-04-24 18:30:35 +08:00
|
|
|
|
Status = EStatus.Loading;
|
2022-03-01 10:44:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 2. 加载资源对象
|
2022-03-09 23:57:04 +08:00
|
|
|
|
if (Status == EStatus.Loading)
|
2022-03-01 10:44:12 +08:00
|
|
|
|
{
|
|
|
|
|
|
if (IsWaitForAsyncComplete)
|
|
|
|
|
|
{
|
2022-05-11 16:48:17 +08:00
|
|
|
|
if (MainAssetInfo.AssetType == null)
|
2022-05-13 21:58:23 +08:00
|
|
|
|
AssetObject = OwnerBundle.CacheBundle.LoadAsset(MainAssetInfo.AssetPath);
|
2022-03-01 10:44:12 +08:00
|
|
|
|
else
|
2022-05-13 21:58:23 +08:00
|
|
|
|
AssetObject = OwnerBundle.CacheBundle.LoadAsset(MainAssetInfo.AssetPath, MainAssetInfo.AssetType);
|
2022-03-01 10:44:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2022-05-11 16:48:17 +08:00
|
|
|
|
if (MainAssetInfo.AssetType == null)
|
2022-05-13 21:58:23 +08:00
|
|
|
|
_cacheRequest = OwnerBundle.CacheBundle.LoadAssetAsync(MainAssetInfo.AssetPath);
|
2022-03-01 10:44:12 +08:00
|
|
|
|
else
|
2022-05-13 21:58:23 +08:00
|
|
|
|
_cacheRequest = OwnerBundle.CacheBundle.LoadAssetAsync(MainAssetInfo.AssetPath, MainAssetInfo.AssetType);
|
2022-03-01 10:44:12 +08:00
|
|
|
|
}
|
2022-03-09 23:57:04 +08:00
|
|
|
|
Status = EStatus.Checking;
|
2022-03-01 10:44:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 3. 检测加载结果
|
2022-03-09 23:57:04 +08:00
|
|
|
|
if (Status == EStatus.Checking)
|
2022-03-01 10:44:12 +08:00
|
|
|
|
{
|
|
|
|
|
|
if (_cacheRequest != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (IsWaitForAsyncComplete)
|
|
|
|
|
|
{
|
|
|
|
|
|
// 强制挂起主线程(注意:该操作会很耗时)
|
2022-03-09 21:53:01 +08:00
|
|
|
|
YooLogger.Warning("Suspend the main thread to load unity asset.");
|
2022-03-01 10:44:12 +08:00
|
|
|
|
AssetObject = _cacheRequest.asset;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2022-12-13 11:46:39 +08:00
|
|
|
|
Progress = _cacheRequest.progress;
|
2022-03-01 10:44:12 +08:00
|
|
|
|
if (_cacheRequest.isDone == false)
|
|
|
|
|
|
return;
|
|
|
|
|
|
AssetObject = _cacheRequest.asset;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2022-11-26 15:31:35 +08:00
|
|
|
|
Status = AssetObject == null ? EStatus.Failed : EStatus.Succeed;
|
|
|
|
|
|
if (Status == EStatus.Failed)
|
2022-04-24 18:30:35 +08:00
|
|
|
|
{
|
2022-08-12 14:30:23 +08:00
|
|
|
|
if (MainAssetInfo.AssetType == null)
|
2022-08-15 11:55:13 +08:00
|
|
|
|
LastError = $"Failed to load asset : {MainAssetInfo.AssetPath} AssetType : null AssetBundle : {OwnerBundle.MainBundleInfo.Bundle.BundleName}";
|
2022-05-09 21:18:15 +08:00
|
|
|
|
else
|
2022-08-15 11:55:13 +08:00
|
|
|
|
LastError = $"Failed to load asset : {MainAssetInfo.AssetPath} AssetType : {MainAssetInfo.AssetType} AssetBundle : {OwnerBundle.MainBundleInfo.Bundle.BundleName}";
|
2022-04-24 18:30:35 +08:00
|
|
|
|
YooLogger.Error(LastError);
|
|
|
|
|
|
}
|
2022-03-01 10:44:12 +08:00
|
|
|
|
InvokeCompletion();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|