合并2.x功能到1.5
1. 增加获取缓存文件信息的异步操作 2. 支持资源下载器合并 3. 新增资源导入器
This commit is contained in:
@@ -154,10 +154,12 @@ namespace YooAsset
|
||||
|
||||
// 填充BundleDic
|
||||
manifest.BundleDic = new Dictionary<string, PackageBundle>(manifest.BundleList.Count);
|
||||
manifest.BundleDic2 = new Dictionary<string, PackageBundle>(manifest.BundleList.Count);
|
||||
foreach (var packageBundle in manifest.BundleList)
|
||||
{
|
||||
packageBundle.ParseBundle(manifest.PackageName, manifest.OutputNameStyle);
|
||||
manifest.BundleDic.Add(packageBundle.BundleName, packageBundle);
|
||||
manifest.BundleDic2.Add(packageBundle.FileName, packageBundle);
|
||||
}
|
||||
|
||||
// 填充AssetDic
|
||||
@@ -210,7 +212,18 @@ namespace YooAsset
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 批量转换为解压BundleInfo
|
||||
/// 转换为导入BundleInfo
|
||||
/// </summary>
|
||||
public static BundleInfo ConvertToImportInfo(PackageBundle packageBundle, string filePath)
|
||||
{
|
||||
// 注意:我们把本地文件路径指定为远端下载地址
|
||||
string persistentPath = PersistentTools.ConvertToWWWPath(filePath);
|
||||
BundleInfo bundleInfo = new BundleInfo(packageBundle, BundleInfo.ELoadMode.None, persistentPath, persistentPath);
|
||||
return bundleInfo;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 批量转换解压为BundleInfo
|
||||
/// </summary>
|
||||
public static List<BundleInfo> ConvertToUnpackInfos(List<PackageBundle> unpackList)
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -64,6 +64,18 @@ namespace YooAsset
|
||||
[NonSerialized]
|
||||
public Dictionary<string, PackageBundle> BundleDic;
|
||||
|
||||
/// <summary>
|
||||
/// 资源包集合(提供FileName获取PackageBundle)
|
||||
/// </summary>
|
||||
[NonSerialized]
|
||||
public Dictionary<string, PackageBundle> BundleDic2;
|
||||
|
||||
/// <summary>
|
||||
/// 资源包集合(提供CacheGUID获取PackageBundle)
|
||||
/// </summary>
|
||||
[NonSerialized]
|
||||
public Dictionary<string, PackageBundle> BundleDic3;
|
||||
|
||||
/// <summary>
|
||||
/// 资源映射集合(提供AssetPath获取PackageAsset)
|
||||
/// </summary>
|
||||
@@ -82,12 +94,6 @@ namespace YooAsset
|
||||
[NonSerialized]
|
||||
public Dictionary<string, string> AssetPathMapping2;
|
||||
|
||||
/// <summary>
|
||||
/// 该资源清单所有文件的缓存GUID集合
|
||||
/// </summary>
|
||||
[NonSerialized]
|
||||
public HashSet<string> CacheGUIDs = new HashSet<string>();
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 尝试映射为资源路径
|
||||
@@ -192,12 +198,28 @@ namespace YooAsset
|
||||
return BundleDic.TryGetValue(bundleName, out result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 尝试获取包裹的资源包
|
||||
/// </summary>
|
||||
public bool TryGetPackageBundleByFileName(string fileName, out PackageBundle result)
|
||||
{
|
||||
return BundleDic2.TryGetValue(fileName, out result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 尝试获取包裹的资源包
|
||||
/// </summary>
|
||||
public bool TryGetPackageBundleByCacheGUID(string cacheGUID, out PackageBundle result)
|
||||
{
|
||||
return BundleDic3.TryGetValue(cacheGUID, out result);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否包含资源文件
|
||||
/// </summary>
|
||||
public bool IsIncludeBundleFile(string cacheGUID)
|
||||
{
|
||||
return CacheGUIDs.Contains(cacheGUID);
|
||||
return BundleDic3.ContainsKey(cacheGUID);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -74,6 +74,11 @@ namespace YooAsset
|
||||
{
|
||||
return ResourceUnpackerOperation.CreateEmptyUnpacker(upackingMaxNumber, failedTryAgain, timeout);
|
||||
}
|
||||
|
||||
ResourceImporterOperation IPlayModeServices.CreateResourceImporterByFilePaths(string[] filePaths, int importerMaxNumber, int failedTryAgain, int timeout)
|
||||
{
|
||||
return ResourceImporterOperation.CreateEmptyImporter(importerMaxNumber, failedTryAgain, timeout);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region IBundleServices接口
|
||||
|
||||
@@ -284,6 +284,39 @@ namespace YooAsset
|
||||
|
||||
return ManifestTools.ConvertToUnpackInfos(downloadList);
|
||||
}
|
||||
|
||||
ResourceImporterOperation IPlayModeServices.CreateResourceImporterByFilePaths(string[] filePaths, int importerMaxNumber, int failedTryAgain, int timeout)
|
||||
{
|
||||
List<BundleInfo> importerList = GetImporterListByFilePaths(_activeManifest, filePaths);
|
||||
var operation = new ResourceImporterOperation(importerList, importerMaxNumber, failedTryAgain, timeout);
|
||||
return operation;
|
||||
}
|
||||
private List<BundleInfo> GetImporterListByFilePaths(PackageManifest manifest, string[] filePaths)
|
||||
{
|
||||
List<BundleInfo> result = new List<BundleInfo>();
|
||||
foreach (var filePath in filePaths)
|
||||
{
|
||||
string fileName = System.IO.Path.GetFileName(filePath);
|
||||
if (manifest.TryGetPackageBundleByFileName(fileName, out PackageBundle packageBundle))
|
||||
{
|
||||
// 忽略缓存文件
|
||||
if (IsCachedPackageBundle(packageBundle))
|
||||
continue;
|
||||
|
||||
// 忽略APP资源
|
||||
if (IsBuildinPackageBundle(packageBundle))
|
||||
continue;
|
||||
|
||||
var bundleInfo = ManifestTools.ConvertToImportInfo(packageBundle, filePath);
|
||||
result.Add(bundleInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
YooLogger.Warning($"Not found package bundle, importer file path : {filePath}");
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region IBundleServices接口
|
||||
|
||||
@@ -117,6 +117,35 @@ namespace YooAsset
|
||||
|
||||
return ManifestTools.ConvertToUnpackInfos(downloadList);
|
||||
}
|
||||
|
||||
ResourceImporterOperation IPlayModeServices.CreateResourceImporterByFilePaths(string[] filePaths, int importerMaxNumber, int failedTryAgain, int timeout)
|
||||
{
|
||||
List<BundleInfo> importerList = GetImporterListByFilePaths(_activeManifest, filePaths);
|
||||
var operation = new ResourceImporterOperation(importerList, importerMaxNumber, failedTryAgain, timeout);
|
||||
return operation;
|
||||
}
|
||||
private List<BundleInfo> GetImporterListByFilePaths(PackageManifest manifest, string[] filePaths)
|
||||
{
|
||||
List<BundleInfo> result = new List<BundleInfo>();
|
||||
foreach (var filePath in filePaths)
|
||||
{
|
||||
string fileName = System.IO.Path.GetFileName(filePath);
|
||||
if (manifest.TryGetPackageBundleByFileName(fileName, out PackageBundle packageBundle))
|
||||
{
|
||||
// 忽略缓存文件
|
||||
if (IsCachedPackageBundle(packageBundle))
|
||||
continue;
|
||||
|
||||
var bundleInfo = ManifestTools.ConvertToImportInfo(packageBundle, filePath);
|
||||
result.Add(bundleInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
YooLogger.Warning($"Not found package bundle, importer file path : {filePath}");
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region IBundleServices接口
|
||||
|
||||
@@ -199,6 +199,11 @@ namespace YooAsset
|
||||
{
|
||||
return ResourceUnpackerOperation.CreateEmptyUnpacker(upackingMaxNumber, failedTryAgain, timeout);
|
||||
}
|
||||
|
||||
ResourceImporterOperation IPlayModeServices.CreateResourceImporterByFilePaths(string[] filePaths, int importerMaxNumber, int failedTryAgain, int timeout)
|
||||
{
|
||||
return ResourceImporterOperation.CreateEmptyImporter(importerMaxNumber, failedTryAgain, timeout);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region IBundleServices接口
|
||||
|
||||
@@ -299,6 +299,17 @@ namespace YooAsset
|
||||
return operation;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取指定版本的缓存信息
|
||||
/// </summary>
|
||||
public GetAllCacheFileInfosOperation GetAllCacheFileInfosAsync(string packageVersion, int timeout = 60)
|
||||
{
|
||||
DebugCheckInitialize();
|
||||
var operation = new GetAllCacheFileInfosOperation(PackageName);
|
||||
OperationSystem.StartOperation(operation);
|
||||
return operation;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取本地包裹的版本信息
|
||||
/// </summary>
|
||||
@@ -335,7 +346,7 @@ namespace YooAsset
|
||||
{
|
||||
DebugCheckInitialize();
|
||||
var persistent = PersistentTools.GetPersistent(PackageName);
|
||||
return persistent.BuildinRoot;
|
||||
return persistent.BuildinPackageRoot;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -345,7 +356,17 @@ namespace YooAsset
|
||||
{
|
||||
DebugCheckInitialize();
|
||||
var persistent = PersistentTools.GetPersistent(PackageName);
|
||||
return persistent.SandboxRoot;
|
||||
return persistent.SandboxPackageRoot;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取包裹的沙盒文件AB文件的缓存目录
|
||||
/// </summary>
|
||||
public string GetPackageSandboxCacheBundleRootDirectory()
|
||||
{
|
||||
DebugCheckInitialize();
|
||||
var persistent = PersistentTools.GetPersistent(PackageName);
|
||||
return persistent.SandboxCacheBundleFilesRoot;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -1026,6 +1047,21 @@ namespace YooAsset
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 资源导入
|
||||
/// <summary>
|
||||
/// 创建资源导入器
|
||||
/// 注意:资源文件名称必须和资源服务器部署的文件名称一致!
|
||||
/// </summary>
|
||||
/// <param name="filePaths">资源路径列表</param>
|
||||
/// <param name="importerMaxNumber">同时导入的最大文件数</param>
|
||||
/// <param name="failedTryAgain">导入失败的重试次数</param>
|
||||
public ResourceImporterOperation CreateResourceImporter(string[] filePaths, int importerMaxNumber, int failedTryAgain)
|
||||
{
|
||||
DebugCheckInitialize();
|
||||
return _playModeServices.CreateResourceImporterByFilePaths(filePaths, importerMaxNumber, failedTryAgain, int.MaxValue);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 内部方法
|
||||
/// <summary>
|
||||
/// 是否包含资源文件
|
||||
|
||||
Reference in New Issue
Block a user