mirror of https://github.com/tuyoogame/YooAsset
update asset system
新增了初始化参数LoadingMaxTimeSlice 移除了参数AssetLoadingMaxNumberpull/86/head
parent
82c83fcdf7
commit
c60cc1e84f
|
@ -1,6 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.SceneManagement;
|
using UnityEngine.SceneManagement;
|
||||||
|
|
||||||
|
@ -20,25 +21,37 @@ namespace YooAsset
|
||||||
private bool _isUnloadSafe = true;
|
private bool _isUnloadSafe = true;
|
||||||
private string _packageName;
|
private string _packageName;
|
||||||
private bool _simulationOnEditor;
|
private bool _simulationOnEditor;
|
||||||
public int LoadingMaxNumber { private set; get; }
|
private long _loadingMaxTimeSlice;
|
||||||
public int DownloadFailedTryAgain { private set; get; }
|
public int DownloadFailedTryAgain { private set; get; }
|
||||||
public IDecryptionServices DecryptionServices { private set; get; }
|
public IDecryptionServices DecryptionServices { private set; get; }
|
||||||
public IBundleServices BundleServices { private set; get; }
|
public IBundleServices BundleServices { private set; get; }
|
||||||
|
|
||||||
|
// 计时器相关
|
||||||
|
private Stopwatch _watch;
|
||||||
|
private long _frameTime;
|
||||||
|
private bool IsBusy
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
return _watch.ElapsedMilliseconds - _frameTime >= _loadingMaxTimeSlice;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 初始化
|
/// 初始化
|
||||||
/// 注意:在使用AssetSystem之前需要初始化
|
/// 注意:在使用AssetSystem之前需要初始化
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Initialize(string packageName, bool simulationOnEditor, int loadingMaxNumber, int downloadFailedTryAgain,
|
public void Initialize(string packageName, bool simulationOnEditor, long loadingMaxTimeSlice, int downloadFailedTryAgain,
|
||||||
IDecryptionServices decryptionServices, IBundleServices bundleServices)
|
IDecryptionServices decryptionServices, IBundleServices bundleServices)
|
||||||
{
|
{
|
||||||
_packageName = packageName;
|
_packageName = packageName;
|
||||||
_simulationOnEditor = simulationOnEditor;
|
_simulationOnEditor = simulationOnEditor;
|
||||||
LoadingMaxNumber = loadingMaxNumber;
|
_loadingMaxTimeSlice = loadingMaxTimeSlice;
|
||||||
DownloadFailedTryAgain = downloadFailedTryAgain;
|
DownloadFailedTryAgain = downloadFailedTryAgain;
|
||||||
DecryptionServices = decryptionServices;
|
DecryptionServices = decryptionServices;
|
||||||
BundleServices = bundleServices;
|
BundleServices = bundleServices;
|
||||||
|
_watch = Stopwatch.StartNew();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -46,6 +59,8 @@ namespace YooAsset
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Update()
|
public void Update()
|
||||||
{
|
{
|
||||||
|
_frameTime = _watch.ElapsedMilliseconds;
|
||||||
|
|
||||||
// 更新加载器
|
// 更新加载器
|
||||||
foreach (var loader in _loaderList)
|
foreach (var loader in _loaderList)
|
||||||
{
|
{
|
||||||
|
@ -56,22 +71,11 @@ namespace YooAsset
|
||||||
// 注意:循环更新的时候,可能会扩展列表
|
// 注意:循环更新的时候,可能会扩展列表
|
||||||
// 注意:不能限制场景对象的加载
|
// 注意:不能限制场景对象的加载
|
||||||
_isUnloadSafe = false;
|
_isUnloadSafe = false;
|
||||||
int loadingCount = 0;
|
|
||||||
for (int i = 0; i < _providerList.Count; i++)
|
for (int i = 0; i < _providerList.Count; i++)
|
||||||
{
|
{
|
||||||
var provider = _providerList[i];
|
if (IsBusy)
|
||||||
if (provider.IsSceneProvider())
|
break;
|
||||||
{
|
_providerList[i].Update();
|
||||||
provider.Update();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (loadingCount < LoadingMaxNumber)
|
|
||||||
provider.Update();
|
|
||||||
|
|
||||||
if (provider.IsDone == false)
|
|
||||||
loadingCount++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
_isUnloadSafe = true;
|
_isUnloadSafe = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,13 +39,14 @@ namespace YooAsset
|
||||||
public IDecryptionServices DecryptionServices = null;
|
public IDecryptionServices DecryptionServices = null;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 资源加载的最大数量
|
/// 资源加载每帧处理的最大时间片段
|
||||||
/// 注意:默认值为MaxValue
|
/// 注意:默认值为MaxValue
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int AssetLoadingMaxNumber = int.MaxValue;
|
public long LoadingMaxTimeSlice = long.MaxValue;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 下载失败尝试次数
|
/// 下载失败尝试次数
|
||||||
|
/// 注意:默认值为MaxValue
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int DownloadFailedTryAgain = int.MaxValue;
|
public int DownloadFailedTryAgain = int.MaxValue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -88,7 +88,7 @@ namespace YooAsset
|
||||||
_bundleServices = editorSimulateModeImpl;
|
_bundleServices = editorSimulateModeImpl;
|
||||||
_playModeServices = editorSimulateModeImpl;
|
_playModeServices = editorSimulateModeImpl;
|
||||||
_assetSystemImpl.Initialize(PackageName, true,
|
_assetSystemImpl.Initialize(PackageName, true,
|
||||||
parameters.AssetLoadingMaxNumber, parameters.DownloadFailedTryAgain,
|
parameters.LoadingMaxTimeSlice, parameters.DownloadFailedTryAgain,
|
||||||
parameters.DecryptionServices, _bundleServices);
|
parameters.DecryptionServices, _bundleServices);
|
||||||
|
|
||||||
var initializeParameters = parameters as EditorSimulateModeParameters;
|
var initializeParameters = parameters as EditorSimulateModeParameters;
|
||||||
|
@ -100,7 +100,7 @@ namespace YooAsset
|
||||||
_bundleServices = offlinePlayModeImpl;
|
_bundleServices = offlinePlayModeImpl;
|
||||||
_playModeServices = offlinePlayModeImpl;
|
_playModeServices = offlinePlayModeImpl;
|
||||||
_assetSystemImpl.Initialize(PackageName, false,
|
_assetSystemImpl.Initialize(PackageName, false,
|
||||||
parameters.AssetLoadingMaxNumber, parameters.DownloadFailedTryAgain,
|
parameters.LoadingMaxTimeSlice, parameters.DownloadFailedTryAgain,
|
||||||
parameters.DecryptionServices, _bundleServices);
|
parameters.DecryptionServices, _bundleServices);
|
||||||
|
|
||||||
var initializeParameters = parameters as OfflinePlayModeParameters;
|
var initializeParameters = parameters as OfflinePlayModeParameters;
|
||||||
|
@ -112,7 +112,7 @@ namespace YooAsset
|
||||||
_bundleServices = hostPlayModeImpl;
|
_bundleServices = hostPlayModeImpl;
|
||||||
_playModeServices = hostPlayModeImpl;
|
_playModeServices = hostPlayModeImpl;
|
||||||
_assetSystemImpl.Initialize(PackageName, false,
|
_assetSystemImpl.Initialize(PackageName, false,
|
||||||
parameters.AssetLoadingMaxNumber, parameters.DownloadFailedTryAgain,
|
parameters.LoadingMaxTimeSlice, parameters.DownloadFailedTryAgain,
|
||||||
parameters.DecryptionServices, _bundleServices);
|
parameters.DecryptionServices, _bundleServices);
|
||||||
|
|
||||||
var initializeParameters = parameters as HostPlayModeParameters;
|
var initializeParameters = parameters as HostPlayModeParameters;
|
||||||
|
@ -188,10 +188,10 @@ namespace YooAsset
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
|
|
||||||
// 检测参数范围
|
// 检测参数范围
|
||||||
if (parameters.AssetLoadingMaxNumber < 1)
|
if (parameters.LoadingMaxTimeSlice < 10)
|
||||||
{
|
{
|
||||||
parameters.AssetLoadingMaxNumber = 1;
|
parameters.LoadingMaxTimeSlice = 10;
|
||||||
YooLogger.Warning($"{nameof(parameters.AssetLoadingMaxNumber)} minimum value is 1");
|
YooLogger.Warning($"{nameof(parameters.LoadingMaxTimeSlice)} minimum value is 10 milliseconds.");
|
||||||
}
|
}
|
||||||
if (parameters.DownloadFailedTryAgain < 1)
|
if (parameters.DownloadFailedTryAgain < 1)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue