mirror of https://github.com/tuyoogame/YooAsset
parent
29d456c065
commit
1ab7689174
|
@ -38,6 +38,10 @@ namespace YooAsset
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class InitializeParameters
|
public abstract class InitializeParameters
|
||||||
{
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// 同时加载Bundle文件的最大并发数
|
||||||
|
/// </summary>
|
||||||
|
public int BundleLoadingMaxConcurrency = int.MaxValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
@ -9,7 +9,8 @@ namespace YooAsset
|
||||||
private enum ESteps
|
private enum ESteps
|
||||||
{
|
{
|
||||||
None,
|
None,
|
||||||
LoadFile,
|
CheckConcurrency,
|
||||||
|
LoadBundleFile,
|
||||||
Done,
|
Done,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,17 +58,32 @@ namespace YooAsset
|
||||||
}
|
}
|
||||||
internal override void InternalStart()
|
internal override void InternalStart()
|
||||||
{
|
{
|
||||||
_steps = ESteps.LoadFile;
|
_steps = ESteps.CheckConcurrency;
|
||||||
}
|
}
|
||||||
internal override void InternalUpdate()
|
internal override void InternalUpdate()
|
||||||
{
|
{
|
||||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (_steps == ESteps.LoadFile)
|
if (_steps == ESteps.CheckConcurrency)
|
||||||
|
{
|
||||||
|
if (IsWaitForAsyncComplete)
|
||||||
|
{
|
||||||
|
_steps = ESteps.LoadBundleFile;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (_resourceManager.BundleLoadingIsBusy())
|
||||||
|
return;
|
||||||
|
_steps = ESteps.LoadBundleFile;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_steps == ESteps.LoadBundleFile)
|
||||||
{
|
{
|
||||||
if (_loadBundleOp == null)
|
if (_loadBundleOp == null)
|
||||||
{
|
{
|
||||||
|
_resourceManager.BundleLoadingCounter++;
|
||||||
_loadBundleOp = LoadBundleInfo.LoadBundleFile();
|
_loadBundleOp = LoadBundleInfo.LoadBundleFile();
|
||||||
_loadBundleOp.StartOperation();
|
_loadBundleOp.StartOperation();
|
||||||
AddChildOperation(_loadBundleOp);
|
AddChildOperation(_loadBundleOp);
|
||||||
|
@ -103,6 +119,9 @@ namespace YooAsset
|
||||||
Status = EOperationStatus.Failed;
|
Status = EOperationStatus.Failed;
|
||||||
Error = _loadBundleOp.Error;
|
Error = _loadBundleOp.Error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 统计计数减少
|
||||||
|
_resourceManager.BundleLoadingCounter--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
internal override void InternalWaitForAsyncComplete()
|
internal override void InternalWaitForAsyncComplete()
|
||||||
|
|
|
@ -14,6 +14,7 @@ namespace YooAsset
|
||||||
internal readonly List<SceneHandle> SceneHandles = new List<SceneHandle>(100);
|
internal readonly List<SceneHandle> SceneHandles = new List<SceneHandle>(100);
|
||||||
private long _sceneCreateIndex = 0;
|
private long _sceneCreateIndex = 0;
|
||||||
private IBundleQuery _bundleQuery;
|
private IBundleQuery _bundleQuery;
|
||||||
|
private int _bundleLoadingMaxConcurrency;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 所属包裹
|
/// 所属包裹
|
||||||
|
@ -25,6 +26,11 @@ namespace YooAsset
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool LockLoadOperation = false;
|
public bool LockLoadOperation = false;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 统计正在加载的Bundle文件数量
|
||||||
|
/// </summary>
|
||||||
|
public int BundleLoadingCounter = 0;
|
||||||
|
|
||||||
|
|
||||||
public ResourceManager(string packageName)
|
public ResourceManager(string packageName)
|
||||||
{
|
{
|
||||||
|
@ -34,8 +40,9 @@ namespace YooAsset
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 初始化
|
/// 初始化
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Initialize(IBundleQuery bundleServices)
|
public void Initialize(InitializeParameters parameters, IBundleQuery bundleServices)
|
||||||
{
|
{
|
||||||
|
_bundleLoadingMaxConcurrency = parameters.BundleLoadingMaxConcurrency;
|
||||||
_bundleQuery = bundleServices;
|
_bundleQuery = bundleServices;
|
||||||
SceneManager.sceneUnloaded += OnSceneUnloaded;
|
SceneManager.sceneUnloaded += OnSceneUnloaded;
|
||||||
}
|
}
|
||||||
|
@ -310,6 +317,10 @@ namespace YooAsset
|
||||||
{
|
{
|
||||||
return LoaderDic.Count > 0;
|
return LoaderDic.Count > 0;
|
||||||
}
|
}
|
||||||
|
internal bool BundleLoadingIsBusy()
|
||||||
|
{
|
||||||
|
return BundleLoadingCounter >= _bundleLoadingMaxConcurrency;
|
||||||
|
}
|
||||||
|
|
||||||
private LoadBundleFileOperation CreateBundleFileLoaderInternal(BundleInfo bundleInfo)
|
private LoadBundleFileOperation CreateBundleFileLoaderInternal(BundleInfo bundleInfo)
|
||||||
{
|
{
|
||||||
|
|
|
@ -100,7 +100,7 @@ namespace YooAsset
|
||||||
var playModeImpl = new PlayModeImpl(PackageName, _playMode);
|
var playModeImpl = new PlayModeImpl(PackageName, _playMode);
|
||||||
_bundleQuery = playModeImpl;
|
_bundleQuery = playModeImpl;
|
||||||
_playModeImpl = playModeImpl;
|
_playModeImpl = playModeImpl;
|
||||||
_resourceManager.Initialize(_bundleQuery);
|
_resourceManager.Initialize(parameters, _bundleQuery);
|
||||||
|
|
||||||
// 初始化资源系统
|
// 初始化资源系统
|
||||||
InitializationOperation initializeOperation;
|
InitializationOperation initializeOperation;
|
||||||
|
@ -162,6 +162,10 @@ namespace YooAsset
|
||||||
throw new Exception($"Editor simulate mode only support unity editor.");
|
throw new Exception($"Editor simulate mode only support unity editor.");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// 检测初始化参数
|
||||||
|
if (parameters.BundleLoadingMaxConcurrency <= 0)
|
||||||
|
throw new Exception($"{nameof(parameters.BundleLoadingMaxConcurrency)} value must be greater than zero.");
|
||||||
|
|
||||||
// 鉴定运行模式
|
// 鉴定运行模式
|
||||||
if (parameters is EditorSimulateModeParameters)
|
if (parameters is EditorSimulateModeParameters)
|
||||||
_playMode = EPlayMode.EditorSimulateMode;
|
_playMode = EPlayMode.EditorSimulateMode;
|
||||||
|
|
Loading…
Reference in New Issue