mirror of https://github.com/tuyoogame/YooAsset
parent
ca89113c67
commit
880d498618
|
@ -95,9 +95,6 @@ namespace YooAsset
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
Status = EStatus.Succeed;
|
Status = EStatus.Succeed;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 注意:释放下载句柄
|
|
||||||
_downloader.DisposeHandler();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,10 +22,10 @@ namespace YooAsset
|
||||||
Done,
|
Done,
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool _keepDownloadHandleLife = false;
|
|
||||||
private DownloadHandlerAssetBundle _downloadhandler;
|
private DownloadHandlerAssetBundle _downloadhandler;
|
||||||
private ESteps _steps = ESteps.None;
|
private ESteps _steps = ESteps.None;
|
||||||
|
private bool _getAssetBundle = false;
|
||||||
|
private AssetBundle _cacheAssetBundle;
|
||||||
|
|
||||||
public WebDownloader(BundleInfo bundleInfo, int failedTryAgain, int timeout) : base(bundleInfo, failedTryAgain, timeout)
|
public WebDownloader(BundleInfo bundleInfo, int failedTryAgain, int timeout) : base(bundleInfo, failedTryAgain, timeout)
|
||||||
{
|
{
|
||||||
|
@ -34,7 +34,10 @@ namespace YooAsset
|
||||||
{
|
{
|
||||||
if (_steps == ESteps.None)
|
if (_steps == ESteps.None)
|
||||||
{
|
{
|
||||||
_keepDownloadHandleLife = (bool)param[0];
|
if (param.Length > 0)
|
||||||
|
{
|
||||||
|
_getAssetBundle = (bool)param[0];
|
||||||
|
}
|
||||||
_steps = ESteps.PrepareDownload;
|
_steps = ESteps.PrepareDownload;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -135,11 +138,18 @@ namespace YooAsset
|
||||||
_lastCode = 0;
|
_lastCode = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (_getAssetBundle)
|
||||||
|
{
|
||||||
|
_cacheAssetBundle = _downloadhandler.assetBundle;
|
||||||
|
if (_cacheAssetBundle == null)
|
||||||
|
{
|
||||||
|
_lastError = "assetBundle is null";
|
||||||
|
_steps = ESteps.TryAgain;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 最终释放请求
|
// 最终释放请求
|
||||||
DisposeRequest();
|
DisposeRequest();
|
||||||
|
|
||||||
if (_keepDownloadHandleLife == false)
|
|
||||||
DisposeHandler();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 重新尝试下载
|
// 重新尝试下载
|
||||||
|
@ -148,7 +158,6 @@ namespace YooAsset
|
||||||
if (_failedTryAgain <= 0)
|
if (_failedTryAgain <= 0)
|
||||||
{
|
{
|
||||||
DisposeRequest();
|
DisposeRequest();
|
||||||
DisposeHandler();
|
|
||||||
ReportError();
|
ReportError();
|
||||||
_status = EStatus.Failed;
|
_status = EStatus.Failed;
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
|
@ -175,7 +184,6 @@ namespace YooAsset
|
||||||
_lastCode = 0;
|
_lastCode = 0;
|
||||||
|
|
||||||
DisposeRequest();
|
DisposeRequest();
|
||||||
DisposeHandler();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void DisposeRequest()
|
private void DisposeRequest()
|
||||||
|
@ -185,6 +193,11 @@ namespace YooAsset
|
||||||
_webRequest.Dispose();
|
_webRequest.Dispose();
|
||||||
_webRequest = null;
|
_webRequest = null;
|
||||||
}
|
}
|
||||||
|
if (_downloadhandler != null)
|
||||||
|
{
|
||||||
|
_downloadhandler.Dispose();
|
||||||
|
_downloadhandler = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -192,22 +205,7 @@ namespace YooAsset
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public AssetBundle GetAssetBundle()
|
public AssetBundle GetAssetBundle()
|
||||||
{
|
{
|
||||||
if (_downloadhandler != null)
|
return _cacheAssetBundle;
|
||||||
return _downloadhandler.assetBundle;
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 释放下载句柄
|
|
||||||
/// </summary>
|
|
||||||
public void DisposeHandler()
|
|
||||||
{
|
|
||||||
if (_downloadhandler != null)
|
|
||||||
{
|
|
||||||
_downloadhandler.Dispose();
|
|
||||||
_downloadhandler = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -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)
|
private BundleInfo ConvertToDownloadInfo(PackageBundle packageBundle)
|
||||||
{
|
{
|
||||||
string remoteMainURL = _remoteServices.GetRemoteMainURL(packageBundle.FileName);
|
string remoteMainURL = _remoteServices.GetRemoteMainURL(packageBundle.FileName);
|
||||||
|
@ -84,15 +94,101 @@ namespace YooAsset
|
||||||
|
|
||||||
ResourceDownloaderOperation IPlayModeServices.CreateResourceDownloaderByAll(int downloadingMaxNumber, int failedTryAgain, int timeout)
|
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)
|
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)
|
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)
|
ResourceUnpackerOperation IPlayModeServices.CreateResourceUnpackerByAll(int upackingMaxNumber, int failedTryAgain, int timeout)
|
||||||
|
|
Loading…
Reference in New Issue