update download system

webgl平台支持下载器
mlyDevMerge1.5.7
hevinci 2023-09-27 16:54:44 +08:00 committed by QiJing
parent a366b08699
commit 00f973b66f
3 changed files with 122 additions and 31 deletions

View File

@ -95,9 +95,6 @@ namespace YooAsset
_steps = ESteps.Done;
Status = EStatus.Succeed;
}
// 注意:释放下载句柄
_downloader.DisposeHandler();
}
}

View File

@ -22,10 +22,10 @@ namespace YooAsset
Done,
}
private bool _keepDownloadHandleLife = false;
private DownloadHandlerAssetBundle _downloadhandler;
private ESteps _steps = ESteps.None;
private bool _getAssetBundle = false;
private AssetBundle _cacheAssetBundle;
public WebDownloader(BundleInfo bundleInfo, int failedTryAgain, int timeout) : base(bundleInfo, failedTryAgain, timeout)
{
@ -34,7 +34,10 @@ namespace YooAsset
{
if (_steps == ESteps.None)
{
_keepDownloadHandleLife = (bool)param[0];
if (param.Length > 0)
{
_getAssetBundle = (bool)param[0];
}
_steps = ESteps.PrepareDownload;
}
}
@ -135,11 +138,18 @@ namespace YooAsset
_lastCode = 0;
}
// 最终释放请求
DisposeRequest();
if (_getAssetBundle)
{
_cacheAssetBundle = _downloadhandler.assetBundle;
if (_cacheAssetBundle == null)
{
_lastError = "assetBundle is null";
_steps = ESteps.TryAgain;
}
}
if (_keepDownloadHandleLife == false)
DisposeHandler();
// 最终释放请求
DisposeRequest();
}
// 重新尝试下载
@ -148,7 +158,6 @@ namespace YooAsset
if (_failedTryAgain <= 0)
{
DisposeRequest();
DisposeHandler();
ReportError();
_status = EStatus.Failed;
_steps = ESteps.Done;
@ -175,7 +184,6 @@ namespace YooAsset
_lastCode = 0;
DisposeRequest();
DisposeHandler();
}
}
private void DisposeRequest()
@ -185,6 +193,11 @@ namespace YooAsset
_webRequest.Dispose();
_webRequest = null;
}
if (_downloadhandler != null)
{
_downloadhandler.Dispose();
_downloadhandler = null;
}
}
/// <summary>
@ -192,22 +205,7 @@ namespace YooAsset
/// </summary>
public AssetBundle GetAssetBundle()
{
if (_downloadhandler != null)
return _downloadhandler.assetBundle;
return null;
}
/// <summary>
/// 释放下载句柄
/// </summary>
public void DisposeHandler()
{
if (_downloadhandler != null)
{
_downloadhandler.Dispose();
_downloadhandler = null;
}
return _cacheAssetBundle;
}
}
}

View File

@ -33,6 +33,16 @@ namespace YooAsset
}
// 下载相关
private List<BundleInfo> ConvertToDownloadList(List<PackageBundle> downloadList)
{
List<BundleInfo> result = new List<BundleInfo>(downloadList.Count);
foreach (var packageBundle in downloadList)
{
var bundleInfo = ConvertToDownloadInfo(packageBundle);
result.Add(bundleInfo);
}
return result;
}
private BundleInfo ConvertToDownloadInfo(PackageBundle packageBundle)
{
string remoteMainURL = _remoteServices.GetRemoteMainURL(packageBundle.FileName);
@ -84,15 +94,101 @@ namespace YooAsset
ResourceDownloaderOperation IPlayModeServices.CreateResourceDownloaderByAll(int downloadingMaxNumber, int failedTryAgain, int timeout)
{
return ResourceDownloaderOperation.CreateEmptyDownloader(downloadingMaxNumber, failedTryAgain, timeout);
List<BundleInfo> downloadList = GetDownloadListByAll(_activeManifest);
var operation = new ResourceDownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain, timeout);
return operation;
}
public List<BundleInfo> GetDownloadListByAll(PackageManifest manifest)
{
List<PackageBundle> downloadList = new List<PackageBundle>(1000);
foreach (var packageBundle in manifest.BundleList)
{
// 忽略APP资源
if (IsBuildinPackageBundle(packageBundle))
continue;
downloadList.Add(packageBundle);
}
return ConvertToDownloadList(downloadList);
}
ResourceDownloaderOperation IPlayModeServices.CreateResourceDownloaderByTags(string[] tags, int downloadingMaxNumber, int failedTryAgain, int timeout)
{
return ResourceDownloaderOperation.CreateEmptyDownloader(downloadingMaxNumber, failedTryAgain, timeout);
List<BundleInfo> downloadList = GetDownloadListByTags(_activeManifest, tags);
var operation = new ResourceDownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain, timeout);
return operation;
}
public List<BundleInfo> GetDownloadListByTags(PackageManifest manifest, string[] tags)
{
List<PackageBundle> downloadList = new List<PackageBundle>(1000);
foreach (var packageBundle in manifest.BundleList)
{
// 忽略APP资源
if (IsBuildinPackageBundle(packageBundle))
continue;
// 如果未带任何标记,则统一下载
if (packageBundle.HasAnyTags() == false)
{
downloadList.Add(packageBundle);
}
else
{
// 查询DLC资源
if (packageBundle.HasTag(tags))
{
downloadList.Add(packageBundle);
}
}
}
return ConvertToDownloadList(downloadList);
}
ResourceDownloaderOperation IPlayModeServices.CreateResourceDownloaderByPaths(AssetInfo[] assetInfos, int downloadingMaxNumber, int failedTryAgain, int timeout)
{
return ResourceDownloaderOperation.CreateEmptyDownloader(downloadingMaxNumber, failedTryAgain, timeout);
List<BundleInfo> downloadList = GetDownloadListByPaths(_activeManifest, assetInfos);
var operation = new ResourceDownloaderOperation(downloadList, downloadingMaxNumber, failedTryAgain, timeout);
return operation;
}
public List<BundleInfo> GetDownloadListByPaths(PackageManifest manifest, AssetInfo[] assetInfos)
{
// 获取资源对象的资源包和所有依赖资源包
List<PackageBundle> checkList = new List<PackageBundle>();
foreach (var assetInfo in assetInfos)
{
if (assetInfo.IsInvalid)
{
YooLogger.Warning(assetInfo.Error);
continue;
}
// 注意:如果清单里未找到资源包会抛出异常!
PackageBundle mainBundle = manifest.GetMainPackageBundle(assetInfo.AssetPath);
if (checkList.Contains(mainBundle) == false)
checkList.Add(mainBundle);
// 注意:如果清单里未找到资源包会抛出异常!
PackageBundle[] dependBundles = manifest.GetAllDependencies(assetInfo.AssetPath);
foreach (var dependBundle in dependBundles)
{
if (checkList.Contains(dependBundle) == false)
checkList.Add(dependBundle);
}
}
List<PackageBundle> downloadList = new List<PackageBundle>(1000);
foreach (var packageBundle in checkList)
{
// 忽略APP资源
if (IsBuildinPackageBundle(packageBundle))
continue;
downloadList.Add(packageBundle);
}
return ConvertToDownloadList(downloadList);
}
ResourceUnpackerOperation IPlayModeServices.CreateResourceUnpackerByAll(int upackingMaxNumber, int failedTryAgain, int timeout)