refactor the runtime code

重构了运行时代码,支持全新的文件系统。
This commit is contained in:
何冠峰
2024-07-04 20:36:26 +08:00
parent 2987d356b6
commit ff02da5c54
313 changed files with 9889 additions and 7234 deletions
@@ -6,6 +6,7 @@ namespace YooAsset
{
internal sealed class BundledAllAssetsProvider : ProviderBase
{
private AssetBundle _assetBundle;
private AssetBundleRequest _cacheRequest;
public BundledAllAssetsProvider(ResourceManager manager, string providerGUID, AssetInfo assetInfo) : base(manager, providerGUID, assetInfo)
@@ -30,54 +31,62 @@ namespace YooAsset
{
if (IsWaitForAsyncComplete)
{
DependBundles.WaitForAsyncComplete();
OwnerBundle.WaitForAsyncComplete();
DependLoaders.WaitForAsyncComplete();
FileLoader.WaitForAsyncComplete();
}
if (DependBundles.IsDone() == false)
if (DependLoaders.IsDone() == false)
return;
if (OwnerBundle.IsDone() == false)
if (FileLoader.IsDone() == false)
return;
if (DependBundles.IsSucceed() == false)
if (DependLoaders.IsSucceed() == false)
{
string error = DependBundles.GetLastError();
string error = DependLoaders.GetLastError();
InvokeCompletion(error, EOperationStatus.Failed);
return;
}
if (OwnerBundle.Status != BundleLoaderBase.EStatus.Succeed)
if (FileLoader.Status != BundleFileLoader.EStatus.Succeed)
{
string error = OwnerBundle.LastError;
string error = FileLoader.LastError;
InvokeCompletion(error, EOperationStatus.Failed);
return;
}
if (OwnerBundle.CacheBundle == null)
if (FileLoader.Result == null)
{
ProcessCacheBundleException();
ProcessFatalEvent();
return;
}
if (FileLoader.Result is AssetBundle == false)
{
string error = "Try load raw file using load assetbundle method !";
InvokeCompletion(error, EOperationStatus.Failed);
return;
}
_assetBundle = FileLoader.Result as AssetBundle;
_steps = ESteps.Loading;
}
// 2. 加载资源对象
if (_steps == ESteps.Loading)
{
if (IsWaitForAsyncComplete || IsForceDestroyComplete)
if (IsWaitForAsyncComplete)
{
if (MainAssetInfo.AssetType == null)
AllAssetObjects = OwnerBundle.CacheBundle.LoadAllAssets();
AllAssetObjects = _assetBundle.LoadAllAssets();
else
AllAssetObjects = OwnerBundle.CacheBundle.LoadAllAssets(MainAssetInfo.AssetType);
AllAssetObjects = _assetBundle.LoadAllAssets(MainAssetInfo.AssetType);
}
else
{
if (MainAssetInfo.AssetType == null)
_cacheRequest = OwnerBundle.CacheBundle.LoadAllAssetsAsync();
_cacheRequest = _assetBundle.LoadAllAssetsAsync();
else
_cacheRequest = OwnerBundle.CacheBundle.LoadAllAssetsAsync(MainAssetInfo.AssetType);
_cacheRequest = _assetBundle.LoadAllAssetsAsync(MainAssetInfo.AssetType);
}
_steps = ESteps.Checking;
}
@@ -87,7 +96,7 @@ namespace YooAsset
{
if (_cacheRequest != null)
{
if (IsWaitForAsyncComplete || IsForceDestroyComplete)
if (IsWaitForAsyncComplete)
{
// 强制挂起主线程(注意:该操作会很耗时)
YooLogger.Warning("Suspend the main thread to load unity asset.");
@@ -106,9 +115,9 @@ namespace YooAsset
{
string error;
if (MainAssetInfo.AssetType == null)
error = $"Failed to load all assets : {MainAssetInfo.AssetPath} AssetType : null AssetBundle : {OwnerBundle.MainBundleInfo.Bundle.BundleName}";
error = $"Failed to load all assets : {MainAssetInfo.AssetPath} AssetType : null AssetBundle : {FileLoader.MainBundleInfo.Bundle.BundleName}";
else
error = $"Failed to load all assets : {MainAssetInfo.AssetPath} AssetType : {MainAssetInfo.AssetType} AssetBundle : {OwnerBundle.MainBundleInfo.Bundle.BundleName}";
error = $"Failed to load all assets : {MainAssetInfo.AssetPath} AssetType : {MainAssetInfo.AssetType} AssetBundle : {FileLoader.MainBundleInfo.Bundle.BundleName}";
YooLogger.Error(error);
InvokeCompletion(error, EOperationStatus.Failed);
}
@@ -6,6 +6,7 @@ namespace YooAsset
{
internal sealed class BundledAssetProvider : ProviderBase
{
private AssetBundle _assetBundle;
private AssetBundleRequest _cacheRequest;
public BundledAssetProvider(ResourceManager manager, string providerGUID, AssetInfo assetInfo) : base(manager, providerGUID, assetInfo)
@@ -30,54 +31,62 @@ namespace YooAsset
{
if (IsWaitForAsyncComplete)
{
DependBundles.WaitForAsyncComplete();
OwnerBundle.WaitForAsyncComplete();
DependLoaders.WaitForAsyncComplete();
FileLoader.WaitForAsyncComplete();
}
if (DependBundles.IsDone() == false)
if (DependLoaders.IsDone() == false)
return;
if (OwnerBundle.IsDone() == false)
if (FileLoader.IsDone() == false)
return;
if (DependBundles.IsSucceed() == false)
if (DependLoaders.IsSucceed() == false)
{
string error = DependBundles.GetLastError();
string error = DependLoaders.GetLastError();
InvokeCompletion(error, EOperationStatus.Failed);
return;
}
if (OwnerBundle.Status != BundleLoaderBase.EStatus.Succeed)
if (FileLoader.Status != BundleFileLoader.EStatus.Succeed)
{
string error = OwnerBundle.LastError;
string error = FileLoader.LastError;
InvokeCompletion(error, EOperationStatus.Failed);
return;
}
if (OwnerBundle.CacheBundle == null)
if (FileLoader.Result == null)
{
ProcessCacheBundleException();
ProcessFatalEvent();
return;
}
if (FileLoader.Result is AssetBundle == false)
{
string error = "Try load raw file using load assetbundle method !";
InvokeCompletion(error, EOperationStatus.Failed);
return;
}
_assetBundle = FileLoader.Result as AssetBundle;
_steps = ESteps.Loading;
}
// 2. 加载资源对象
if (_steps == ESteps.Loading)
{
if (IsWaitForAsyncComplete || IsForceDestroyComplete)
if (IsWaitForAsyncComplete)
{
if (MainAssetInfo.AssetType == null)
AssetObject = OwnerBundle.CacheBundle.LoadAsset(MainAssetInfo.AssetPath);
AssetObject = _assetBundle.LoadAsset(MainAssetInfo.AssetPath);
else
AssetObject = OwnerBundle.CacheBundle.LoadAsset(MainAssetInfo.AssetPath, MainAssetInfo.AssetType);
AssetObject = _assetBundle.LoadAsset(MainAssetInfo.AssetPath, MainAssetInfo.AssetType);
}
else
{
if (MainAssetInfo.AssetType == null)
_cacheRequest = OwnerBundle.CacheBundle.LoadAssetAsync(MainAssetInfo.AssetPath);
_cacheRequest = _assetBundle.LoadAssetAsync(MainAssetInfo.AssetPath);
else
_cacheRequest = OwnerBundle.CacheBundle.LoadAssetAsync(MainAssetInfo.AssetPath, MainAssetInfo.AssetType);
_cacheRequest = _assetBundle.LoadAssetAsync(MainAssetInfo.AssetPath, MainAssetInfo.AssetType);
}
_steps = ESteps.Checking;
}
@@ -87,7 +96,7 @@ namespace YooAsset
{
if (_cacheRequest != null)
{
if (IsWaitForAsyncComplete || IsForceDestroyComplete)
if (IsWaitForAsyncComplete)
{
// 强制挂起主线程(注意:该操作会很耗时)
YooLogger.Warning("Suspend the main thread to load unity asset.");
@@ -106,9 +115,9 @@ namespace YooAsset
{
string error;
if (MainAssetInfo.AssetType == null)
error = $"Failed to load asset : {MainAssetInfo.AssetPath} AssetType : null AssetBundle : {OwnerBundle.MainBundleInfo.Bundle.BundleName}";
error = $"Failed to load asset : {MainAssetInfo.AssetPath} AssetType : null AssetBundle : {FileLoader.MainBundleInfo.Bundle.BundleName}";
else
error = $"Failed to load asset : {MainAssetInfo.AssetPath} AssetType : {MainAssetInfo.AssetType} AssetBundle : {OwnerBundle.MainBundleInfo.Bundle.BundleName}";
error = $"Failed to load asset : {MainAssetInfo.AssetPath} AssetType : {MainAssetInfo.AssetType} AssetBundle : {FileLoader.MainBundleInfo.Bundle.BundleName}";
YooLogger.Error(error);
InvokeCompletion(error, EOperationStatus.Failed);
}
@@ -24,16 +24,21 @@ namespace YooAsset
if (_steps == ESteps.CheckBundle)
{
if (IsWaitForAsyncComplete)
{
OwnerBundle.WaitForAsyncComplete();
}
FileLoader.WaitForAsyncComplete();
if (OwnerBundle.IsDone() == false)
if (FileLoader.IsDone() == false)
return;
if (OwnerBundle.Status != BundleLoaderBase.EStatus.Succeed)
if (FileLoader.Status != BundleFileLoader.EStatus.Succeed)
{
string error = OwnerBundle.LastError;
string error = FileLoader.LastError;
InvokeCompletion(error, EOperationStatus.Failed);
return;
}
if (FileLoader.Result is string == false)
{
string error = "Try load AssetBundle file using load raw file method !";
InvokeCompletion(error, EOperationStatus.Failed);
return;
}
@@ -44,7 +49,7 @@ namespace YooAsset
// 2. 检测加载结果
if (_steps == ESteps.Checking)
{
RawFilePath = OwnerBundle.FileLoadPath;
RawFilePath = FileLoader.Result as string;
InvokeCompletion(string.Empty, EOperationStatus.Succeed);
}
}
@@ -37,25 +37,25 @@ namespace YooAsset
{
if (IsWaitForAsyncComplete)
{
DependBundles.WaitForAsyncComplete();
OwnerBundle.WaitForAsyncComplete();
DependLoaders.WaitForAsyncComplete();
FileLoader.WaitForAsyncComplete();
}
if (DependBundles.IsDone() == false)
if (DependLoaders.IsDone() == false)
return;
if (OwnerBundle.IsDone() == false)
if (FileLoader.IsDone() == false)
return;
if (DependBundles.IsSucceed() == false)
if (DependLoaders.IsSucceed() == false)
{
string error = DependBundles.GetLastError();
string error = DependLoaders.GetLastError();
InvokeCompletion(error, EOperationStatus.Failed);
return;
}
if (OwnerBundle.Status != BundleLoaderBase.EStatus.Succeed)
if (FileLoader.Status != BundleFileLoader.EStatus.Succeed)
{
string error = OwnerBundle.LastError;
string error = FileLoader.LastError;
InvokeCompletion(error, EOperationStatus.Failed);
return;
}
@@ -66,7 +66,7 @@ namespace YooAsset
// 2. 加载场景
if (_steps == ESteps.Loading)
{
if (IsWaitForAsyncComplete || IsForceDestroyComplete)
if (IsWaitForAsyncComplete)
{
// 注意:场景同步加载方法不会立即加载场景,而是在下一帧加载。
LoadSceneParameters parameters = new LoadSceneParameters(SceneMode);
@@ -99,7 +99,7 @@ namespace YooAsset
{
if (_asyncOperation != null)
{
if (IsWaitForAsyncComplete || IsForceDestroyComplete)
if (IsWaitForAsyncComplete)
{
// 场景加载无法强制异步转同步
YooLogger.Error("The scene is loading asyn !");
@@ -6,6 +6,7 @@ namespace YooAsset
{
internal sealed class BundledSubAssetsProvider : ProviderBase
{
private AssetBundle _assetBundle;
private AssetBundleRequest _cacheRequest;
public BundledSubAssetsProvider(ResourceManager manager, string providerGUID, AssetInfo assetInfo) : base(manager, providerGUID, assetInfo)
@@ -30,54 +31,62 @@ namespace YooAsset
{
if (IsWaitForAsyncComplete)
{
DependBundles.WaitForAsyncComplete();
OwnerBundle.WaitForAsyncComplete();
DependLoaders.WaitForAsyncComplete();
FileLoader.WaitForAsyncComplete();
}
if (DependBundles.IsDone() == false)
if (DependLoaders.IsDone() == false)
return;
if (OwnerBundle.IsDone() == false)
if (FileLoader.IsDone() == false)
return;
if (DependBundles.IsSucceed() == false)
if (DependLoaders.IsSucceed() == false)
{
string error = DependBundles.GetLastError();
string error = DependLoaders.GetLastError();
InvokeCompletion(error, EOperationStatus.Failed);
return;
}
if (OwnerBundle.Status != BundleLoaderBase.EStatus.Succeed)
if (FileLoader.Status != BundleFileLoader.EStatus.Succeed)
{
string error = OwnerBundle.LastError;
string error = FileLoader.LastError;
InvokeCompletion(error, EOperationStatus.Failed);
return;
}
if (OwnerBundle.CacheBundle == null)
if (FileLoader.Result == null)
{
ProcessCacheBundleException();
ProcessFatalEvent();
return;
}
if (FileLoader.Result is AssetBundle == false)
{
string error = "Try load raw file using load assetbundle method !";
InvokeCompletion(error, EOperationStatus.Failed);
return;
}
_assetBundle = FileLoader.Result as AssetBundle;
_steps = ESteps.Loading;
}
// 2. 加载资源对象
if (_steps == ESteps.Loading)
{
if (IsWaitForAsyncComplete || IsForceDestroyComplete)
if (IsWaitForAsyncComplete)
{
if (MainAssetInfo.AssetType == null)
AllAssetObjects = OwnerBundle.CacheBundle.LoadAssetWithSubAssets(MainAssetInfo.AssetPath);
AllAssetObjects = _assetBundle.LoadAssetWithSubAssets(MainAssetInfo.AssetPath);
else
AllAssetObjects = OwnerBundle.CacheBundle.LoadAssetWithSubAssets(MainAssetInfo.AssetPath, MainAssetInfo.AssetType);
AllAssetObjects = _assetBundle.LoadAssetWithSubAssets(MainAssetInfo.AssetPath, MainAssetInfo.AssetType);
}
else
{
if (MainAssetInfo.AssetType == null)
_cacheRequest = OwnerBundle.CacheBundle.LoadAssetWithSubAssetsAsync(MainAssetInfo.AssetPath);
_cacheRequest = _assetBundle.LoadAssetWithSubAssetsAsync(MainAssetInfo.AssetPath);
else
_cacheRequest = OwnerBundle.CacheBundle.LoadAssetWithSubAssetsAsync(MainAssetInfo.AssetPath, MainAssetInfo.AssetType);
_cacheRequest = _assetBundle.LoadAssetWithSubAssetsAsync(MainAssetInfo.AssetPath, MainAssetInfo.AssetType);
}
_steps = ESteps.Checking;
}
@@ -87,7 +96,7 @@ namespace YooAsset
{
if (_cacheRequest != null)
{
if (IsWaitForAsyncComplete || IsForceDestroyComplete)
if (IsWaitForAsyncComplete)
{
// 强制挂起主线程(注意:该操作会很耗时)
YooLogger.Warning("Suspend the main thread to load unity asset.");
@@ -106,9 +115,9 @@ namespace YooAsset
{
string error;
if (MainAssetInfo.AssetType == null)
error = $"Failed to load sub assets : {MainAssetInfo.AssetPath} AssetType : null AssetBundle : {OwnerBundle.MainBundleInfo.Bundle.BundleName}";
error = $"Failed to load sub assets : {MainAssetInfo.AssetPath} AssetType : null AssetBundle : {FileLoader.MainBundleInfo.Bundle.BundleName}";
else
error = $"Failed to load sub assets : {MainAssetInfo.AssetPath} AssetType : {MainAssetInfo.AssetType} AssetBundle : {OwnerBundle.MainBundleInfo.Bundle.BundleName}";
error = $"Failed to load sub assets : {MainAssetInfo.AssetPath} AssetType : {MainAssetInfo.AssetType} AssetBundle : {FileLoader.MainBundleInfo.Bundle.BundleName}";
YooLogger.Error(error);
InvokeCompletion(error, EOperationStatus.Failed);
}
@@ -43,15 +43,15 @@ namespace YooAsset
{
if (IsWaitForAsyncComplete)
{
OwnerBundle.WaitForAsyncComplete();
FileLoader.WaitForAsyncComplete();
}
if (OwnerBundle.IsDone() == false)
if (FileLoader.IsDone() == false)
return;
if (OwnerBundle.Status != BundleLoaderBase.EStatus.Succeed)
if (FileLoader.Status != BundleFileLoader.EStatus.Succeed)
{
string error = OwnerBundle.LastError;
string error = FileLoader.LastError;
InvokeCompletion(error, EOperationStatus.Failed);
return;
}
@@ -65,7 +65,7 @@ namespace YooAsset
if (MainAssetInfo.AssetType == null)
{
List<UnityEngine.Object> result = new List<Object>();
foreach (var assetPath in OwnerBundle.MainBundleInfo.IncludeAssetsInEditor)
foreach (var assetPath in FileLoader.MainBundleInfo.IncludeAssetsInEditor)
{
UnityEngine.Object mainAsset = UnityEditor.AssetDatabase.LoadMainAssetAtPath(assetPath);
if (mainAsset != null)
@@ -76,7 +76,7 @@ namespace YooAsset
else
{
List<UnityEngine.Object> result = new List<Object>();
foreach (var assetPath in OwnerBundle.MainBundleInfo.IncludeAssetsInEditor)
foreach (var assetPath in FileLoader.MainBundleInfo.IncludeAssetsInEditor)
{
UnityEngine.Object mainAsset = UnityEditor.AssetDatabase.LoadAssetAtPath(assetPath, MainAssetInfo.AssetType);
if (mainAsset != null)
@@ -43,15 +43,15 @@ namespace YooAsset
{
if (IsWaitForAsyncComplete)
{
OwnerBundle.WaitForAsyncComplete();
FileLoader.WaitForAsyncComplete();
}
if (OwnerBundle.IsDone() == false)
if (FileLoader.IsDone() == false)
return;
if (OwnerBundle.Status != BundleLoaderBase.EStatus.Succeed)
if (FileLoader.Status != BundleFileLoader.EStatus.Succeed)
{
string error = OwnerBundle.LastError;
string error = FileLoader.LastError;
InvokeCompletion(error, EOperationStatus.Failed);
return;
}
@@ -40,15 +40,15 @@ namespace YooAsset
{
if (IsWaitForAsyncComplete)
{
OwnerBundle.WaitForAsyncComplete();
FileLoader.WaitForAsyncComplete();
}
if (OwnerBundle.IsDone() == false)
if (FileLoader.IsDone() == false)
return;
if (OwnerBundle.Status != BundleLoaderBase.EStatus.Succeed)
if (FileLoader.Status != BundleFileLoader.EStatus.Succeed)
{
string error = OwnerBundle.LastError;
string error = FileLoader.LastError;
InvokeCompletion(error, EOperationStatus.Failed);
return;
}
@@ -38,15 +38,15 @@ namespace YooAsset
{
if (IsWaitForAsyncComplete)
{
OwnerBundle.WaitForAsyncComplete();
FileLoader.WaitForAsyncComplete();
}
if (OwnerBundle.IsDone() == false)
if (FileLoader.IsDone() == false)
return;
if (OwnerBundle.Status != BundleLoaderBase.EStatus.Succeed)
if (FileLoader.Status != BundleFileLoader.EStatus.Succeed)
{
string error = OwnerBundle.LastError;
string error = FileLoader.LastError;
InvokeCompletion(error, EOperationStatus.Failed);
return;
}
@@ -57,7 +57,7 @@ namespace YooAsset
// 2. 加载资源对象
if (_steps == ESteps.Loading)
{
if (IsWaitForAsyncComplete || IsForceDestroyComplete)
if (IsWaitForAsyncComplete)
{
LoadSceneParameters loadSceneParameters = new LoadSceneParameters(SceneMode);
SceneObject = UnityEditor.SceneManagement.EditorSceneManager.LoadSceneInPlayMode(MainAssetInfo.AssetPath, loadSceneParameters);
@@ -88,7 +88,7 @@ namespace YooAsset
{
if (_asyncOperation != null)
{
if (IsWaitForAsyncComplete || IsForceDestroyComplete)
if (IsWaitForAsyncComplete)
{
// 场景加载无法强制异步转同步
YooLogger.Error("The scene is loading asyn !");
@@ -43,15 +43,15 @@ namespace YooAsset
{
if (IsWaitForAsyncComplete)
{
OwnerBundle.WaitForAsyncComplete();
FileLoader.WaitForAsyncComplete();
}
if (OwnerBundle.IsDone() == false)
if (FileLoader.IsDone() == false)
return;
if (OwnerBundle.Status != BundleLoaderBase.EStatus.Succeed)
if (FileLoader.Status != BundleFileLoader.EStatus.Succeed)
{
string error = OwnerBundle.LastError;
string error = FileLoader.LastError;
InvokeCompletion(error, EOperationStatus.Failed);
return;
}
@@ -1,7 +1,6 @@
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Threading.Tasks;
using System;
namespace YooAsset
@@ -69,10 +68,9 @@ namespace YooAsset
protected ESteps _steps = ESteps.None;
protected BundleLoaderBase OwnerBundle { private set; get; }
protected DependAssetBundles DependBundles { private set; get; }
protected BundleFileLoader FileLoader { private set; get; }
protected DependFileLoaders DependLoaders { private set; get; }
protected bool IsWaitForAsyncComplete { private set; get; } = false;
protected bool IsForceDestroyComplete { private set; get; } = false;
private readonly List<HandleBase> _handles = new List<HandleBase>();
@@ -85,13 +83,30 @@ namespace YooAsset
// 创建资源包加载器
if (manager != null)
{
OwnerBundle = manager.CreateOwnerAssetBundleLoader(assetInfo);
OwnerBundle.Reference();
OwnerBundle.AddProvider(this);
FileLoader = manager.CreateOwnerFileLoader(assetInfo);
FileLoader.Reference();
FileLoader.AddProvider(this);
var dependList = manager.CreateDependAssetBundleLoaders(assetInfo);
DependBundles = new DependAssetBundles(dependList);
DependBundles.Reference();
var dependList = manager.CreateDependFileLoaders(assetInfo);
DependLoaders = new DependFileLoaders(dependList);
DependLoaders.Reference();
}
}
/// <summary>
/// 等待异步执行完毕
/// </summary>
public override void WaitForAsyncComplete()
{
IsWaitForAsyncComplete = true;
// 注意:主动轮询更新完成同步加载
InternalOnUpdate();
// 验证结果
if (IsDone == false)
{
YooLogger.Warning($"{nameof(WaitForAsyncComplete)} failed to loading : {MainAssetInfo.AssetPath}");
}
}
@@ -110,15 +125,15 @@ namespace YooAsset
}
// 释放资源包加载器
if (OwnerBundle != null)
if (FileLoader != null)
{
OwnerBundle.Release();
OwnerBundle = null;
FileLoader.Release();
FileLoader = null;
}
if (DependBundles != null)
if (DependLoaders != null)
{
DependBundles.Release();
DependBundles = null;
DependLoaders.Release();
DependLoaders = null;
}
}
@@ -188,43 +203,14 @@ namespace YooAsset
}
/// <summary>
/// 等待异步执行完毕
/// 处理致命问题
/// </summary>
public void WaitForAsyncComplete()
protected void ProcessFatalEvent()
{
IsWaitForAsyncComplete = true;
// 注意:主动轮询更新完成同步加载
InternalOnUpdate();
// 验证结果
if (IsDone == false)
{
YooLogger.Warning($"{nameof(WaitForAsyncComplete)} failed to loading : {MainAssetInfo.AssetPath}");
}
}
/// <summary>
/// 强制销毁资源提供者
/// </summary>
public void ForceDestroyComplete()
{
IsForceDestroyComplete = true;
// 注意:主动轮询更新完成同步加载
// 说明:如果资源包未准备完毕也可以放心销毁。
InternalOnUpdate();
}
/// <summary>
/// 处理特殊异常
/// </summary>
protected void ProcessCacheBundleException()
{
if (OwnerBundle.IsDestroyed)
if (FileLoader.IsDestroyed)
throw new System.Exception("Should never get here !");
string error = $"The bundle {OwnerBundle.MainBundleInfo.Bundle.BundleName} has been destroyed by unity bugs !";
string error = $"The bundle {FileLoader.MainBundleInfo.Bundle.BundleName} has been destroyed by unity bugs !";
YooLogger.Error(error);
InvokeCompletion(Error, EOperationStatus.Failed);
}
@@ -252,6 +238,28 @@ namespace YooAsset
}
}
/// <summary>
/// 获取下载报告
/// </summary>
public DownloadStatus GetDownloadStatus()
{
DownloadStatus status = new DownloadStatus();
status.TotalBytes = FileLoader.MainBundleInfo.Bundle.FileSize;
status.DownloadedBytes = FileLoader.DownloadedBytes;
foreach (var dependBundle in DependLoaders.DependList)
{
status.TotalBytes += dependBundle.MainBundleInfo.Bundle.FileSize;
status.DownloadedBytes += dependBundle.DownloadedBytes;
}
if (status.TotalBytes == 0)
throw new System.Exception("Should never get here !");
status.IsDone = status.DownloadedBytes == status.TotalBytes;
status.Progress = (float)status.DownloadedBytes / status.TotalBytes;
return status;
}
#region 调试信息相关
/// <summary>
/// 出生的场景
@@ -304,40 +312,18 @@ namespace YooAsset
}
}
/// <summary>
/// 获取下载报告
/// </summary>
internal DownloadStatus GetDownloadStatus()
{
DownloadStatus status = new DownloadStatus();
status.TotalBytes = (ulong)OwnerBundle.MainBundleInfo.Bundle.FileSize;
status.DownloadedBytes = OwnerBundle.DownloadedBytes;
foreach (var dependBundle in DependBundles.DependList)
{
status.TotalBytes += (ulong)dependBundle.MainBundleInfo.Bundle.FileSize;
status.DownloadedBytes += dependBundle.DownloadedBytes;
}
if (status.TotalBytes == 0)
throw new System.Exception("Should never get here !");
status.IsDone = status.DownloadedBytes == status.TotalBytes;
status.Progress = (float)status.DownloadedBytes / status.TotalBytes;
return status;
}
/// <summary>
/// 获取资源包的调试信息列表
/// </summary>
internal void GetBundleDebugInfos(List<DebugBundleInfo> output)
{
var bundleInfo = new DebugBundleInfo();
bundleInfo.BundleName = OwnerBundle.MainBundleInfo.Bundle.BundleName;
bundleInfo.RefCount = OwnerBundle.RefCount;
bundleInfo.Status = OwnerBundle.Status.ToString();
bundleInfo.BundleName = FileLoader.MainBundleInfo.Bundle.BundleName;
bundleInfo.RefCount = FileLoader.RefCount;
bundleInfo.Status = FileLoader.Status.ToString();
output.Add(bundleInfo);
DependBundles.GetBundleDebugInfos(output);
DependLoaders.GetBundleDebugInfos(output);
}
#endregion
}