Optimized asset system and patch system framework

优化了资源定位不正确导致的错误报告方式。
YooAssets.ProcessOperation()重命名为YooAssets.StartOperation()
YooAssets.GetBundleInfo()已经移除方法。
YooAssets.IsNeedDownloadFromRemote()新增加方法。
This commit is contained in:
hevinci
2022-05-11 16:48:17 +08:00
parent 67eeae31c7
commit 4cad587609
34 changed files with 726 additions and 573 deletions
@@ -17,8 +17,7 @@ namespace YooAsset
}
}
public BundledAssetProvider(string assetPath, System.Type assetType)
: base(assetPath, assetType)
public BundledAssetProvider(AssetInfo assetInfo) : base(assetInfo)
{
}
public override void Update()
@@ -36,19 +35,19 @@ namespace YooAsset
{
if (IsWaitForAsyncComplete)
{
DependBundles.WaitForAsyncComplete();
DependBundleGroup.WaitForAsyncComplete();
OwnerBundle.WaitForAsyncComplete();
}
if (DependBundles.IsDone() == false)
if (DependBundleGroup.IsDone() == false)
return;
if (OwnerBundle.IsDone() == false)
return;
if (DependBundles.IsSucceed() == false)
if (DependBundleGroup.IsSucceed() == false)
{
Status = EStatus.Fail;
LastError = DependBundles.GetLastError();
LastError = DependBundleGroup.GetLastError();
InvokeCompletion();
return;
}
@@ -69,17 +68,17 @@ namespace YooAsset
{
if (IsWaitForAsyncComplete)
{
if (AssetType == null)
AssetObject = OwnerBundle.CacheBundle.LoadAsset(AssetName);
if (MainAssetInfo.AssetType == null)
AssetObject = OwnerBundle.CacheBundle.LoadAsset(MainAssetInfo.AssetName);
else
AssetObject = OwnerBundle.CacheBundle.LoadAsset(AssetName, AssetType);
AssetObject = OwnerBundle.CacheBundle.LoadAsset(MainAssetInfo.AssetName, MainAssetInfo.AssetType);
}
else
{
if (AssetType == null)
_cacheRequest = OwnerBundle.CacheBundle.LoadAssetAsync(AssetName);
if (MainAssetInfo.AssetType == null)
_cacheRequest = OwnerBundle.CacheBundle.LoadAssetAsync(MainAssetInfo.AssetName);
else
_cacheRequest = OwnerBundle.CacheBundle.LoadAssetAsync(AssetName, AssetType);
_cacheRequest = OwnerBundle.CacheBundle.LoadAssetAsync(MainAssetInfo.AssetName, MainAssetInfo.AssetType);
}
Status = EStatus.Checking;
}
@@ -106,10 +105,10 @@ namespace YooAsset
Status = AssetObject == null ? EStatus.Fail : EStatus.Success;
if (Status == EStatus.Fail)
{
if(AssetType == null)
LastError = $"Failed to load asset : {AssetName} AssetType : null AssetBundle : {OwnerBundle.BundleFileInfo.BundleName}";
if(MainAssetInfo.AssetType == null)
LastError = $"Failed to load asset : {MainAssetInfo.AssetName} AssetType : null AssetBundle : {OwnerBundle.MainBundleInfo.BundleName}";
else
LastError = $"Failed to load asset : {AssetName} AssetType : {AssetType} AssetBundle : {OwnerBundle.BundleFileInfo.BundleName}";
LastError = $"Failed to load asset : {MainAssetInfo.AssetName} AssetType : {MainAssetInfo.AssetType} AssetBundle : {OwnerBundle.MainBundleInfo.BundleName}";
YooLogger.Error(LastError);
}
InvokeCompletion();
@@ -6,15 +6,17 @@ namespace YooAsset
internal abstract class BundledProvider : ProviderBase
{
protected AssetBundleLoaderBase OwnerBundle { private set; get; }
protected DependAssetBundleGroup DependBundles { private set; get; }
protected DependAssetBundleGroup DependBundleGroup { private set; get; }
public BundledProvider(string assetPath, System.Type assetType) : base(assetPath, assetType)
public BundledProvider(AssetInfo assetInfo) : base(assetInfo)
{
OwnerBundle = AssetSystem.CreateOwnerAssetBundleLoader(assetPath);
OwnerBundle = AssetSystem.CreateOwnerAssetBundleLoader(assetInfo);
OwnerBundle.Reference();
OwnerBundle.AddProvider(this);
DependBundles = new DependAssetBundleGroup(assetPath);
DependBundles.Reference();
var dependBundles = AssetSystem.CreateDependAssetBundleLoaders(assetInfo);
DependBundleGroup = new DependAssetBundleGroup(dependBundles);
DependBundleGroup.Reference();
}
public override void Destroy()
{
@@ -26,10 +28,10 @@ namespace YooAsset
OwnerBundle.Release();
OwnerBundle = null;
}
if (DependBundles != null)
if (DependBundleGroup != null)
{
DependBundles.Release();
DependBundles = null;
DependBundleGroup.Release();
DependBundleGroup = null;
}
}
@@ -39,12 +41,12 @@ namespace YooAsset
internal void GetBundleDebugInfos(List<DebugBundleInfo> output)
{
var bundleInfo = new DebugBundleInfo();
bundleInfo.BundleName = OwnerBundle.BundleFileInfo.BundleName;
bundleInfo.BundleName = OwnerBundle.MainBundleInfo.BundleName;
bundleInfo.RefCount = OwnerBundle.RefCount;
bundleInfo.Status = OwnerBundle.Status;
output.Add(bundleInfo);
DependBundles.GetBundleDebugInfos(output);
DependBundleGroup.GetBundleDebugInfos(output);
}
}
}
@@ -1,5 +1,6 @@
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using UnityEngine.SceneManagement;
@@ -22,11 +23,10 @@ namespace YooAsset
}
}
public BundledSceneProvider(string scenePath, LoadSceneMode sceneMode, bool activateOnLoad, int priority)
: base(scenePath, null)
public BundledSceneProvider(AssetInfo assetInfo, LoadSceneMode sceneMode, bool activateOnLoad, int priority) : base(assetInfo)
{
SceneMode = sceneMode;
_sceneName = System.IO.Path.GetFileNameWithoutExtension(scenePath);
_sceneName = Path.GetFileNameWithoutExtension(assetInfo.AssetPath);
_activateOnLoad = activateOnLoad;
_priority = priority;
}
@@ -43,15 +43,15 @@ namespace YooAsset
// 1. 检测资源包
if (Status == EStatus.CheckBundle)
{
if (DependBundles.IsDone() == false)
if (DependBundleGroup.IsDone() == false)
return;
if (OwnerBundle.IsDone() == false)
return;
if (DependBundles.IsSucceed() == false)
if (DependBundleGroup.IsSucceed() == false)
{
Status = EStatus.Fail;
LastError = DependBundles.GetLastError();
LastError = DependBundleGroup.GetLastError();
InvokeCompletion();
return;
}
@@ -98,7 +98,7 @@ namespace YooAsset
Status = SceneObject.IsValid() ? EStatus.Success : EStatus.Fail;
if(Status == EStatus.Fail)
{
LastError = $"The load scene is invalid : {AssetPath}";
LastError = $"The load scene is invalid : {MainAssetInfo.AssetPath}";
YooLogger.Error(LastError);
}
InvokeCompletion();
@@ -17,8 +17,7 @@ namespace YooAsset
}
}
public BundledSubAssetsProvider(string assetPath, System.Type assetType)
: base(assetPath, assetType)
public BundledSubAssetsProvider(AssetInfo assetInfo) : base(assetInfo)
{
}
public override void Update()
@@ -36,19 +35,19 @@ namespace YooAsset
{
if (IsWaitForAsyncComplete)
{
DependBundles.WaitForAsyncComplete();
DependBundleGroup.WaitForAsyncComplete();
OwnerBundle.WaitForAsyncComplete();
}
if (DependBundles.IsDone() == false)
if (DependBundleGroup.IsDone() == false)
return;
if (OwnerBundle.IsDone() == false)
return;
if (DependBundles.IsSucceed() == false)
if (DependBundleGroup.IsSucceed() == false)
{
Status = EStatus.Fail;
LastError = DependBundles.GetLastError();
LastError = DependBundleGroup.GetLastError();
InvokeCompletion();
return;
}
@@ -69,17 +68,17 @@ namespace YooAsset
{
if (IsWaitForAsyncComplete)
{
if (AssetType == null)
AllAssetObjects = OwnerBundle.CacheBundle.LoadAssetWithSubAssets(AssetName);
if (MainAssetInfo.AssetType == null)
AllAssetObjects = OwnerBundle.CacheBundle.LoadAssetWithSubAssets(MainAssetInfo.AssetName);
else
AllAssetObjects = OwnerBundle.CacheBundle.LoadAssetWithSubAssets(AssetName, AssetType);
AllAssetObjects = OwnerBundle.CacheBundle.LoadAssetWithSubAssets(MainAssetInfo.AssetName, MainAssetInfo.AssetType);
}
else
{
if (AssetType == null)
_cacheRequest = OwnerBundle.CacheBundle.LoadAssetWithSubAssetsAsync(AssetName);
if (MainAssetInfo.AssetType == null)
_cacheRequest = OwnerBundle.CacheBundle.LoadAssetWithSubAssetsAsync(MainAssetInfo.AssetName);
else
_cacheRequest = OwnerBundle.CacheBundle.LoadAssetWithSubAssetsAsync(AssetName, AssetType);
_cacheRequest = OwnerBundle.CacheBundle.LoadAssetWithSubAssetsAsync(MainAssetInfo.AssetName, MainAssetInfo.AssetType);
}
Status = EStatus.Checking;
}
@@ -106,10 +105,10 @@ namespace YooAsset
Status = AllAssetObjects == null ? EStatus.Fail : EStatus.Success;
if (Status == EStatus.Fail)
{
if (AssetType == null)
LastError = $"Failed to load sub assets : {AssetName} AssetType : null AssetBundle : {OwnerBundle.BundleFileInfo.BundleName}";
if (MainAssetInfo.AssetType == null)
LastError = $"Failed to load sub assets : {MainAssetInfo.AssetName} AssetType : null AssetBundle : {OwnerBundle.MainBundleInfo.BundleName}";
else
LastError = $"Failed to load sub assets : {AssetName} AssetType : {AssetType} AssetBundle : {OwnerBundle.BundleFileInfo.BundleName}";
LastError = $"Failed to load sub assets : {MainAssetInfo.AssetName} AssetType : {MainAssetInfo.AssetType} AssetBundle : {OwnerBundle.MainBundleInfo.BundleName}";
YooLogger.Error(LastError);
}
InvokeCompletion();
@@ -0,0 +1,33 @@
namespace YooAsset
{
internal sealed class CompletedProvider : ProviderBase
{
public override float Progress
{
get
{
if (IsDone)
return 1f;
else
return 0;
}
}
public CompletedProvider(AssetInfo assetInfo) : base(assetInfo)
{
}
public override void Update()
{
if (IsDone)
return;
if (Status == EStatus.None)
{
Status = EStatus.Fail;
LastError = MainAssetInfo.Error;
InvokeCompletion();
}
}
}
}
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 8e64fd2ee771f7d498838ebf375a9531
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
@@ -17,8 +17,7 @@ namespace YooAsset
}
}
public DatabaseAssetProvider(string assetPath, System.Type assetType)
: base(assetPath, assetType)
public DatabaseAssetProvider(AssetInfo assetInfo) : base(assetInfo)
{
}
public override void Update()
@@ -30,11 +29,11 @@ namespace YooAsset
if (Status == EStatus.None)
{
// 检测资源文件是否存在
string guid = UnityEditor.AssetDatabase.AssetPathToGUID(AssetPath);
string guid = UnityEditor.AssetDatabase.AssetPathToGUID(MainAssetInfo.AssetPath);
if (string.IsNullOrEmpty(guid))
{
Status = EStatus.Fail;
LastError = $"Not found asset : {AssetPath}";
LastError = $"Not found asset : {MainAssetInfo.AssetPath}";
YooLogger.Error(LastError);
InvokeCompletion();
return;
@@ -50,10 +49,10 @@ namespace YooAsset
// 1. 加载资源对象
if (Status == EStatus.Loading)
{
if (AssetType == null)
AssetObject = UnityEditor.AssetDatabase.LoadMainAssetAtPath(AssetPath);
if (MainAssetInfo.AssetType == null)
AssetObject = UnityEditor.AssetDatabase.LoadMainAssetAtPath(MainAssetInfo.AssetPath);
else
AssetObject = UnityEditor.AssetDatabase.LoadAssetAtPath(AssetPath, AssetType);
AssetObject = UnityEditor.AssetDatabase.LoadAssetAtPath(MainAssetInfo.AssetPath, MainAssetInfo.AssetType);
Status = EStatus.Checking;
}
@@ -66,7 +65,7 @@ namespace YooAsset
{
AssetObject = null;
Status = EStatus.Fail;
LastError = $"The loaded asset object is not main asset : {AssetPath} AssetType : {AssetType}";
LastError = $"The loaded asset object is not main asset : {MainAssetInfo.AssetPath} AssetType : {MainAssetInfo.AssetType}";
YooLogger.Error(LastError);
InvokeCompletion();
return;
@@ -76,12 +75,12 @@ namespace YooAsset
Status = AssetObject == null ? EStatus.Fail : EStatus.Success;
if (Status == EStatus.Fail)
{
if (AssetType == null)
LastError = $"Failed to load asset object : {AssetPath} AssetType : null";
if (MainAssetInfo.AssetType == null)
LastError = $"Failed to load asset object : {MainAssetInfo.AssetPath} AssetType : null";
else
LastError = $"Failed to load asset object : {AssetPath} AssetType : {AssetType}";
LastError = $"Failed to load asset object : {MainAssetInfo.AssetPath} AssetType : {MainAssetInfo.AssetType}";
YooLogger.Error(LastError);
}
}
InvokeCompletion();
}
#endif
@@ -19,8 +19,7 @@ namespace YooAsset
}
}
public DatabaseSceneProvider(string scenePath, LoadSceneMode sceneMode, bool activateOnLoad, int priority)
: base(scenePath, null)
public DatabaseSceneProvider(AssetInfo assetInfo, LoadSceneMode sceneMode, bool activateOnLoad, int priority) : base(assetInfo)
{
SceneMode = sceneMode;
_activateOnLoad = activateOnLoad;
@@ -42,7 +41,7 @@ namespace YooAsset
{
LoadSceneParameters loadSceneParameters = new LoadSceneParameters();
loadSceneParameters.loadSceneMode = SceneMode;
_asyncOp = UnityEditor.SceneManagement.EditorSceneManager.LoadSceneAsyncInPlayMode(AssetPath, loadSceneParameters);
_asyncOp = UnityEditor.SceneManagement.EditorSceneManager.LoadSceneAsyncInPlayMode(MainAssetInfo.AssetPath, loadSceneParameters);
if (_asyncOp != null)
{
_asyncOp.allowSceneActivation = true;
@@ -52,7 +51,7 @@ namespace YooAsset
else
{
Status = EStatus.Fail;
LastError = $"Failed to load scene : {AssetPath}";
LastError = $"Failed to load scene : {MainAssetInfo.AssetPath}";
YooLogger.Error(LastError);
InvokeCompletion();
}
@@ -70,7 +69,7 @@ namespace YooAsset
Status = SceneObject.IsValid() ? EStatus.Success : EStatus.Fail;
if (Status == EStatus.Fail)
{
LastError = $"The loaded scene is invalid : {AssetPath}";
LastError = $"The loaded scene is invalid : {MainAssetInfo.AssetPath}";
YooLogger.Error(LastError);
}
InvokeCompletion();
@@ -17,8 +17,7 @@ namespace YooAsset
}
}
public DatabaseSubAssetsProvider(string assetPath, System.Type assetType)
: base(assetPath, assetType)
public DatabaseSubAssetsProvider(AssetInfo assetInfo) : base(assetInfo)
{
}
public override void Update()
@@ -30,11 +29,11 @@ namespace YooAsset
if (Status == EStatus.None)
{
// 检测资源文件是否存在
string guid = UnityEditor.AssetDatabase.AssetPathToGUID(AssetPath);
string guid = UnityEditor.AssetDatabase.AssetPathToGUID(MainAssetInfo.AssetPath);
if (string.IsNullOrEmpty(guid))
{
Status = EStatus.Fail;
LastError = $"Not found asset : {AssetPath}";
LastError = $"Not found asset : {MainAssetInfo.AssetPath}";
YooLogger.Error(LastError);
InvokeCompletion();
return;
@@ -50,17 +49,17 @@ namespace YooAsset
// 1. 加载资源对象
if (Status == EStatus.Loading)
{
if (AssetType == null)
if (MainAssetInfo.AssetType == null)
{
AllAssetObjects = UnityEditor.AssetDatabase.LoadAllAssetRepresentationsAtPath(AssetPath);
AllAssetObjects = UnityEditor.AssetDatabase.LoadAllAssetRepresentationsAtPath(MainAssetInfo.AssetPath);
}
else
{
UnityEngine.Object[] findAssets = UnityEditor.AssetDatabase.LoadAllAssetRepresentationsAtPath(AssetPath);
UnityEngine.Object[] findAssets = UnityEditor.AssetDatabase.LoadAllAssetRepresentationsAtPath(MainAssetInfo.AssetPath);
List<UnityEngine.Object> result = new List<Object>(findAssets.Length);
foreach (var findAsset in findAssets)
{
if (AssetType.IsAssignableFrom(findAsset.GetType()))
if (MainAssetInfo.AssetType.IsAssignableFrom(findAsset.GetType()))
result.Add(findAsset);
}
AllAssetObjects = result.ToArray();
@@ -74,10 +73,10 @@ namespace YooAsset
Status = AllAssetObjects == null ? EStatus.Fail : EStatus.Success;
if (Status == EStatus.Fail)
{
if (AssetType == null)
LastError = $"Failed to load sub assets : {AssetPath} AssetType : null";
if (MainAssetInfo.AssetType == null)
LastError = $"Failed to load sub assets : {MainAssetInfo.AssetPath} AssetType : null";
else
LastError = $"Failed to load sub assets : {AssetPath} AssetType : {AssetType}";
LastError = $"Failed to load sub assets : {MainAssetInfo.AssetPath} AssetType : {MainAssetInfo.AssetType}";
YooLogger.Error(LastError);
}
InvokeCompletion();
@@ -18,19 +18,9 @@ namespace YooAsset
}
/// <summary>
/// 资源路径
/// 资源信息
/// </summary>
public string AssetPath { private set; get; }
/// <summary>
/// 资源对象的名称
/// </summary>
public string AssetName { private set; get; }
/// <summary>
/// 资源对象的类型
/// </summary>
public System.Type AssetType { private set; get; }
public AssetInfo MainAssetInfo { private set; get; }
/// <summary>
/// 获取的资源对象
@@ -95,11 +85,9 @@ namespace YooAsset
private readonly List<OperationHandleBase> _handles = new List<OperationHandleBase>();
public ProviderBase(string assetPath, System.Type assetType)
public ProviderBase(AssetInfo assetInfo)
{
AssetPath = assetPath;
AssetName = System.IO.Path.GetFileName(assetPath);
AssetType = assetType;
MainAssetInfo = assetInfo;
}
/// <summary>
@@ -126,25 +114,38 @@ namespace YooAsset
return RefCount <= 0;
}
/// <summary>
/// 是否为场景提供者
/// </summary>
public bool IsSceneProvider()
{
if (this is BundledSceneProvider || this is DatabaseSceneProvider)
return true;
else
return false;
}
/// <summary>
/// 创建操作句柄
/// </summary>
/// <returns></returns>
public OperationHandleBase CreateHandle()
public T CreateHandle<T>() where T : OperationHandleBase
{
// 引用计数增加
RefCount++;
OperationHandleBase handle;
if (IsSceneProvider())
if (typeof(T) == typeof(AssetOperationHandle))
handle = new AssetOperationHandle(this);
else if (typeof(T) == typeof(SceneOperationHandle))
handle = new SceneOperationHandle(this);
else if (IsSubAssetsProvider())
else if (typeof(T) == typeof(SubAssetsOperationHandle))
handle = new SubAssetsOperationHandle(this);
else
handle = new AssetOperationHandle(this);
throw new System.NotImplementedException();
_handles.Add(handle);
return handle;
return handle as T;
}
/// <summary>
@@ -175,7 +176,7 @@ namespace YooAsset
// 验证结果
if (IsDone == false)
{
YooLogger.Warning($"WaitForAsyncComplete failed to loading : {AssetPath}");
YooLogger.Warning($"WaitForAsyncComplete failed to loading : {MainAssetInfo.AssetPath}");
}
}
@@ -196,21 +197,6 @@ namespace YooAsset
}
}
public bool IsSceneProvider()
{
if (this is BundledSceneProvider || this is DatabaseSceneProvider)
return true;
else
return false;
}
public bool IsSubAssetsProvider()
{
if (this is BundledSubAssetsProvider || this is DatabaseSubAssetsProvider)
return true;
else
return false;
}
#region 异步编程相关
private TaskCompletionSource<object> _taskCompletionSource;
protected void InvokeCompletion()