Files
YooAsset/Assets/YooAsset/Runtime/AssetSystem/Provider/DatabaseAssetProvider.cs

76 lines
1.8 KiB
C#
Raw Normal View History

2022-03-01 10:44:12 +08:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace YooAsset
{
2022-03-22 20:47:22 +08:00
internal sealed class DatabaseAssetProvider : ProviderBase
2022-03-01 10:44:12 +08:00
{
public override float Progress
{
get
{
if (IsDone)
return 1f;
2022-03-01 10:44:12 +08:00
else
return 0;
}
}
public DatabaseAssetProvider(string providerGUID, AssetInfo assetInfo) : base(providerGUID, assetInfo)
2022-03-01 10:44:12 +08:00
{
}
public override void Update()
{
#if UNITY_EDITOR
if (IsDone)
return;
2022-03-09 23:57:04 +08:00
if (Status == EStatus.None)
2022-03-01 10:44:12 +08:00
{
// 检测资源文件是否存在
string guid = UnityEditor.AssetDatabase.AssetPathToGUID(MainAssetInfo.AssetPath);
2022-03-01 10:44:12 +08:00
if (string.IsNullOrEmpty(guid))
{
2022-03-09 23:57:04 +08:00
Status = EStatus.Fail;
LastError = $"Not found asset : {MainAssetInfo.AssetPath}";
YooLogger.Error(LastError);
2022-03-01 10:44:12 +08:00
InvokeCompletion();
return;
}
Status = EStatus.Loading;
2022-03-01 10:44:12 +08:00
// 注意:模拟异步加载效果提前返回
if (IsWaitForAsyncComplete == false)
return;
}
// 1. 加载资源对象
2022-03-09 23:57:04 +08:00
if (Status == EStatus.Loading)
2022-03-01 10:44:12 +08:00
{
if (MainAssetInfo.AssetType == null)
AssetObject = UnityEditor.AssetDatabase.LoadMainAssetAtPath(MainAssetInfo.AssetPath);
else
AssetObject = UnityEditor.AssetDatabase.LoadAssetAtPath(MainAssetInfo.AssetPath, MainAssetInfo.AssetType);
2022-03-09 23:57:04 +08:00
Status = EStatus.Checking;
2022-03-01 10:44:12 +08:00
}
// 2. 检测加载结果
2022-03-09 23:57:04 +08:00
if (Status == EStatus.Checking)
2022-03-01 10:44:12 +08:00
{
2022-03-09 23:57:04 +08:00
Status = AssetObject == null ? EStatus.Fail : EStatus.Success;
if (Status == EStatus.Fail)
{
if (MainAssetInfo.AssetType == null)
LastError = $"Failed to load asset object : {MainAssetInfo.AssetPath} AssetType : null";
2022-05-09 21:18:15 +08:00
else
LastError = $"Failed to load asset object : {MainAssetInfo.AssetPath} AssetType : {MainAssetInfo.AssetType}";
YooLogger.Error(LastError);
}
2022-03-01 10:44:12 +08:00
InvokeCompletion();
}
#endif
}
}
}