合并2.x功能到1.5
1. 增加获取缓存文件信息的异步操作 2. 支持资源下载器合并 3. 新增资源导入器
This commit is contained in:
@@ -91,14 +91,7 @@ namespace YooAsset
|
||||
_failedTryAgain = failedTryAgain;
|
||||
_timeout = timeout;
|
||||
|
||||
if (downloadList != null)
|
||||
{
|
||||
TotalDownloadCount = downloadList.Count;
|
||||
foreach (var packageBundle in downloadList)
|
||||
{
|
||||
TotalDownloadBytes += packageBundle.Bundle.FileSize;
|
||||
}
|
||||
}
|
||||
CalculatDownloaderInfo();
|
||||
}
|
||||
internal override void Start()
|
||||
{
|
||||
@@ -206,6 +199,57 @@ namespace YooAsset
|
||||
}
|
||||
}
|
||||
}
|
||||
private void CalculatDownloaderInfo()
|
||||
{
|
||||
if (_downloadList != null)
|
||||
{
|
||||
TotalDownloadBytes = 0;
|
||||
TotalDownloadCount = _downloadList.Count;
|
||||
foreach (var packageBundle in _downloadList)
|
||||
{
|
||||
TotalDownloadBytes += packageBundle.Bundle.FileSize;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
TotalDownloadBytes = 0;
|
||||
TotalDownloadCount = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 合并其它下载器
|
||||
/// </summary>
|
||||
/// <param name="downloader">合并的下载器</param>
|
||||
public void Combine(DownloaderOperation downloader)
|
||||
{
|
||||
if (_steps != ESteps.None)
|
||||
{
|
||||
YooLogger.Error("The downloader is running, can not combine with other downloader !");
|
||||
return;
|
||||
}
|
||||
|
||||
HashSet<string> temper = new HashSet<string>();
|
||||
foreach (var bundleInfo in _downloadList)
|
||||
{
|
||||
if (temper.Contains(bundleInfo.Bundle.CachedDataFilePath) == false)
|
||||
{
|
||||
temper.Add(bundleInfo.Bundle.CachedDataFilePath);
|
||||
}
|
||||
}
|
||||
|
||||
// 合并下载列表
|
||||
foreach (var bundleInfo in downloader._downloadList)
|
||||
{
|
||||
if (temper.Contains(bundleInfo.Bundle.CachedDataFilePath) == false)
|
||||
{
|
||||
_downloadList.Add(bundleInfo);
|
||||
}
|
||||
}
|
||||
|
||||
// 重新统计下载信息
|
||||
CalculatDownloaderInfo();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 开始下载
|
||||
@@ -282,4 +326,21 @@ namespace YooAsset
|
||||
return operation;
|
||||
}
|
||||
}
|
||||
public sealed class ResourceImporterOperation : DownloaderOperation
|
||||
{
|
||||
internal ResourceImporterOperation(List<BundleInfo> downloadList, int downloadingMaxNumber, int failedTryAgain, int timeout)
|
||||
: base(downloadList, downloadingMaxNumber, failedTryAgain, timeout)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建空的导入器
|
||||
/// </summary>
|
||||
internal static ResourceImporterOperation CreateEmptyImporter(int upackingMaxNumber, int failedTryAgain, int timeout)
|
||||
{
|
||||
List<BundleInfo> downloadList = new List<BundleInfo>();
|
||||
var operation = new ResourceImporterOperation(downloadList, upackingMaxNumber, failedTryAgain, int.MaxValue);
|
||||
return operation;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,11 @@ namespace YooAsset
|
||||
public abstract class InitializationOperation : AsyncOperationBase
|
||||
{
|
||||
public string PackageVersion { protected set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 本地记录的资源包裹的版本
|
||||
/// </summary>
|
||||
public string RecordVersion { protected set; get; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -242,6 +247,7 @@ namespace YooAsset
|
||||
|
||||
if (_queryCachePackageVersionOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
RecordVersion = _queryCachePackageVersionOp.PackageVersion;
|
||||
_steps = ESteps.TryLoadCacheManifest;
|
||||
}
|
||||
else
|
||||
|
||||
+5
-2
@@ -189,6 +189,8 @@ namespace YooAsset
|
||||
_packageBundleCount = _buffer.ReadInt32();
|
||||
Manifest.BundleList = new List<PackageBundle>(_packageBundleCount);
|
||||
Manifest.BundleDic = new Dictionary<string, PackageBundle>(_packageBundleCount);
|
||||
Manifest.BundleDic2 = new Dictionary<string, PackageBundle>(_packageBundleCount);
|
||||
Manifest.BundleDic3 = new Dictionary<string, PackageBundle>(_packageBundleCount);
|
||||
_progressTotalValue = _packageBundleCount;
|
||||
_steps = ESteps.DeserializeBundleList;
|
||||
}
|
||||
@@ -210,10 +212,11 @@ namespace YooAsset
|
||||
|
||||
packageBundle.ParseBundle(Manifest.PackageName, Manifest.OutputNameStyle);
|
||||
Manifest.BundleDic.Add(packageBundle.BundleName, packageBundle);
|
||||
Manifest.BundleDic2.Add(packageBundle.FileName, packageBundle);
|
||||
|
||||
// 注意:原始文件可能存在相同的CacheGUID
|
||||
if (Manifest.CacheGUIDs.Contains(packageBundle.CacheGUID) == false)
|
||||
Manifest.CacheGUIDs.Add(packageBundle.CacheGUID);
|
||||
if (Manifest.BundleDic3.ContainsKey(packageBundle.CacheGUID) == false)
|
||||
Manifest.BundleDic3.Add(packageBundle.CacheGUID, packageBundle);
|
||||
|
||||
_packageBundleCount--;
|
||||
Progress = 1f - _packageBundleCount / _progressTotalValue;
|
||||
|
||||
Reference in New Issue
Block a user