update asset system

增加了下载失败尝试次数的初始化参数
pull/86/head
hevinci 2023-03-22 17:14:58 +08:00
parent 49e0d9729d
commit 027ae02aa0
8 changed files with 39 additions and 12 deletions

View File

@ -20,7 +20,8 @@ namespace YooAsset
private bool _isUnloadSafe = true;
private string _packageName;
private bool _simulationOnEditor;
private int _loadingMaxNumber;
public int LoadingMaxNumber { private set; get; }
public int DownloadFailedTryAgain { private set; get; }
public IDecryptionServices DecryptionServices { private set; get; }
public IBundleServices BundleServices { private set; get; }
@ -29,11 +30,13 @@ namespace YooAsset
/// 初始化
/// 注意在使用AssetSystem之前需要初始化
/// </summary>
public void Initialize(string packageName, bool simulationOnEditor, int loadingMaxNumber, IDecryptionServices decryptionServices, IBundleServices bundleServices)
public void Initialize(string packageName, bool simulationOnEditor, int loadingMaxNumber, int downloadFailedTryAgain,
IDecryptionServices decryptionServices, IBundleServices bundleServices)
{
_packageName = packageName;
_simulationOnEditor = simulationOnEditor;
_loadingMaxNumber = loadingMaxNumber;
LoadingMaxNumber = loadingMaxNumber;
DownloadFailedTryAgain = downloadFailedTryAgain;
DecryptionServices = decryptionServices;
BundleServices = bundleServices;
}
@ -63,7 +66,7 @@ namespace YooAsset
}
else
{
if (loadingCount < _loadingMaxNumber)
if (loadingCount < LoadingMaxNumber)
provider.Update();
if (provider.IsDone == false)

View File

@ -81,7 +81,7 @@ namespace YooAsset
// 1. 从服务器下载
if (_steps == ESteps.Download)
{
int failedTryAgain = int.MaxValue;
int failedTryAgain = Impl.DownloadFailedTryAgain;
_downloader = DownloadSystem.BeginDownload(MainBundleInfo, failedTryAgain);
_steps = ESteps.CheckDownload;
}

View File

@ -70,7 +70,7 @@ namespace YooAsset
// 1. 从服务器下载
if (_steps == ESteps.Download)
{
int failedTryAgain = int.MaxValue;
int failedTryAgain = Impl.DownloadFailedTryAgain;
_downloader = DownloadSystem.BeginDownload(MainBundleInfo, failedTryAgain);
_steps = ESteps.CheckDownload;
}

View File

@ -63,7 +63,7 @@ namespace YooAsset
// 1. 下载远端文件
if (_steps == ESteps.Download)
{
int failedTryAgain = int.MaxValue;
int failedTryAgain = Impl.DownloadFailedTryAgain;
_downloader = DownloadSystem.BeginDownload(MainBundleInfo, failedTryAgain);
_steps = ESteps.CheckDownload;
}

View File

@ -61,7 +61,7 @@ namespace YooAsset
// 1. 下载远端文件
if (_steps == ESteps.Download)
{
int failedTryAgain = int.MaxValue;
int failedTryAgain = Impl.DownloadFailedTryAgain;
_downloader = DownloadSystem.BeginDownload(MainBundleInfo, failedTryAgain);
_steps = ESteps.CheckDownload;
}

View File

@ -43,6 +43,11 @@ namespace YooAsset
/// 注意默认值为MaxValue
/// </summary>
public int AssetLoadingMaxNumber = int.MaxValue;
/// <summary>
/// 下载失败尝试次数
/// </summary>
public int DownloadFailedTryAgain = int.MaxValue;
}
/// <summary>

View File

@ -74,6 +74,14 @@ namespace YooAsset
}
}
/// <summary>
/// 反序列化JSON文件
/// </summary>
public static PackageManifest DeserializeFromJson(string jsonContent)
{
return JsonUtility.FromJson<PackageManifest>(jsonContent);
}
/// <summary>
/// 反序列化(二进制文件)
/// </summary>

View File

@ -87,7 +87,9 @@ namespace YooAsset
var editorSimulateModeImpl = new EditorSimulateModeImpl();
_bundleServices = editorSimulateModeImpl;
_playModeServices = editorSimulateModeImpl;
_assetSystemImpl.Initialize(PackageName, true, parameters.AssetLoadingMaxNumber, parameters.DecryptionServices, _bundleServices);
_assetSystemImpl.Initialize(PackageName, true,
parameters.AssetLoadingMaxNumber, parameters.DownloadFailedTryAgain,
parameters.DecryptionServices, _bundleServices);
var initializeParameters = parameters as EditorSimulateModeParameters;
initializeOperation = editorSimulateModeImpl.InitializeAsync(initializeParameters.LocationToLower, initializeParameters.SimulateManifestFilePath);
@ -97,7 +99,9 @@ namespace YooAsset
var offlinePlayModeImpl = new OfflinePlayModeImpl();
_bundleServices = offlinePlayModeImpl;
_playModeServices = offlinePlayModeImpl;
_assetSystemImpl.Initialize(PackageName, false, parameters.AssetLoadingMaxNumber, parameters.DecryptionServices, _bundleServices);
_assetSystemImpl.Initialize(PackageName, false,
parameters.AssetLoadingMaxNumber, parameters.DownloadFailedTryAgain,
parameters.DecryptionServices, _bundleServices);
var initializeParameters = parameters as OfflinePlayModeParameters;
initializeOperation = offlinePlayModeImpl.InitializeAsync(PackageName, initializeParameters.LocationToLower);
@ -107,7 +111,9 @@ namespace YooAsset
var hostPlayModeImpl = new HostPlayModeImpl();
_bundleServices = hostPlayModeImpl;
_playModeServices = hostPlayModeImpl;
_assetSystemImpl.Initialize(PackageName, false, parameters.AssetLoadingMaxNumber, parameters.DecryptionServices, _bundleServices);
_assetSystemImpl.Initialize(PackageName, false,
parameters.AssetLoadingMaxNumber, parameters.DownloadFailedTryAgain,
parameters.DecryptionServices, _bundleServices);
var initializeParameters = parameters as HostPlayModeParameters;
initializeOperation = hostPlayModeImpl.InitializeAsync(
@ -187,6 +193,11 @@ namespace YooAsset
parameters.AssetLoadingMaxNumber = 1;
YooLogger.Warning($"{nameof(parameters.AssetLoadingMaxNumber)} minimum value is 1");
}
if (parameters.DownloadFailedTryAgain < 1)
{
parameters.DownloadFailedTryAgain = 1;
YooLogger.Warning($"{nameof(parameters.DownloadFailedTryAgain)} minimum value is 1");
}
}
private void InitializeOperation_Completed(AsyncOperationBase op)
{