update operation logic

pull/326/head
何冠峰 2024-07-07 16:01:55 +08:00
parent 25231ecd32
commit 260867b588
46 changed files with 525 additions and 678 deletions

View File

@ -189,7 +189,7 @@ namespace YooAsset.Editor
// Status // Status
StyleColor textColor; StyleColor textColor;
if (bundleInfo.Status == BundleFileLoader.EStatus.Failed.ToString()) if (bundleInfo.Status == EOperationStatus.Failed)
textColor = new StyleColor(Color.yellow); textColor = new StyleColor(Color.yellow);
else else
textColor = label1.style.color; textColor = label1.style.color;

View File

@ -25,7 +25,7 @@ namespace YooAsset
/// <summary> /// <summary>
/// 加载状态 /// 加载状态
/// </summary> /// </summary>
public string Status; public EOperationStatus Status;
public int CompareTo(DebugBundleInfo other) public int CompareTo(DebugBundleInfo other)
{ {

View File

@ -43,7 +43,7 @@ namespace YooAsset
#elif UNITY_OPENHARMONY #elif UNITY_OPENHARMONY
return StringUtility.Format("file://{0}", path); return StringUtility.Format("file://{0}", path);
#else #else
return path; throw new System.NotImplementedException();
#endif #endif
} }
} }

View File

@ -84,19 +84,17 @@ namespace YooAsset
} }
} }
} }
internal override void InternalWaitForAsyncComplete()
public override void WaitForAsyncComplete()
{ {
_isWaitForAsyncComplete = true; _isWaitForAsyncComplete = true;
while (true) while (true)
{ {
// 驱动流程 if (ExecuteWhileDone())
InternalOnUpdate(); {
_steps = ESteps.Done;
// 完成后退出
if (IsDone)
break; break;
}
} }
} }
public override void AbortDownloadOperation() public override void AbortDownloadOperation()
@ -170,17 +168,15 @@ namespace YooAsset
} }
} }
} }
internal override void InternalWaitForAsyncComplete()
public override void WaitForAsyncComplete()
{ {
while (true) while (true)
{ {
// 驱动流程 if (ExecuteWhileDone())
InternalOnUpdate(); {
_steps = ESteps.Done;
// 完成后退出
if (IsDone)
break; break;
}
} }
} }
public override void AbortDownloadOperation() public override void AbortDownloadOperation()

View File

@ -94,8 +94,6 @@ namespace YooAsset
// 等待验证完成 // 等待验证完成
if (_steps == ESteps.CheckVerifyTempFile) if (_steps == ESteps.CheckVerifyTempFile)
{ {
// 注意:同步解压文件更新
_verifyOperation.InternalOnUpdate();
if (_verifyOperation.IsDone == false) if (_verifyOperation.IsDone == false)
return; return;
@ -103,21 +101,21 @@ namespace YooAsset
{ {
if (_fileSystem.WriteCacheFile(Bundle, _tempFilePath)) if (_fileSystem.WriteCacheFile(Bundle, _tempFilePath))
{ {
Status = EOperationStatus.Succeed;
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Succeed;
} }
else else
{ {
Error = $"{_fileSystem.GetType().FullName} failed to write file !";
Status = EOperationStatus.Failed;
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = $"{_fileSystem.GetType().FullName} failed to write file !";
YooLogger.Error(Error); YooLogger.Error(Error);
} }
} }
else else
{ {
Error = _verifyOperation.Error;
_steps = ESteps.TryAgain; _steps = ESteps.TryAgain;
Error = _verifyOperation.Error;
} }
// 注意:验证完成后直接删除文件 // 注意:验证完成后直接删除文件
@ -150,23 +148,30 @@ namespace YooAsset
_steps = ESteps.Done; _steps = ESteps.Done;
DisposeWebRequest(); DisposeWebRequest();
} }
public override void WaitForAsyncComplete() internal override void InternalWaitForAsyncComplete()
{ {
bool isReuqestLocalFile = IsRequestLocalFile();
while (true) while (true)
{ {
// 文件验证
if (_verifyOperation != null) if (_verifyOperation != null)
_verifyOperation.WaitForAsyncComplete();
// 注意:如果是导入或解压本地文件,执行等待完毕
if (isReuqestLocalFile)
{ {
if (_verifyOperation.IsDone == false) InternalOnUpdate();
_verifyOperation.WaitForAsyncComplete(); if (IsDone)
break;
}
else
{
if (ExecuteWhileDone())
{
_steps = ESteps.Done;
break;
}
} }
// 驱动流程
InternalOnUpdate();
// 完成后退出
if (IsDone)
break;
} }
} }
@ -353,23 +358,30 @@ namespace YooAsset
_steps = ESteps.Done; _steps = ESteps.Done;
DisposeWebRequest(); DisposeWebRequest();
} }
public override void WaitForAsyncComplete() internal override void InternalWaitForAsyncComplete()
{ {
bool isReuqestLocalFile = IsRequestLocalFile();
while (true) while (true)
{ {
// 文件验证
if (_verifyOperation != null) if (_verifyOperation != null)
_verifyOperation.WaitForAsyncComplete();
// 注意:如果是导入或解压本地文件,执行等待完毕
if (isReuqestLocalFile)
{ {
if (_verifyOperation.IsDone == false) InternalOnUpdate();
_verifyOperation.WaitForAsyncComplete(); if (IsDone)
break;
}
else
{
if (ExecuteWhileDone())
{
_steps = ESteps.Done;
break;
}
} }
// 驱动流程
InternalOnUpdate();
// 完成后退出
if (IsDone)
break;
} }
} }

View File

@ -159,31 +159,23 @@ namespace YooAsset
} }
} }
} }
internal override void InternalWaitForAsyncComplete()
public override void WaitForAsyncComplete()
{ {
_isWaitForAsyncComplete = true; _isWaitForAsyncComplete = true;
int frame = 1000;
while (true) while (true)
{ {
// 保险机制 if(_downloadFileOp != null)
// 注意:如果需要从远端下载资源,可能会触发保险机制! _downloadFileOp.WaitForAsyncComplete();
frame--;
if (frame == 0) if (ExecuteWhileDone())
{ {
Status = EOperationStatus.Failed; if (_downloadFileOp != null && _downloadFileOp.Status == EOperationStatus.Failed)
Error = $"{nameof(WaitForAsyncComplete)} failed ! Try load bundle {_bundle.BundleName} from remote with sync load method !"; YooLogger.Error($"Try load bundle {_bundle.BundleName} from remote !");
_steps = ESteps.Done; _steps = ESteps.Done;
YooLogger.Error(Error);
}
// 驱动流程
InternalOnUpdate();
// 完成后退出
if (IsDone)
break; break;
}
} }
} }
public override void AbortDownloadOperation() public override void AbortDownloadOperation()
@ -299,29 +291,21 @@ namespace YooAsset
} }
} }
} }
internal override void InternalWaitForAsyncComplete()
public override void WaitForAsyncComplete()
{ {
int frame = 1000;
while (true) while (true)
{ {
// 保险机制 if (_downloadFileOp != null)
// 注意:如果需要从远端下载资源,可能会触发保险机制! _downloadFileOp.WaitForAsyncComplete();
frame--;
if (frame == 0) if (ExecuteWhileDone())
{ {
Status = EOperationStatus.Failed; if (_downloadFileOp != null && _downloadFileOp.Status == EOperationStatus.Failed)
Error = $"{nameof(WaitForAsyncComplete)} failed ! Try load bundle {_bundle.BundleName} from remote with sync load method !"; YooLogger.Error($"Try load bundle {_bundle.BundleName} from remote !");
_steps = ESteps.Done; _steps = ESteps.Done;
YooLogger.Error(Error);
}
// 驱动流程
InternalOnUpdate();
// 完成后退出
if (IsDone)
break; break;
}
} }
} }
public override void AbortDownloadOperation() public override void AbortDownloadOperation()

View File

@ -85,14 +85,12 @@ namespace YooAsset
} }
} }
} }
public override void WaitForAsyncComplete() internal override void InternalWaitForAsyncComplete()
{ {
while (true) while (true)
{ {
// 驱动流程 // 注意:等待子线程验证文件完毕
InternalOnUpdate(); InternalOnUpdate();
// 完成后退出
if (IsDone) if (IsDone)
break; break;
} }

View File

@ -20,8 +20,7 @@ namespace YooAsset
internal override void InternalOnUpdate() internal override void InternalOnUpdate()
{ {
} }
internal override void InternalWaitForAsyncComplete()
public override void WaitForAsyncComplete()
{ {
} }
public override void AbortDownloadOperation() public override void AbortDownloadOperation()

View File

@ -17,20 +17,5 @@ namespace YooAsset
_saveFileRoot = PathUtility.Combine(_packageRoot, DefaultUnpackFileSystemDefine.SaveFilesFolderName); _saveFileRoot = PathUtility.Combine(_packageRoot, DefaultUnpackFileSystemDefine.SaveFilesFolderName);
_tempFileRoot = PathUtility.Combine(_packageRoot, DefaultUnpackFileSystemDefine.TempFilesFolderName); _tempFileRoot = PathUtility.Combine(_packageRoot, DefaultUnpackFileSystemDefine.TempFilesFolderName);
} }
public override FSLoadBundleOperation LoadBundleFile(PackageBundle bundle)
{
if (RawFileBuildPipeline)
{
var operation = new DUFSLoadRawBundleOperation(this, bundle);
OperationSystem.StartOperation(PackageName, operation);
return operation;
}
else
{
var operation = new DUFSLoadAssetBundleOperation(this, bundle);
OperationSystem.StartOperation(PackageName, operation);
return operation;
}
}
} }
} }

View File

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: 59b123e460757694180175970bf28826
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,57 +0,0 @@

namespace YooAsset
{
internal class DUFSLoadAssetBundleOperation : DCFSLoadAssetBundleOperation
{
public DUFSLoadAssetBundleOperation(DefaultUnpackFileSystem fileSystem, PackageBundle bundle) : base(fileSystem, bundle)
{
}
public override void WaitForAsyncComplete()
{
_isWaitForAsyncComplete = true;
while (true)
{
// 文件解压
if (_downloadFileOp != null)
{
if (_downloadFileOp.IsDone == false)
_downloadFileOp.WaitForAsyncComplete();
}
// 驱动流程
InternalOnUpdate();
// 完成后退出
if (IsDone)
break;
}
}
}
internal class DUFSLoadRawBundleOperation : DCFSLoadRawBundleOperation
{
public DUFSLoadRawBundleOperation(DefaultUnpackFileSystem fileSystem, PackageBundle bundle) : base(fileSystem, bundle)
{
}
public override void WaitForAsyncComplete()
{
while (true)
{
// 文件解压
if (_downloadFileOp != null)
{
if (_downloadFileOp.IsDone == false)
_downloadFileOp.WaitForAsyncComplete();
}
// 驱动流程
InternalOnUpdate();
// 完成后退出
if (IsDone)
break;
}
}
}
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: 47f6fe3a815d28e49815db7c09c1fa76
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -62,10 +62,9 @@ namespace YooAsset
} }
} }
} }
internal override void InternalWaitForAsyncComplete()
public override void WaitForAsyncComplete()
{ {
if (IsDone == false) if (_steps != ESteps.Done)
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;

View File

@ -89,7 +89,7 @@ namespace YooAsset
float offset = UnityEngine.Time.realtimeSinceStartup - _latestDownloadRealtime; float offset = UnityEngine.Time.realtimeSinceStartup - _latestDownloadRealtime;
if (offset > Param.Timeout) if (offset > Param.Timeout)
{ {
YooLogger.Warning($"Web file request timeout : {_requestURL}"); YooLogger.Warning($"Download request timeout : {_requestURL}");
if (_webRequest != null) if (_webRequest != null)
_webRequest.Abort(); _webRequest.Abort();
_isAbort = true; _isAbort = true;
@ -126,5 +126,19 @@ namespace YooAsset
} }
#endif #endif
} }
/// <summary>
/// 是否请求的本地文件
/// </summary>
protected bool IsRequestLocalFile()
{
//TODO : UNITY_STANDALONE_OSX平台目前无法确定
if (Param.MainURL.StartsWith("file:"))
return true;
if (Param.MainURL.StartsWith("jar:file:"))
return true;
return false;
}
} }
} }

View File

@ -175,10 +175,6 @@ namespace YooAsset
/// </summary> /// </summary>
public abstract class InitializeParameters public abstract class InitializeParameters
{ {
/// <summary>
/// 自动销毁不再使用的资源提供者
/// </summary>
public bool AutoDestroyAssetProvider = false;
} }
/// <summary> /// <summary>

View File

@ -8,13 +8,13 @@ namespace YooAsset
{ {
public abstract class AsyncOperationBase : IEnumerator, IComparable<AsyncOperationBase> public abstract class AsyncOperationBase : IEnumerator, IComparable<AsyncOperationBase>
{ {
// 用户请求的回调
private Action<AsyncOperationBase> _callback; private Action<AsyncOperationBase> _callback;
// 所属包裹
private string _packageName = null; private string _packageName = null;
private int _whileFrame = 1000;
// 是否已经完成 /// <summary>
/// 是否已经完成
/// </summary>
internal bool IsFinish = false; internal bool IsFinish = false;
/// <summary> /// <summary>
@ -85,7 +85,13 @@ namespace YooAsset
internal abstract void InternalOnStart(); internal abstract void InternalOnStart();
internal abstract void InternalOnUpdate(); internal abstract void InternalOnUpdate();
internal virtual void InternalOnAbort() { } internal virtual void InternalOnAbort()
{
}
internal virtual void InternalWaitForAsyncComplete()
{
throw new System.NotImplementedException(this.GetType().Name);
}
internal string GetPackageName() internal string GetPackageName()
{ {
@ -125,19 +131,36 @@ namespace YooAsset
} }
/// <summary> /// <summary>
/// 等待异步执行完毕 /// 执行While循环
/// </summary> /// </summary>
public virtual void WaitForAsyncComplete() protected bool ExecuteWhileDone()
{ {
throw new System.NotImplementedException(this.GetType().Name); if (IsDone == false)
{
// 执行更新逻辑
InternalOnUpdate();
// 当执行次数用完时
_whileFrame--;
if (_whileFrame == 0)
{
Status = EOperationStatus.Failed;
Error = $"Operation {this.GetType().Name} failed to wait for async complete !";
YooLogger.Error(Error);
}
}
return IsDone;
} }
/// <summary> /// <summary>
/// 清空完成回调 /// 等待异步执行完毕
/// </summary> /// </summary>
protected void ClearCompletedCallback() public void WaitForAsyncComplete()
{ {
_callback = null; if (IsDone)
return;
InternalWaitForAsyncComplete();
} }
#region 排序接口实现 #region 排序接口实现
@ -159,19 +182,5 @@ namespace YooAsset
private TaskCompletionSource<object> _taskCompletionSource; private TaskCompletionSource<object> _taskCompletionSource;
#endregion #endregion
#region 调试方法
[Conditional("DEBUG")]
protected void DebugCheckWaitForAsyncComplete(string error = null)
{
if (IsDone == false)
{
if (string.IsNullOrEmpty(error))
YooLogger.Error($"Operation {this.GetType().Name} failed to wait for async complete !");
else
YooLogger.Error($"Operation {this.GetType().Name} failed to wait for async complete ! {error}");
}
}
#endregion
} }
} }

View File

@ -7,7 +7,7 @@ namespace YooAsset
{ {
private System.Action<AllAssetsHandle> _callback; private System.Action<AllAssetsHandle> _callback;
internal AllAssetsHandle(ProviderBase provider) : base(provider) internal AllAssetsHandle(ProviderOperation provider) : base(provider)
{ {
} }
internal override void InvokeCallback() internal override void InvokeCallback()

View File

@ -8,7 +8,7 @@ namespace YooAsset
{ {
private System.Action<AssetHandle> _callback; private System.Action<AssetHandle> _callback;
internal AssetHandle(ProviderBase provider) : base(provider) internal AssetHandle(ProviderOperation provider) : base(provider)
{ {
} }
internal override void InvokeCallback() internal override void InvokeCallback()

View File

@ -6,9 +6,9 @@ namespace YooAsset
public abstract class HandleBase : IEnumerator public abstract class HandleBase : IEnumerator
{ {
private readonly AssetInfo _assetInfo; private readonly AssetInfo _assetInfo;
internal ProviderBase Provider { private set; get; } internal ProviderOperation Provider { private set; get; }
internal HandleBase(ProviderBase provider) internal HandleBase(ProviderOperation provider)
{ {
Provider = provider; Provider = provider;
_assetInfo = provider.MainAssetInfo; _assetInfo = provider.MainAssetInfo;

View File

@ -8,7 +8,7 @@ namespace YooAsset
{ {
private System.Action<RawFileHandle> _callback; private System.Action<RawFileHandle> _callback;
internal RawFileHandle(ProviderBase provider) : base(provider) internal RawFileHandle(ProviderOperation provider) : base(provider)
{ {
} }
internal override void InvokeCallback() internal override void InvokeCallback()

View File

@ -7,7 +7,7 @@ namespace YooAsset
private System.Action<SceneHandle> _callback; private System.Action<SceneHandle> _callback;
internal string PackageName { set; get; } internal string PackageName { set; get; }
internal SceneHandle(ProviderBase provider) : base(provider) internal SceneHandle(ProviderOperation provider) : base(provider)
{ {
} }
internal override void InvokeCallback() internal override void InvokeCallback()

View File

@ -7,7 +7,7 @@ namespace YooAsset
{ {
private System.Action<SubAssetsHandle> _callback; private System.Action<SubAssetsHandle> _callback;
internal SubAssetsHandle(ProviderBase provider) : base(provider) internal SubAssetsHandle(ProviderOperation provider) : base(provider)
{ {
} }
internal override void InvokeCallback() internal override void InvokeCallback()

View File

@ -1,112 +0,0 @@
using System;
using System.Collections;
using System.Collections.Generic;
namespace YooAsset
{
internal class DependFileLoaders
{
/// <summary>
/// 依赖的资源包加载器列表
/// </summary>
internal readonly List<BundleFileLoader> DependList;
public DependFileLoaders(List<BundleFileLoader> dpendList)
{
DependList = dpendList;
}
/// <summary>
/// 是否已经完成(无论成功或失败)
/// </summary>
public bool IsDone()
{
foreach (var loader in DependList)
{
if (loader.IsDone() == false)
return false;
}
return true;
}
/// <summary>
/// 依赖资源包是否全部加载成功
/// </summary>
public bool IsSucceed()
{
foreach (var loader in DependList)
{
if (loader.Status != BundleFileLoader.EStatus.Succeed)
{
return false;
}
}
return true;
}
/// <summary>
/// 获取某个加载失败的资源包错误信息
/// </summary>
public string GetLastError()
{
foreach (var loader in DependList)
{
if (loader.Status != BundleFileLoader.EStatus.Succeed)
{
return loader.LastError;
}
}
return string.Empty;
}
/// <summary>
/// 主线程等待异步操作完毕
/// </summary>
public void WaitForAsyncComplete()
{
foreach (var loader in DependList)
{
if (loader.IsDone() == false)
loader.WaitForAsyncComplete();
}
}
/// <summary>
/// 增加引用计数
/// </summary>
public void Reference()
{
foreach (var loader in DependList)
{
loader.Reference();
}
}
/// <summary>
/// 减少引用计数
/// </summary>
public void Release()
{
foreach (var loader in DependList)
{
loader.Release();
}
}
/// <summary>
/// 获取资源包的调试信息列表
/// </summary>
internal void GetBundleDebugInfos(List<DebugBundleInfo> output)
{
foreach (var loader in DependList)
{
var bundleInfo = new DebugBundleInfo();
bundleInfo.BundleName = loader.MainBundleInfo.Bundle.BundleName;
bundleInfo.RefCount = loader.RefCount;
bundleInfo.Status = loader.Status.ToString();
output.Add(bundleInfo);
}
}
}
}

View File

@ -1,39 +1,28 @@
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine;
namespace YooAsset namespace YooAsset
{ {
internal class BundleFileLoader internal class LoadBundleFileOperation : AsyncOperationBase
{ {
public enum EStatus private enum ESteps
{ {
None = 0, None,
Succeed, LoadFile,
Failed Done,
} }
private readonly ResourceManager _resourceManager; private readonly ResourceManager _resourceManager;
private readonly List<ProviderBase> _providers = new List<ProviderBase>(100); private readonly List<ProviderOperation> _providers = new List<ProviderOperation>(100);
private readonly List<ProviderBase> _removeList = new List<ProviderBase>(100); private readonly List<ProviderOperation> _removeList = new List<ProviderOperation>(100);
private FSLoadBundleOperation _loadBundleOp; private FSLoadBundleOperation _loadBundleOp;
private bool _isDone = false; private ESteps _steps = ESteps.None;
/// <summary> /// <summary>
/// 资源包文件信息 /// 资源包文件信息
/// </summary> /// </summary>
public BundleInfo MainBundleInfo { private set; get; } public BundleInfo BundleFileInfo { private set; get; }
/// <summary>
/// 加载状态
/// </summary>
public EStatus Status { protected set; get; }
/// <summary>
/// 最近的错误信息
/// </summary>
public string LastError { protected set; get; } = string.Empty;
/// <summary> /// <summary>
/// 是否已经销毁 /// 是否已经销毁
@ -61,57 +50,57 @@ namespace YooAsset
public object Result { set; get; } public object Result { set; get; }
public BundleFileLoader(ResourceManager resourceManager, BundleInfo bundleInfo) internal LoadBundleFileOperation(ResourceManager resourceManager, BundleInfo bundleInfo)
{ {
_resourceManager = resourceManager; _resourceManager = resourceManager;
MainBundleInfo = bundleInfo; BundleFileInfo = bundleInfo;
Status = EStatus.None;
} }
internal override void InternalOnStart()
/// <summary>
/// 轮询更新
/// </summary>
public void Update()
{ {
if (_isDone) _steps = ESteps.LoadFile;
}
internal override void InternalOnUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return; return;
if (_loadBundleOp == null) if (_steps == ESteps.LoadFile)
_loadBundleOp = MainBundleInfo.LoadBundleFile();
DownloadProgress = _loadBundleOp.DownloadProgress;
DownloadedBytes = _loadBundleOp.DownloadedBytes;
if (_loadBundleOp.IsDone == false)
return;
if (_loadBundleOp.Status == EOperationStatus.Succeed)
{ {
_isDone = true; if (_loadBundleOp == null)
Status = EStatus.Succeed; _loadBundleOp = BundleFileInfo.LoadBundleFile();
Result = _loadBundleOp.Result;
} DownloadProgress = _loadBundleOp.DownloadProgress;
else DownloadedBytes = _loadBundleOp.DownloadedBytes;
{ if (_loadBundleOp.IsDone == false)
_isDone = true; return;
Status = EStatus.Failed;
LastError = _loadBundleOp.Error; if (_loadBundleOp.Status == EOperationStatus.Succeed)
{
_steps = ESteps.Done;
Result = _loadBundleOp.Result;
Status = EOperationStatus.Succeed;
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _loadBundleOp.Error;
}
} }
} }
internal override void InternalWaitForAsyncComplete()
/// <summary>
/// 销毁
/// </summary>
public void Destroy()
{ {
IsDestroyed = true; while (true)
{
if (_loadBundleOp != null)
_loadBundleOp.WaitForAsyncComplete();
// Check fatal if (ExecuteWhileDone())
if (RefCount > 0) {
throw new Exception($"Bundle file loader ref is not zero : {MainBundleInfo.Bundle.BundleName}"); _steps = ESteps.Done;
if (IsDone() == false) break;
throw new Exception($"Bundle file loader is not done : {MainBundleInfo.Bundle.BundleName}"); }
}
MainBundleInfo.UnloadBundleFile(Result);
} }
/// <summary> /// <summary>
@ -131,19 +120,27 @@ namespace YooAsset
} }
/// <summary> /// <summary>
/// 是否完毕(无论成功或失败) /// 销毁
/// </summary> /// </summary>
public bool IsDone() public void DestroyLoader()
{ {
return Status == EStatus.Succeed || Status == EStatus.Failed; IsDestroyed = true;
// Check fatal
if (RefCount > 0)
throw new Exception($"Bundle file loader ref is not zero : {BundleFileInfo.Bundle.BundleName}");
if (IsDone == false)
throw new Exception($"Bundle file loader is not done : {BundleFileInfo.Bundle.BundleName}");
BundleFileInfo.UnloadBundleFile(Result);
} }
/// <summary> /// <summary>
/// 是否可以销毁 /// 是否可以销毁
/// </summary> /// </summary>
public bool CanDestroy() public bool CanDestroyLoader()
{ {
if (IsDone() == false) if (IsDone == false)
return false; return false;
return RefCount <= 0; return RefCount <= 0;
@ -152,7 +149,7 @@ namespace YooAsset
/// <summary> /// <summary>
/// 添加附属的资源提供者 /// 添加附属的资源提供者
/// </summary> /// </summary>
public void AddProvider(ProviderBase provider) public void AddProvider(ProviderOperation provider)
{ {
if (_providers.Contains(provider) == false) if (_providers.Contains(provider) == false)
_providers.Add(provider); _providers.Add(provider);
@ -167,7 +164,7 @@ namespace YooAsset
_removeList.Clear(); _removeList.Clear();
foreach (var provider in _providers) foreach (var provider in _providers)
{ {
if (provider.CanDestroy()) if (provider.CanDestroyProvider())
{ {
_removeList.Add(provider); _removeList.Add(provider);
} }
@ -177,7 +174,7 @@ namespace YooAsset
foreach (var provider in _removeList) foreach (var provider in _removeList)
{ {
_providers.Remove(provider); _providers.Remove(provider);
provider.Destroy(); provider.DestroyProvider();
} }
// 移除资源提供者 // 移除资源提供者
@ -188,28 +185,6 @@ namespace YooAsset
} }
} }
/// <summary>
/// 主线程等待异步操作完毕
/// </summary>
public void WaitForAsyncComplete()
{
while (true)
{
if (_loadBundleOp != null)
{
if (_loadBundleOp.IsDone == false)
_loadBundleOp.WaitForAsyncComplete();
}
// 驱动流程
Update();
// 完成后退出
if (IsDone())
break;
}
}
/// <summary> /// <summary>
/// 终止下载任务 /// 终止下载任务
/// </summary> /// </summary>

View File

@ -0,0 +1,126 @@
using System;
using System.Collections;
using System.Collections.Generic;
namespace YooAsset
{
internal class LoadDependBundleFileOperation : AsyncOperationBase
{
private enum ESteps
{
None,
CheckDepend,
CheckResult,
Done,
}
/// <summary>
/// 依赖的资源包加载器列表
/// </summary>
internal readonly List<LoadBundleFileOperation> Depends;
private ESteps _steps = ESteps.None;
internal LoadDependBundleFileOperation(List<LoadBundleFileOperation> dpends)
{
Depends = dpends;
}
internal override void InternalOnStart()
{
_steps = ESteps.CheckDepend;
}
internal override void InternalOnUpdate()
{
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
if (_steps == ESteps.CheckDepend)
{
foreach (var loader in Depends)
{
if (loader.IsDone == false)
return;
}
_steps = ESteps.CheckResult;
}
if (_steps == ESteps.CheckResult)
{
LoadBundleFileOperation failedLoader = null;
foreach (var loader in Depends)
{
if (loader.Status != EOperationStatus.Succeed)
{
failedLoader = loader;
break;
}
}
if (failedLoader == null)
{
_steps = ESteps.Done;
Status = EOperationStatus.Succeed;
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = failedLoader.Error;
}
}
}
internal override void InternalWaitForAsyncComplete()
{
while (true)
{
foreach (var loader in Depends)
{
loader.WaitForAsyncComplete();
}
if (ExecuteWhileDone())
{
_steps = ESteps.Done;
break;
}
}
}
/// <summary>
/// 增加引用计数
/// </summary>
public void Reference()
{
foreach (var loader in Depends)
{
loader.Reference();
}
}
/// <summary>
/// 减少引用计数
/// </summary>
public void Release()
{
foreach (var loader in Depends)
{
loader.Release();
}
}
/// <summary>
/// 获取资源包的调试信息列表
/// </summary>
internal void GetBundleDebugInfos(List<DebugBundleInfo> output)
{
foreach (var loader in Depends)
{
var bundleInfo = new DebugBundleInfo();
bundleInfo.BundleName = loader.BundleFileInfo.Bundle.BundleName;
bundleInfo.RefCount = loader.RefCount;
bundleInfo.Status = loader.Status;
output.Add(bundleInfo);
}
}
}
}

View File

@ -71,17 +71,19 @@ namespace YooAsset
Status = EOperationStatus.Succeed; Status = EOperationStatus.Succeed;
} }
} }
internal override void InternalWaitForAsyncComplete()
/// <summary>
/// 等待异步实例化结束
/// </summary>
public override void WaitForAsyncComplete()
{ {
if (_steps == ESteps.Clone) while (true)
{ {
_handle.WaitForAsyncComplete(); // 等待句柄完成
InternalOnUpdate(); if (_handle != null)
DebugCheckWaitForAsyncComplete(); _handle.WaitForAsyncComplete();
if (ExecuteWhileDone())
{
_steps = ESteps.Done;
break;
}
} }
} }

View File

@ -33,8 +33,8 @@ namespace YooAsset
if (_steps == ESteps.AbortDownload) if (_steps == ESteps.AbortDownload)
{ {
// 注意:终止所有下载任务 // 注意:终止所有下载任务
var loaderList = _resManager._loaderList; var loaderDic = _resManager._loaderDic;
foreach (var loader in loaderList) foreach (var loader in loaderDic.Values)
{ {
loader.AbortDownloadOperation(); loader.AbortDownloadOperation();
} }
@ -55,7 +55,6 @@ namespace YooAsset
if (_steps == ESteps.UnloadAll) if (_steps == ESteps.UnloadAll)
{ {
var loaderList = _resManager._loaderList;
var loaderDic = _resManager._loaderDic; var loaderDic = _resManager._loaderDic;
var providerDic = _resManager._providerDic; var providerDic = _resManager._providerDic;
@ -68,18 +67,17 @@ namespace YooAsset
// 强制销毁资源提供者 // 强制销毁资源提供者
foreach (var provider in providerDic.Values) foreach (var provider in providerDic.Values)
{ {
provider.Destroy(); provider.DestroyProvider();
} }
// 强制销毁文件加载器 // 强制销毁文件加载器
foreach (var loader in loaderList) foreach (var loader in loaderDic.Values)
{ {
loader.Destroy(); loader.DestroyLoader();
} }
// 清空数据 // 清空数据
providerDic.Clear(); providerDic.Clear();
loaderList.Clear();
loaderDic.Clear(); loaderDic.Clear();
_resManager.ClearSceneHandle(); _resManager.ClearSceneHandle();

View File

@ -20,14 +20,14 @@ namespace YooAsset
private ESteps _steps = ESteps.None; private ESteps _steps = ESteps.None;
private readonly string _error; private readonly string _error;
private readonly ProviderBase _provider; private readonly ProviderOperation _provider;
private AsyncOperation _asyncOp; private AsyncOperation _asyncOp;
internal UnloadSceneOperation(string error) internal UnloadSceneOperation(string error)
{ {
_error = error; _error = error;
} }
internal UnloadSceneOperation(ProviderBase provider) internal UnloadSceneOperation(ProviderOperation provider)
{ {
_error = null; _error = null;
_provider = provider; _provider = provider;

View File

@ -1,4 +1,6 @@
using UnityEngine; using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace YooAsset namespace YooAsset
{ {
@ -29,27 +31,32 @@ namespace YooAsset
if (_steps == ESteps.UnloadUnused) if (_steps == ESteps.UnloadUnused)
{ {
var loaderList = _resManager._loaderList;
var loaderDic = _resManager._loaderDic; var loaderDic = _resManager._loaderDic;
var removeList = new List<LoadBundleFileOperation>(loaderDic.Count);
for (int i = loaderList.Count - 1; i >= 0; i--) // 注意:优先销毁资源提供者
foreach (var loader in loaderDic.Values)
{ {
BundleFileLoader loader = loaderList[i];
loader.TryDestroyProviders(); loader.TryDestroyProviders();
} }
for (int i = loaderList.Count - 1; i >= 0; i--) // 获取销毁列表
foreach (var loader in loaderDic.Values)
{ {
BundleFileLoader loader = loaderList[i]; if (loader.CanDestroyLoader())
if (loader.CanDestroy())
{ {
string bundleName = loader.MainBundleInfo.Bundle.BundleName; removeList.Add(loader);
loader.Destroy();
loaderList.RemoveAt(i);
loaderDic.Remove(bundleName);
} }
} }
// 销毁文件加载器
foreach (var loader in removeList)
{
string bundleName = loader.BundleFileInfo.Bundle.BundleName;
loader.DestroyLoader();
_resManager._loaderDic.Remove(bundleName);
}
// 注意:调用底层接口释放所有资源 // 注意:调用底层接口释放所有资源
Resources.UnloadUnusedAssets(); Resources.UnloadUnusedAssets();
@ -57,10 +64,16 @@ namespace YooAsset
Status = EOperationStatus.Succeed; Status = EOperationStatus.Succeed;
} }
} }
public override void WaitForAsyncComplete() internal override void InternalWaitForAsyncComplete()
{ {
InternalOnUpdate(); while (true)
DebugCheckWaitForAsyncComplete(); {
if (ExecuteWhileDone())
{
_steps = ESteps.Done;
break;
}
}
} }
} }
} }

View File

@ -4,7 +4,7 @@ using UnityEngine;
namespace YooAsset namespace YooAsset
{ {
internal sealed class BundledAllAssetsProvider : ProviderBase internal sealed class BundledAllAssetsProvider : ProviderOperation
{ {
private AssetBundle _assetBundle; private AssetBundle _assetBundle;
private AssetBundleRequest _cacheRequest; private AssetBundleRequest _cacheRequest;
@ -29,45 +29,37 @@ namespace YooAsset
// 1. 检测资源包 // 1. 检测资源包
if (_steps == ESteps.CheckBundle) if (_steps == ESteps.CheckBundle)
{ {
if (IsWaitForAsyncComplete) if (LoadDependBundleFileOp.IsDone == false)
{
DependLoaders.WaitForAsyncComplete();
FileLoader.WaitForAsyncComplete();
}
if (DependLoaders.IsDone() == false)
return; return;
if (FileLoader.IsDone() == false) if (LoadBundleFileOp.IsDone == false)
return; return;
if (DependLoaders.IsSucceed() == false) if (LoadDependBundleFileOp.Status != EOperationStatus.Succeed)
{ {
string error = DependLoaders.GetLastError(); InvokeCompletion(LoadDependBundleFileOp.Error, EOperationStatus.Failed);
InvokeCompletion(error, EOperationStatus.Failed);
return; return;
} }
if (FileLoader.Status != BundleFileLoader.EStatus.Succeed) if (LoadBundleFileOp.Status != EOperationStatus.Succeed)
{ {
string error = FileLoader.LastError; InvokeCompletion(LoadBundleFileOp.Error, EOperationStatus.Failed);
InvokeCompletion(error, EOperationStatus.Failed);
return; return;
} }
if (FileLoader.Result == null) if (LoadBundleFileOp.Result == null)
{ {
ProcessFatalEvent(); ProcessFatalEvent();
return; return;
} }
if (FileLoader.Result is AssetBundle == false) if (LoadBundleFileOp.Result is AssetBundle == false)
{ {
string error = "Try load raw file using load assetbundle method !"; string error = "Try load raw file using load assetbundle method !";
InvokeCompletion(error, EOperationStatus.Failed); InvokeCompletion(error, EOperationStatus.Failed);
return; return;
} }
_assetBundle = FileLoader.Result as AssetBundle; _assetBundle = LoadBundleFileOp.Result as AssetBundle;
_steps = ESteps.Loading; _steps = ESteps.Loading;
} }
@ -115,9 +107,9 @@ namespace YooAsset
{ {
string error; string error;
if (MainAssetInfo.AssetType == null) if (MainAssetInfo.AssetType == null)
error = $"Failed to load all assets : {MainAssetInfo.AssetPath} AssetType : null AssetBundle : {FileLoader.MainBundleInfo.Bundle.BundleName}"; error = $"Failed to load all assets : {MainAssetInfo.AssetPath} AssetType : null AssetBundle : {LoadBundleFileOp.BundleFileInfo.Bundle.BundleName}";
else else
error = $"Failed to load all assets : {MainAssetInfo.AssetPath} AssetType : {MainAssetInfo.AssetType} AssetBundle : {FileLoader.MainBundleInfo.Bundle.BundleName}"; error = $"Failed to load all assets : {MainAssetInfo.AssetPath} AssetType : {MainAssetInfo.AssetType} AssetBundle : {LoadBundleFileOp.BundleFileInfo.Bundle.BundleName}";
YooLogger.Error(error); YooLogger.Error(error);
InvokeCompletion(error, EOperationStatus.Failed); InvokeCompletion(error, EOperationStatus.Failed);
} }

View File

@ -4,7 +4,7 @@ using UnityEngine;
namespace YooAsset namespace YooAsset
{ {
internal sealed class BundledAssetProvider : ProviderBase internal sealed class BundledAssetProvider : ProviderOperation
{ {
private AssetBundle _assetBundle; private AssetBundle _assetBundle;
private AssetBundleRequest _cacheRequest; private AssetBundleRequest _cacheRequest;
@ -29,45 +29,37 @@ namespace YooAsset
// 1. 检测资源包 // 1. 检测资源包
if (_steps == ESteps.CheckBundle) if (_steps == ESteps.CheckBundle)
{ {
if (IsWaitForAsyncComplete) if (LoadDependBundleFileOp.IsDone == false)
{
DependLoaders.WaitForAsyncComplete();
FileLoader.WaitForAsyncComplete();
}
if (DependLoaders.IsDone() == false)
return; return;
if (FileLoader.IsDone() == false) if (LoadBundleFileOp.IsDone == false)
return; return;
if (DependLoaders.IsSucceed() == false) if (LoadDependBundleFileOp.Status != EOperationStatus.Succeed)
{ {
string error = DependLoaders.GetLastError(); InvokeCompletion(LoadDependBundleFileOp.Error, EOperationStatus.Failed);
InvokeCompletion(error, EOperationStatus.Failed);
return; return;
} }
if (FileLoader.Status != BundleFileLoader.EStatus.Succeed) if (LoadBundleFileOp.Status != EOperationStatus.Succeed)
{ {
string error = FileLoader.LastError; InvokeCompletion(LoadBundleFileOp.Error, EOperationStatus.Failed);
InvokeCompletion(error, EOperationStatus.Failed);
return; return;
} }
if (FileLoader.Result == null) if (LoadBundleFileOp.Result == null)
{ {
ProcessFatalEvent(); ProcessFatalEvent();
return; return;
} }
if (FileLoader.Result is AssetBundle == false) if (LoadBundleFileOp.Result is AssetBundle == false)
{ {
string error = "Try load raw file using load assetbundle method !"; string error = "Try load raw file using load assetbundle method !";
InvokeCompletion(error, EOperationStatus.Failed); InvokeCompletion(error, EOperationStatus.Failed);
return; return;
} }
_assetBundle = FileLoader.Result as AssetBundle; _assetBundle = LoadBundleFileOp.Result as AssetBundle;
_steps = ESteps.Loading; _steps = ESteps.Loading;
} }
@ -115,9 +107,9 @@ namespace YooAsset
{ {
string error; string error;
if (MainAssetInfo.AssetType == null) if (MainAssetInfo.AssetType == null)
error = $"Failed to load asset : {MainAssetInfo.AssetPath} AssetType : null AssetBundle : {FileLoader.MainBundleInfo.Bundle.BundleName}"; error = $"Failed to load asset : {MainAssetInfo.AssetPath} AssetType : null AssetBundle : {LoadBundleFileOp.BundleFileInfo.Bundle.BundleName}";
else else
error = $"Failed to load asset : {MainAssetInfo.AssetPath} AssetType : {MainAssetInfo.AssetType} AssetBundle : {FileLoader.MainBundleInfo.Bundle.BundleName}"; error = $"Failed to load asset : {MainAssetInfo.AssetPath} AssetType : {MainAssetInfo.AssetType} AssetBundle : {LoadBundleFileOp.BundleFileInfo.Bundle.BundleName}";
YooLogger.Error(error); YooLogger.Error(error);
InvokeCompletion(error, EOperationStatus.Failed); InvokeCompletion(error, EOperationStatus.Failed);
} }

View File

@ -1,7 +1,7 @@
 
namespace YooAsset namespace YooAsset
{ {
internal class BundledRawFileProvider : ProviderBase internal class BundledRawFileProvider : ProviderOperation
{ {
public BundledRawFileProvider(ResourceManager manager, string providerGUID, AssetInfo assetInfo) : base(manager, providerGUID, assetInfo) public BundledRawFileProvider(ResourceManager manager, string providerGUID, AssetInfo assetInfo) : base(manager, providerGUID, assetInfo)
{ {
@ -23,20 +23,16 @@ namespace YooAsset
// 1. 检测资源包 // 1. 检测资源包
if (_steps == ESteps.CheckBundle) if (_steps == ESteps.CheckBundle)
{ {
if (IsWaitForAsyncComplete) if (LoadBundleFileOp.IsDone == false)
FileLoader.WaitForAsyncComplete();
if (FileLoader.IsDone() == false)
return; return;
if (FileLoader.Status != BundleFileLoader.EStatus.Succeed) if (LoadBundleFileOp.Status != EOperationStatus.Succeed)
{ {
string error = FileLoader.LastError; InvokeCompletion(LoadBundleFileOp.Error, EOperationStatus.Failed);
InvokeCompletion(error, EOperationStatus.Failed);
return; return;
} }
if (FileLoader.Result is string == false) if (LoadBundleFileOp.Result is string == false)
{ {
string error = "Try load AssetBundle file using load raw file method !"; string error = "Try load AssetBundle file using load raw file method !";
InvokeCompletion(error, EOperationStatus.Failed); InvokeCompletion(error, EOperationStatus.Failed);
@ -49,7 +45,7 @@ namespace YooAsset
// 2. 检测加载结果 // 2. 检测加载结果
if (_steps == ESteps.Checking) if (_steps == ESteps.Checking)
{ {
RawFilePath = FileLoader.Result as string; RawFilePath = LoadBundleFileOp.Result as string;
InvokeCompletion(string.Empty, EOperationStatus.Succeed); InvokeCompletion(string.Empty, EOperationStatus.Succeed);
} }
} }

View File

@ -6,7 +6,7 @@ using UnityEngine.SceneManagement;
namespace YooAsset namespace YooAsset
{ {
internal sealed class BundledSceneProvider : ProviderBase internal sealed class BundledSceneProvider : ProviderOperation
{ {
public readonly LoadSceneMode SceneMode; public readonly LoadSceneMode SceneMode;
private AsyncOperation _asyncOperation; private AsyncOperation _asyncOperation;
@ -35,28 +35,20 @@ namespace YooAsset
// 1. 检测资源包 // 1. 检测资源包
if (_steps == ESteps.CheckBundle) if (_steps == ESteps.CheckBundle)
{ {
if (IsWaitForAsyncComplete) if (LoadDependBundleFileOp.IsDone == false)
{
DependLoaders.WaitForAsyncComplete();
FileLoader.WaitForAsyncComplete();
}
if (DependLoaders.IsDone() == false)
return; return;
if (FileLoader.IsDone() == false) if (LoadBundleFileOp.IsDone == false)
return; return;
if (DependLoaders.IsSucceed() == false) if (LoadDependBundleFileOp.Status != EOperationStatus.Succeed)
{ {
string error = DependLoaders.GetLastError(); InvokeCompletion(LoadDependBundleFileOp.Error, EOperationStatus.Failed);
InvokeCompletion(error, EOperationStatus.Failed);
return; return;
} }
if (FileLoader.Status != BundleFileLoader.EStatus.Succeed) if (LoadBundleFileOp.Status != EOperationStatus.Succeed)
{ {
string error = FileLoader.LastError; InvokeCompletion(LoadBundleFileOp.Error, EOperationStatus.Failed);
InvokeCompletion(error, EOperationStatus.Failed);
return; return;
} }

View File

@ -4,7 +4,7 @@ using UnityEngine;
namespace YooAsset namespace YooAsset
{ {
internal sealed class BundledSubAssetsProvider : ProviderBase internal sealed class BundledSubAssetsProvider : ProviderOperation
{ {
private AssetBundle _assetBundle; private AssetBundle _assetBundle;
private AssetBundleRequest _cacheRequest; private AssetBundleRequest _cacheRequest;
@ -29,45 +29,37 @@ namespace YooAsset
// 1. 检测资源包 // 1. 检测资源包
if (_steps == ESteps.CheckBundle) if (_steps == ESteps.CheckBundle)
{ {
if (IsWaitForAsyncComplete) if (LoadDependBundleFileOp.IsDone == false)
{
DependLoaders.WaitForAsyncComplete();
FileLoader.WaitForAsyncComplete();
}
if (DependLoaders.IsDone() == false)
return; return;
if (FileLoader.IsDone() == false) if (LoadBundleFileOp.IsDone == false)
return; return;
if (DependLoaders.IsSucceed() == false) if (LoadDependBundleFileOp.Status != EOperationStatus.Succeed)
{ {
string error = DependLoaders.GetLastError(); InvokeCompletion(LoadDependBundleFileOp.Error, EOperationStatus.Failed);
InvokeCompletion(error, EOperationStatus.Failed);
return; return;
} }
if (FileLoader.Status != BundleFileLoader.EStatus.Succeed) if (LoadBundleFileOp.Status != EOperationStatus.Succeed)
{ {
string error = FileLoader.LastError; InvokeCompletion(LoadBundleFileOp.Error, EOperationStatus.Failed);
InvokeCompletion(error, EOperationStatus.Failed);
return; return;
} }
if (FileLoader.Result == null) if (LoadBundleFileOp.Result == null)
{ {
ProcessFatalEvent(); ProcessFatalEvent();
return; return;
} }
if (FileLoader.Result is AssetBundle == false) if (LoadBundleFileOp.Result is AssetBundle == false)
{ {
string error = "Try load raw file using load assetbundle method !"; string error = "Try load raw file using load assetbundle method !";
InvokeCompletion(error, EOperationStatus.Failed); InvokeCompletion(error, EOperationStatus.Failed);
return; return;
} }
_assetBundle = FileLoader.Result as AssetBundle; _assetBundle = LoadBundleFileOp.Result as AssetBundle;
_steps = ESteps.Loading; _steps = ESteps.Loading;
} }
@ -115,9 +107,9 @@ namespace YooAsset
{ {
string error; string error;
if (MainAssetInfo.AssetType == null) if (MainAssetInfo.AssetType == null)
error = $"Failed to load sub assets : {MainAssetInfo.AssetPath} AssetType : null AssetBundle : {FileLoader.MainBundleInfo.Bundle.BundleName}"; error = $"Failed to load sub assets : {MainAssetInfo.AssetPath} AssetType : null AssetBundle : {LoadBundleFileOp.BundleFileInfo.Bundle.BundleName}";
else else
error = $"Failed to load sub assets : {MainAssetInfo.AssetPath} AssetType : {MainAssetInfo.AssetType} AssetBundle : {FileLoader.MainBundleInfo.Bundle.BundleName}"; error = $"Failed to load sub assets : {MainAssetInfo.AssetPath} AssetType : {MainAssetInfo.AssetType} AssetBundle : {LoadBundleFileOp.BundleFileInfo.Bundle.BundleName}";
YooLogger.Error(error); YooLogger.Error(error);
InvokeCompletion(error, EOperationStatus.Failed); InvokeCompletion(error, EOperationStatus.Failed);
} }

View File

@ -1,9 +1,9 @@
 
namespace YooAsset namespace YooAsset
{ {
internal sealed class CompletedProvider : ProviderBase internal sealed class CompletedProvider : ProviderOperation
{ {
public CompletedProvider(AssetInfo assetInfo) : base(null, string.Empty, assetInfo) public CompletedProvider(ResourceManager manager, AssetInfo assetInfo) : base(manager, string.Empty, assetInfo)
{ {
} }

View File

@ -4,7 +4,7 @@ using UnityEngine;
namespace YooAsset namespace YooAsset
{ {
internal sealed class DatabaseAllAssetsProvider : ProviderBase internal sealed class DatabaseAllAssetsProvider : ProviderOperation
{ {
public DatabaseAllAssetsProvider(ResourceManager manager, string providerGUID, AssetInfo assetInfo) : base(manager, providerGUID, assetInfo) public DatabaseAllAssetsProvider(ResourceManager manager, string providerGUID, AssetInfo assetInfo) : base(manager, providerGUID, assetInfo)
{ {
@ -41,16 +41,12 @@ namespace YooAsset
// 1. 检测资源包 // 1. 检测资源包
if (_steps == ESteps.CheckBundle) if (_steps == ESteps.CheckBundle)
{ {
if (IsWaitForAsyncComplete) if (LoadBundleFileOp.IsDone == false)
FileLoader.WaitForAsyncComplete();
if (FileLoader.IsDone() == false)
return; return;
if (FileLoader.Status != BundleFileLoader.EStatus.Succeed) if (LoadBundleFileOp.Status != EOperationStatus.Succeed)
{ {
string error = FileLoader.LastError; InvokeCompletion(LoadBundleFileOp.Error, EOperationStatus.Failed);
InvokeCompletion(error, EOperationStatus.Failed);
return; return;
} }
@ -63,7 +59,7 @@ namespace YooAsset
if (MainAssetInfo.AssetType == null) if (MainAssetInfo.AssetType == null)
{ {
List<UnityEngine.Object> result = new List<Object>(); List<UnityEngine.Object> result = new List<Object>();
foreach (var assetPath in FileLoader.MainBundleInfo.IncludeAssetsInEditor) foreach (var assetPath in LoadBundleFileOp.BundleFileInfo.IncludeAssetsInEditor)
{ {
UnityEngine.Object mainAsset = UnityEditor.AssetDatabase.LoadMainAssetAtPath(assetPath); UnityEngine.Object mainAsset = UnityEditor.AssetDatabase.LoadMainAssetAtPath(assetPath);
if (mainAsset != null) if (mainAsset != null)
@ -74,7 +70,7 @@ namespace YooAsset
else else
{ {
List<UnityEngine.Object> result = new List<Object>(); List<UnityEngine.Object> result = new List<Object>();
foreach (var assetPath in FileLoader.MainBundleInfo.IncludeAssetsInEditor) foreach (var assetPath in LoadBundleFileOp.BundleFileInfo.IncludeAssetsInEditor)
{ {
UnityEngine.Object mainAsset = UnityEditor.AssetDatabase.LoadAssetAtPath(assetPath, MainAssetInfo.AssetType); UnityEngine.Object mainAsset = UnityEditor.AssetDatabase.LoadAssetAtPath(assetPath, MainAssetInfo.AssetType);
if (mainAsset != null) if (mainAsset != null)

View File

@ -4,7 +4,7 @@ using UnityEngine;
namespace YooAsset namespace YooAsset
{ {
internal sealed class DatabaseAssetProvider : ProviderBase internal sealed class DatabaseAssetProvider : ProviderOperation
{ {
public DatabaseAssetProvider(ResourceManager manager, string providerGUID, AssetInfo assetInfo) : base(manager, providerGUID, assetInfo) public DatabaseAssetProvider(ResourceManager manager, string providerGUID, AssetInfo assetInfo) : base(manager, providerGUID, assetInfo)
{ {
@ -41,16 +41,12 @@ namespace YooAsset
// 1. 检测资源包 // 1. 检测资源包
if (_steps == ESteps.CheckBundle) if (_steps == ESteps.CheckBundle)
{ {
if (IsWaitForAsyncComplete) if (LoadBundleFileOp.IsDone == false)
FileLoader.WaitForAsyncComplete();
if (FileLoader.IsDone() == false)
return; return;
if (FileLoader.Status != BundleFileLoader.EStatus.Succeed) if (LoadBundleFileOp.Status != EOperationStatus.Succeed)
{ {
string error = FileLoader.LastError; InvokeCompletion(LoadBundleFileOp.Error, EOperationStatus.Failed);
InvokeCompletion(error, EOperationStatus.Failed);
return; return;
} }

View File

@ -1,7 +1,7 @@
 
namespace YooAsset namespace YooAsset
{ {
internal class DatabaseRawFileProvider : ProviderBase internal class DatabaseRawFileProvider : ProviderOperation
{ {
public DatabaseRawFileProvider(ResourceManager manager, string providerGUID, AssetInfo assetInfo) : base(manager, providerGUID, assetInfo) public DatabaseRawFileProvider(ResourceManager manager, string providerGUID, AssetInfo assetInfo) : base(manager, providerGUID, assetInfo)
{ {
@ -38,16 +38,12 @@ namespace YooAsset
// 1. 检测资源包 // 1. 检测资源包
if (_steps == ESteps.CheckBundle) if (_steps == ESteps.CheckBundle)
{ {
if (IsWaitForAsyncComplete) if (LoadBundleFileOp.IsDone == false)
FileLoader.WaitForAsyncComplete();
if (FileLoader.IsDone() == false)
return; return;
if (FileLoader.Status != BundleFileLoader.EStatus.Succeed) if (LoadBundleFileOp.Status != EOperationStatus.Succeed)
{ {
string error = FileLoader.LastError; InvokeCompletion(LoadBundleFileOp.Error, EOperationStatus.Failed);
InvokeCompletion(error, EOperationStatus.Failed);
return; return;
} }

View File

@ -6,7 +6,7 @@ using UnityEngine.SceneManagement;
namespace YooAsset namespace YooAsset
{ {
internal sealed class DatabaseSceneProvider : ProviderBase internal sealed class DatabaseSceneProvider : ProviderOperation
{ {
public readonly LoadSceneMode SceneMode; public readonly LoadSceneMode SceneMode;
private bool _suspendLoadMode; private bool _suspendLoadMode;
@ -36,16 +36,12 @@ namespace YooAsset
// 1. 检测资源包 // 1. 检测资源包
if (_steps == ESteps.CheckBundle) if (_steps == ESteps.CheckBundle)
{ {
if (IsWaitForAsyncComplete) if (LoadBundleFileOp.IsDone == false)
FileLoader.WaitForAsyncComplete();
if (FileLoader.IsDone() == false)
return; return;
if (FileLoader.Status != BundleFileLoader.EStatus.Succeed) if (LoadBundleFileOp.Status != EOperationStatus.Succeed)
{ {
string error = FileLoader.LastError; InvokeCompletion(LoadBundleFileOp.Error, EOperationStatus.Failed);
InvokeCompletion(error, EOperationStatus.Failed);
return; return;
} }

View File

@ -4,7 +4,7 @@ using UnityEngine;
namespace YooAsset namespace YooAsset
{ {
internal sealed class DatabaseSubAssetsProvider : ProviderBase internal sealed class DatabaseSubAssetsProvider : ProviderOperation
{ {
public DatabaseSubAssetsProvider(ResourceManager manager, string providerGUID, AssetInfo assetInfo) : base(manager, providerGUID, assetInfo) public DatabaseSubAssetsProvider(ResourceManager manager, string providerGUID, AssetInfo assetInfo) : base(manager, providerGUID, assetInfo)
{ {
@ -41,16 +41,12 @@ namespace YooAsset
// 1. 检测资源包 // 1. 检测资源包
if (_steps == ESteps.CheckBundle) if (_steps == ESteps.CheckBundle)
{ {
if (IsWaitForAsyncComplete) if (LoadBundleFileOp.IsDone == false)
FileLoader.WaitForAsyncComplete();
if (FileLoader.IsDone() == false)
return; return;
if (FileLoader.Status != BundleFileLoader.EStatus.Succeed) if (LoadBundleFileOp.Status != EOperationStatus.Succeed)
{ {
string error = FileLoader.LastError; InvokeCompletion(LoadBundleFileOp.Error, EOperationStatus.Failed);
InvokeCompletion(error, EOperationStatus.Failed);
return; return;
} }

View File

@ -5,7 +5,7 @@ using System;
namespace YooAsset namespace YooAsset
{ {
internal abstract class ProviderBase : AsyncOperationBase internal abstract class ProviderOperation : AsyncOperationBase
{ {
protected enum ESteps protected enum ESteps
{ {
@ -68,47 +68,52 @@ namespace YooAsset
protected ESteps _steps = ESteps.None; protected ESteps _steps = ESteps.None;
protected BundleFileLoader FileLoader { private set; get; } protected LoadBundleFileOperation LoadBundleFileOp { private set; get; }
protected DependFileLoaders DependLoaders { private set; get; } protected LoadDependBundleFileOperation LoadDependBundleFileOp { private set; get; }
protected bool IsWaitForAsyncComplete { private set; get; } = false; protected bool IsWaitForAsyncComplete { private set; get; } = false;
private readonly List<HandleBase> _handles = new List<HandleBase>(); private readonly List<HandleBase> _handles = new List<HandleBase>();
public ProviderBase(ResourceManager manager, string providerGUID, AssetInfo assetInfo) public ProviderOperation(ResourceManager manager, string providerGUID, AssetInfo assetInfo)
{ {
ResourceMgr = manager; ResourceMgr = manager;
ProviderGUID = providerGUID; ProviderGUID = providerGUID;
MainAssetInfo = assetInfo; MainAssetInfo = assetInfo;
// 创建资源包加载器 if (string.IsNullOrEmpty(providerGUID) == false)
if (manager != null)
{ {
FileLoader = manager.CreateOwnerFileLoader(assetInfo); LoadBundleFileOp = manager.CreateMainBundleFileLoader(assetInfo);
FileLoader.Reference(); LoadBundleFileOp.Reference();
FileLoader.AddProvider(this); LoadBundleFileOp.AddProvider(this);
var dependList = manager.CreateDependFileLoaders(assetInfo); LoadDependBundleFileOp = manager.CreateDependFileLoaders(assetInfo);
DependLoaders = new DependFileLoaders(dependList); LoadDependBundleFileOp.Reference();
DependLoaders.Reference();
} }
} }
/// <summary> internal override void InternalWaitForAsyncComplete()
/// 等待异步执行完毕
/// </summary>
public override void WaitForAsyncComplete()
{ {
IsWaitForAsyncComplete = true; IsWaitForAsyncComplete = true;
// 注意:主动轮询更新完成同步加载 while (true)
InternalOnUpdate(); {
DebugCheckWaitForAsyncComplete($"Loading asset {MainAssetInfo.AssetPath}"); if (LoadDependBundleFileOp != null)
LoadDependBundleFileOp.WaitForAsyncComplete();
if (LoadBundleFileOp != null)
LoadBundleFileOp.WaitForAsyncComplete();
if (ExecuteWhileDone())
{
_steps = ESteps.Done;
break;
}
}
} }
/// <summary> /// <summary>
/// 销毁资源提供者 /// 销毁资源提供者
/// </summary> /// </summary>
public void Destroy() public void DestroyProvider()
{ {
IsDestroyed = true; IsDestroyed = true;
@ -120,22 +125,22 @@ namespace YooAsset
} }
// 释放资源包加载器 // 释放资源包加载器
if (FileLoader != null) if (LoadBundleFileOp != null)
{ {
FileLoader.Release(); LoadBundleFileOp.Release();
FileLoader = null; LoadBundleFileOp = null;
} }
if (DependLoaders != null) if (LoadDependBundleFileOp != null)
{ {
DependLoaders.Release(); LoadDependBundleFileOp.Release();
DependLoaders = null; LoadDependBundleFileOp = null;
} }
} }
/// <summary> /// <summary>
/// 是否可以销毁 /// 是否可以销毁
/// </summary> /// </summary>
public bool CanDestroy() public bool CanDestroyProvider()
{ {
// 注意:在进行资源加载过程时不可以销毁 // 注意:在进行资源加载过程时不可以销毁
if (_steps == ESteps.Loading || _steps == ESteps.Checking) if (_steps == ESteps.Loading || _steps == ESteps.Checking)
@ -202,10 +207,10 @@ namespace YooAsset
/// </summary> /// </summary>
protected void ProcessFatalEvent() protected void ProcessFatalEvent()
{ {
if (FileLoader.IsDestroyed) if (LoadBundleFileOp.IsDestroyed)
throw new System.Exception("Should never get here !"); throw new System.Exception("Should never get here !");
string error = $"The bundle {FileLoader.MainBundleInfo.Bundle.BundleName} has been destroyed by unity bugs !"; string error = $"The bundle {LoadBundleFileOp.BundleFileInfo.Bundle.BundleName} has been destroyed by unity bugs !";
YooLogger.Error(error); YooLogger.Error(error);
InvokeCompletion(Error, EOperationStatus.Failed); InvokeCompletion(Error, EOperationStatus.Failed);
} }
@ -239,11 +244,11 @@ namespace YooAsset
public DownloadStatus GetDownloadStatus() public DownloadStatus GetDownloadStatus()
{ {
DownloadStatus status = new DownloadStatus(); DownloadStatus status = new DownloadStatus();
status.TotalBytes = FileLoader.MainBundleInfo.Bundle.FileSize; status.TotalBytes = LoadBundleFileOp.BundleFileInfo.Bundle.FileSize;
status.DownloadedBytes = FileLoader.DownloadedBytes; status.DownloadedBytes = LoadBundleFileOp.DownloadedBytes;
foreach (var dependBundle in DependLoaders.DependList) foreach (var dependBundle in LoadDependBundleFileOp.Depends)
{ {
status.TotalBytes += dependBundle.MainBundleInfo.Bundle.FileSize; status.TotalBytes += dependBundle.BundleFileInfo.Bundle.FileSize;
status.DownloadedBytes += dependBundle.DownloadedBytes; status.DownloadedBytes += dependBundle.DownloadedBytes;
} }
@ -313,12 +318,12 @@ namespace YooAsset
internal void GetBundleDebugInfos(List<DebugBundleInfo> output) internal void GetBundleDebugInfos(List<DebugBundleInfo> output)
{ {
var bundleInfo = new DebugBundleInfo(); var bundleInfo = new DebugBundleInfo();
bundleInfo.BundleName = FileLoader.MainBundleInfo.Bundle.BundleName; bundleInfo.BundleName = LoadBundleFileOp.BundleFileInfo.Bundle.BundleName;
bundleInfo.RefCount = FileLoader.RefCount; bundleInfo.RefCount = LoadBundleFileOp.RefCount;
bundleInfo.Status = FileLoader.Status.ToString(); bundleInfo.Status = LoadBundleFileOp.Status;
output.Add(bundleInfo); output.Add(bundleInfo);
DependLoaders.GetBundleDebugInfos(output); LoadDependBundleFileOp.GetBundleDebugInfos(output);
} }
#endregion #endregion
} }

View File

@ -13,12 +13,10 @@ namespace YooAsset
private readonly static Dictionary<string, SceneHandle> _sceneHandles = new Dictionary<string, SceneHandle>(100); private readonly static Dictionary<string, SceneHandle> _sceneHandles = new Dictionary<string, SceneHandle>(100);
private static long _sceneCreateCount = 0; private static long _sceneCreateCount = 0;
internal readonly Dictionary<string, ProviderBase> _providerDic = new Dictionary<string, ProviderBase>(5000); internal readonly Dictionary<string, ProviderOperation> _providerDic = new Dictionary<string, ProviderOperation>(5000);
internal readonly Dictionary<string, BundleFileLoader> _loaderDic = new Dictionary<string, BundleFileLoader>(5000); internal readonly Dictionary<string, LoadBundleFileOperation> _loaderDic = new Dictionary<string, LoadBundleFileOperation>(5000);
internal readonly List<BundleFileLoader> _loaderList = new List<BundleFileLoader>(5000);
private bool _simulationOnEditor; private bool _simulationOnEditor;
private bool _autoDestroyAssetProvider;
private IBundleQuery _bundleQuery; private IBundleQuery _bundleQuery;
/// <summary> /// <summary>
@ -38,24 +36,9 @@ namespace YooAsset
public void Initialize(InitializeParameters initializeParameters, IBundleQuery bundleServices) public void Initialize(InitializeParameters initializeParameters, IBundleQuery bundleServices)
{ {
_simulationOnEditor = initializeParameters is EditorSimulateModeParameters; _simulationOnEditor = initializeParameters is EditorSimulateModeParameters;
_autoDestroyAssetProvider = initializeParameters.AutoDestroyAssetProvider;
_bundleQuery = bundleServices; _bundleQuery = bundleServices;
} }
/// <summary>
/// 更新
/// </summary>
public void Update()
{
foreach (var loader in _loaderList)
{
loader.Update();
if (_autoDestroyAssetProvider)
loader.TryDestroyProviders();
}
}
/// <summary> /// <summary>
/// 尝试卸载指定资源的资源包(包括依赖资源) /// 尝试卸载指定资源的资源包(包括依赖资源)
/// </summary> /// </summary>
@ -73,11 +56,10 @@ namespace YooAsset
if (mainLoader != null) if (mainLoader != null)
{ {
mainLoader.TryDestroyProviders(); mainLoader.TryDestroyProviders();
if (mainLoader.CanDestroy()) if (mainLoader.CanDestroyLoader())
{ {
string bundleName = mainLoader.MainBundleInfo.Bundle.BundleName; string bundleName = mainLoader.BundleFileInfo.Bundle.BundleName;
mainLoader.Destroy(); mainLoader.DestroyLoader();
_loaderList.Remove(mainLoader);
_loaderDic.Remove(bundleName); _loaderDic.Remove(bundleName);
} }
} }
@ -89,11 +71,10 @@ namespace YooAsset
var dependLoader = TryGetFileLoader(dependBundleName); var dependLoader = TryGetFileLoader(dependBundleName);
if (dependLoader != null) if (dependLoader != null)
{ {
if (dependLoader.CanDestroy()) if (dependLoader.CanDestroyLoader())
{ {
string bundleName = dependLoader.MainBundleInfo.Bundle.BundleName; string bundleName = dependLoader.BundleFileInfo.Bundle.BundleName;
dependLoader.Destroy(); dependLoader.DestroyLoader();
_loaderList.Remove(dependLoader);
_loaderDic.Remove(bundleName); _loaderDic.Remove(bundleName);
} }
} }
@ -110,7 +91,7 @@ namespace YooAsset
if (assetInfo.IsInvalid) if (assetInfo.IsInvalid)
{ {
YooLogger.Error($"Failed to load scene ! {assetInfo.Error}"); YooLogger.Error($"Failed to load scene ! {assetInfo.Error}");
CompletedProvider completedProvider = new CompletedProvider(assetInfo); CompletedProvider completedProvider = new CompletedProvider(this, assetInfo);
completedProvider.SetCompleted(assetInfo.Error); completedProvider.SetCompleted(assetInfo.Error);
return completedProvider.CreateHandle<SceneHandle>(); return completedProvider.CreateHandle<SceneHandle>();
} }
@ -123,7 +104,7 @@ namespace YooAsset
// 注意同一个场景的ProviderGUID每次加载都会变化 // 注意同一个场景的ProviderGUID每次加载都会变化
string providerGUID = $"{assetInfo.GUID}-{++_sceneCreateCount}"; string providerGUID = $"{assetInfo.GUID}-{++_sceneCreateCount}";
ProviderBase provider; ProviderOperation provider;
{ {
if (_simulationOnEditor) if (_simulationOnEditor)
provider = new DatabaseSceneProvider(this, providerGUID, assetInfo, sceneMode, suspendLoad); provider = new DatabaseSceneProvider(this, providerGUID, assetInfo, sceneMode, suspendLoad);
@ -149,13 +130,13 @@ namespace YooAsset
if (assetInfo.IsInvalid) if (assetInfo.IsInvalid)
{ {
YooLogger.Error($"Failed to load asset ! {assetInfo.Error}"); YooLogger.Error($"Failed to load asset ! {assetInfo.Error}");
CompletedProvider completedProvider = new CompletedProvider(assetInfo); CompletedProvider completedProvider = new CompletedProvider(this, assetInfo);
completedProvider.SetCompleted(assetInfo.Error); completedProvider.SetCompleted(assetInfo.Error);
return completedProvider.CreateHandle<AssetHandle>(); return completedProvider.CreateHandle<AssetHandle>();
} }
string providerGUID = nameof(LoadAssetAsync) + assetInfo.GUID; string providerGUID = nameof(LoadAssetAsync) + assetInfo.GUID;
ProviderBase provider = TryGetProvider(providerGUID); ProviderOperation provider = TryGetProvider(providerGUID);
if (provider == null) if (provider == null)
{ {
if (_simulationOnEditor) if (_simulationOnEditor)
@ -179,13 +160,13 @@ namespace YooAsset
if (assetInfo.IsInvalid) if (assetInfo.IsInvalid)
{ {
YooLogger.Error($"Failed to load sub assets ! {assetInfo.Error}"); YooLogger.Error($"Failed to load sub assets ! {assetInfo.Error}");
CompletedProvider completedProvider = new CompletedProvider(assetInfo); CompletedProvider completedProvider = new CompletedProvider(this, assetInfo);
completedProvider.SetCompleted(assetInfo.Error); completedProvider.SetCompleted(assetInfo.Error);
return completedProvider.CreateHandle<SubAssetsHandle>(); return completedProvider.CreateHandle<SubAssetsHandle>();
} }
string providerGUID = nameof(LoadSubAssetsAsync) + assetInfo.GUID; string providerGUID = nameof(LoadSubAssetsAsync) + assetInfo.GUID;
ProviderBase provider = TryGetProvider(providerGUID); ProviderOperation provider = TryGetProvider(providerGUID);
if (provider == null) if (provider == null)
{ {
if (_simulationOnEditor) if (_simulationOnEditor)
@ -209,13 +190,13 @@ namespace YooAsset
if (assetInfo.IsInvalid) if (assetInfo.IsInvalid)
{ {
YooLogger.Error($"Failed to load all assets ! {assetInfo.Error}"); YooLogger.Error($"Failed to load all assets ! {assetInfo.Error}");
CompletedProvider completedProvider = new CompletedProvider(assetInfo); CompletedProvider completedProvider = new CompletedProvider(this, assetInfo);
completedProvider.SetCompleted(assetInfo.Error); completedProvider.SetCompleted(assetInfo.Error);
return completedProvider.CreateHandle<AllAssetsHandle>(); return completedProvider.CreateHandle<AllAssetsHandle>();
} }
string providerGUID = nameof(LoadAllAssetsAsync) + assetInfo.GUID; string providerGUID = nameof(LoadAllAssetsAsync) + assetInfo.GUID;
ProviderBase provider = TryGetProvider(providerGUID); ProviderOperation provider = TryGetProvider(providerGUID);
if (provider == null) if (provider == null)
{ {
if (_simulationOnEditor) if (_simulationOnEditor)
@ -239,13 +220,13 @@ namespace YooAsset
if (assetInfo.IsInvalid) if (assetInfo.IsInvalid)
{ {
YooLogger.Error($"Failed to load raw file ! {assetInfo.Error}"); YooLogger.Error($"Failed to load raw file ! {assetInfo.Error}");
CompletedProvider completedProvider = new CompletedProvider(assetInfo); CompletedProvider completedProvider = new CompletedProvider(this, assetInfo);
completedProvider.SetCompleted(assetInfo.Error); completedProvider.SetCompleted(assetInfo.Error);
return completedProvider.CreateHandle<RawFileHandle>(); return completedProvider.CreateHandle<RawFileHandle>();
} }
string providerGUID = nameof(LoadRawFileAsync) + assetInfo.GUID; string providerGUID = nameof(LoadRawFileAsync) + assetInfo.GUID;
ProviderBase provider = TryGetProvider(providerGUID); ProviderOperation provider = TryGetProvider(providerGUID);
if (provider == null) if (provider == null)
{ {
if (_simulationOnEditor) if (_simulationOnEditor)
@ -311,23 +292,25 @@ namespace YooAsset
} }
} }
internal BundleFileLoader CreateOwnerFileLoader(AssetInfo assetInfo) internal LoadBundleFileOperation CreateMainBundleFileLoader(AssetInfo assetInfo)
{ {
BundleInfo bundleInfo = _bundleQuery.GetMainBundleInfo(assetInfo); BundleInfo bundleInfo = _bundleQuery.GetMainBundleInfo(assetInfo);
return CreateFileLoaderInternal(bundleInfo); return CreateFileLoaderInternal(bundleInfo);
} }
internal List<BundleFileLoader> CreateDependFileLoaders(AssetInfo assetInfo) internal LoadDependBundleFileOperation CreateDependFileLoaders(AssetInfo assetInfo)
{ {
BundleInfo[] depends = _bundleQuery.GetDependBundleInfos(assetInfo); BundleInfo[] bundleInfos = _bundleQuery.GetDependBundleInfos(assetInfo);
List<BundleFileLoader> result = new List<BundleFileLoader>(depends.Length); List<LoadBundleFileOperation> depends = new List<LoadBundleFileOperation>(bundleInfos.Length);
foreach (var bundleInfo in depends) foreach (var bundleInfo in bundleInfos)
{ {
BundleFileLoader dependLoader = CreateFileLoaderInternal(bundleInfo); LoadBundleFileOperation dependLoader = CreateFileLoaderInternal(bundleInfo);
result.Add(dependLoader); depends.Add(dependLoader);
} }
return result; var operation = new LoadDependBundleFileOperation(depends);
OperationSystem.StartOperation(PackageName, operation);
return operation;
} }
internal void RemoveBundleProviders(List<ProviderBase> removeList) internal void RemoveBundleProviders(List<ProviderOperation> removeList)
{ {
foreach (var provider in removeList) foreach (var provider in removeList)
{ {
@ -336,33 +319,33 @@ namespace YooAsset
} }
internal bool HasAnyLoader() internal bool HasAnyLoader()
{ {
return _loaderList.Count > 0; return _loaderDic.Count > 0;
} }
private BundleFileLoader CreateFileLoaderInternal(BundleInfo bundleInfo) private LoadBundleFileOperation CreateFileLoaderInternal(BundleInfo bundleInfo)
{ {
// 如果加载器已经存在 // 如果加载器已经存在
string bundleName = bundleInfo.Bundle.BundleName; string bundleName = bundleInfo.Bundle.BundleName;
BundleFileLoader loader = TryGetFileLoader(bundleName); LoadBundleFileOperation loaderOperation = TryGetFileLoader(bundleName);
if (loader != null) if (loaderOperation != null)
return loader; return loaderOperation;
// 新增下载需求 // 新增下载需求
loader = new BundleFileLoader(this, bundleInfo); loaderOperation = new LoadBundleFileOperation(this, bundleInfo);
_loaderList.Add(loader); OperationSystem.StartOperation(PackageName, loaderOperation);
_loaderDic.Add(bundleName, loader); _loaderDic.Add(bundleName, loaderOperation);
return loader; return loaderOperation;
} }
private BundleFileLoader TryGetFileLoader(string bundleName) private LoadBundleFileOperation TryGetFileLoader(string bundleName)
{ {
if (_loaderDic.TryGetValue(bundleName, out BundleFileLoader value)) if (_loaderDic.TryGetValue(bundleName, out LoadBundleFileOperation value))
return value; return value;
else else
return null; return null;
} }
private ProviderBase TryGetProvider(string providerGUID) private ProviderOperation TryGetProvider(string providerGUID)
{ {
if (_providerDic.TryGetValue(providerGUID, out ProviderBase value)) if (_providerDic.TryGetValue(providerGUID, out ProviderOperation value))
return value; return value;
else else
return null; return null;

View File

@ -42,9 +42,6 @@ namespace YooAsset
/// </summary> /// </summary>
internal void UpdatePackage() internal void UpdatePackage()
{ {
if (_resourceManager != null)
_resourceManager.Update();
if (_playModeImpl != null) if (_playModeImpl != null)
_playModeImpl.UpdatePlayMode(); _playModeImpl.UpdatePlayMode();
} }