mirror of
https://github.com/tuyoogame/YooAsset.git
synced 2026-05-25 18:20:15 +00:00
refactor : 重构代码
This commit is contained in:
@@ -6,22 +6,22 @@ namespace YooAsset
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 下载是否已经完成
|
/// 下载是否已经完成
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IsDone;
|
public bool IsDone { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 下载进度(0-1f)
|
/// 下载进度(0-1f)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public float Progress;
|
public float Progress { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 下载文件的总大小
|
/// 下载文件的总大小
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public long TotalBytes;
|
public long TotalBytes { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 已经下载的文件大小
|
/// 已经下载的文件大小
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public long DownloadedBytes;
|
public long DownloadedBytes { get; set; }
|
||||||
|
|
||||||
public static DownloadStatus CreateDefaultStatus()
|
public static DownloadStatus CreateDefaultStatus()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -6,12 +6,12 @@ namespace YooAsset
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 释放所有资源句柄,防止卸载过程中触发完成回调!
|
/// 释放所有资源句柄,防止卸载过程中触发完成回调!
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool ReleaseAllHandles { private set; get; }
|
public bool ReleaseAllHandles { set; get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 卸载过程中锁定加载操作,防止新的任务请求!
|
/// 卸载过程中锁定加载操作,防止新的任务请求!
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool LockLoadOperation { private set; get; }
|
public bool LockLoadOperation { set; get; }
|
||||||
|
|
||||||
public UnloadAllAssetsOptions(bool releaseAllHandles, bool lockLoadOperation)
|
public UnloadAllAssetsOptions(bool releaseAllHandles, bool lockLoadOperation)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ namespace YooAsset
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 循环迭代次数
|
/// 循环迭代次数
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int LoopCount { private set; get; }
|
public int LoopCount { set; get; }
|
||||||
|
|
||||||
public UnloadUnusedAssetsOptions(int loopCount)
|
public UnloadUnusedAssetsOptions(int loopCount)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ namespace YooAsset
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 当前激活的清单
|
/// 当前激活的清单
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public PackageManifest ActiveManifest { set; get; }
|
public PackageManifest ActiveManifest { private set; get; }
|
||||||
|
|
||||||
|
|
||||||
public FileSystemHost(string packageName)
|
public FileSystemHost(string packageName)
|
||||||
@@ -65,6 +65,44 @@ namespace YooAsset
|
|||||||
FileSystems.Clear();
|
FileSystems.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 设置当前激活的资源清单
|
||||||
|
/// </summary>
|
||||||
|
public void SetActiveManifest(PackageManifest manifest)
|
||||||
|
{
|
||||||
|
ActiveManifest = manifest;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取主文件系统
|
||||||
|
/// 说明:文件系统列表里,最后一个属于主文件系统
|
||||||
|
/// </summary>
|
||||||
|
public IFileSystem GetMainFileSystem()
|
||||||
|
{
|
||||||
|
int count = FileSystems.Count;
|
||||||
|
if (count == 0)
|
||||||
|
return null;
|
||||||
|
return FileSystems[count - 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 获取资源包所属文件系统
|
||||||
|
/// </summary>
|
||||||
|
private IFileSystem GetBelongFileSystem(PackageBundle packageBundle)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < FileSystems.Count; i++)
|
||||||
|
{
|
||||||
|
IFileSystem fileSystem = FileSystems[i];
|
||||||
|
if (fileSystem.Belong(packageBundle))
|
||||||
|
{
|
||||||
|
return fileSystem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
YooLogger.Error($"Can not found belong file system : {packageBundle.BundleName}");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
#region 资源包相关
|
#region 资源包相关
|
||||||
private BundleInfo CreateBundleInfo(PackageBundle packageBundle)
|
private BundleInfo CreateBundleInfo(PackageBundle packageBundle)
|
||||||
{
|
{
|
||||||
@@ -80,10 +118,6 @@ namespace YooAsset
|
|||||||
|
|
||||||
throw new YooFileSystemException($"Can not found belong file system : {packageBundle.BundleName}");
|
throw new YooFileSystemException($"Can not found belong file system : {packageBundle.BundleName}");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 获取主资源包信息
|
|
||||||
/// </summary>
|
|
||||||
public BundleInfo GetMainBundleInfo(AssetInfo assetInfo)
|
public BundleInfo GetMainBundleInfo(AssetInfo assetInfo)
|
||||||
{
|
{
|
||||||
if (assetInfo == null || assetInfo.IsInvalid)
|
if (assetInfo == null || assetInfo.IsInvalid)
|
||||||
@@ -93,20 +127,12 @@ namespace YooAsset
|
|||||||
var packageBundle = ActiveManifest.GetMainPackageBundle(assetInfo.Asset);
|
var packageBundle = ActiveManifest.GetMainPackageBundle(assetInfo.Asset);
|
||||||
return CreateBundleInfo(packageBundle);
|
return CreateBundleInfo(packageBundle);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 获取主资源包名称
|
|
||||||
/// </summary>
|
|
||||||
public string GetMainBundleName(int bundleID)
|
public string GetMainBundleName(int bundleID)
|
||||||
{
|
{
|
||||||
// 注意:如果清单里未找到资源包会抛出异常!
|
// 注意:如果清单里未找到资源包会抛出异常!
|
||||||
var packageBundle = ActiveManifest.GetMainPackageBundle(bundleID);
|
var packageBundle = ActiveManifest.GetMainPackageBundle(bundleID);
|
||||||
return packageBundle.BundleName;
|
return packageBundle.BundleName;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 获取依赖的资源包信息集合
|
|
||||||
/// </summary>
|
|
||||||
public List<BundleInfo> GetDependBundleInfos(AssetInfo assetInfo)
|
public List<BundleInfo> GetDependBundleInfos(AssetInfo assetInfo)
|
||||||
{
|
{
|
||||||
if (assetInfo == null || assetInfo.IsInvalid)
|
if (assetInfo == null || assetInfo.IsInvalid)
|
||||||
@@ -135,47 +161,88 @@ namespace YooAsset
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region 下载器相关
|
#region 下载器相关
|
||||||
|
public bool IsNeedDownloadFromRemoteInternal(AssetInfo assetInfo)
|
||||||
|
{
|
||||||
|
if (assetInfo.IsInvalid)
|
||||||
|
{
|
||||||
|
YooLogger.Warning(assetInfo.Error);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
BundleInfo bundleInfo = GetMainBundleInfo(assetInfo);
|
||||||
|
if (bundleInfo.IsNeedDownloadFromRemote())
|
||||||
|
return true;
|
||||||
|
|
||||||
|
List<BundleInfo> depends = GetDependBundleInfos(assetInfo);
|
||||||
|
foreach (var depend in depends)
|
||||||
|
{
|
||||||
|
if (depend.IsNeedDownloadFromRemote())
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public ResourceDownloaderOperation CreateResourceDownloader(ResourceDownloaderOptions options)
|
public ResourceDownloaderOperation CreateResourceDownloader(ResourceDownloaderOptions options)
|
||||||
|
{
|
||||||
|
return CreateResourceDownloader(ActiveManifest, options);
|
||||||
|
}
|
||||||
|
public ResourceDownloaderOperation CreateResourceDownloader(PackageManifest manifest, ResourceDownloaderOptions options)
|
||||||
{
|
{
|
||||||
List<BundleInfo> downloadList;
|
List<BundleInfo> downloadList;
|
||||||
if (options.Tags == null)
|
if (options.Tags == null)
|
||||||
downloadList = GetDownloadListByAll(ActiveManifest);
|
downloadList = GetDownloadListByAll(manifest);
|
||||||
else
|
else
|
||||||
downloadList = GetDownloadListByTags(ActiveManifest, options.Tags);
|
downloadList = GetDownloadListByTags(manifest, options.Tags);
|
||||||
|
|
||||||
var operation = new ResourceDownloaderOperation(PackageName, downloadList, options.MaximumConcurrency, options.FailedTryAgain);
|
var operation = new ResourceDownloaderOperation(PackageName, downloadList, options.MaximumConcurrency, options.FailedTryAgain);
|
||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResourceDownloaderOperation CreateResourceDownloader(BundleDownloaderOptions options)
|
public ResourceDownloaderOperation CreateResourceDownloader(BundleDownloaderOptions options)
|
||||||
|
{
|
||||||
|
return CreateResourceDownloader(ActiveManifest, options);
|
||||||
|
}
|
||||||
|
public ResourceDownloaderOperation CreateResourceDownloader(PackageManifest manifest, BundleDownloaderOptions options)
|
||||||
{
|
{
|
||||||
List<BundleInfo> downloadList;
|
List<BundleInfo> downloadList;
|
||||||
if (options.AssetInfos == null)
|
if (options.AssetInfos == null)
|
||||||
downloadList = GetDownloadListByAll(ActiveManifest);
|
downloadList = GetDownloadListByAll(manifest);
|
||||||
else
|
else
|
||||||
downloadList = GetDownloadListByAssetInfos(ActiveManifest, options.AssetInfos, options.DownloadBundleDependencies);
|
downloadList = GetDownloadListByAssetInfos(manifest, options.AssetInfos, options.DownloadBundleDependencies);
|
||||||
|
|
||||||
var operation = new ResourceDownloaderOperation(PackageName, downloadList, options.MaximumConcurrency, options.FailedTryAgain);
|
var operation = new ResourceDownloaderOperation(PackageName, downloadList, options.MaximumConcurrency, options.FailedTryAgain);
|
||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResourceUnpackerOperation CreateResourceUnpacker(ResourceUnpackerOptions options)
|
public ResourceUnpackerOperation CreateResourceUnpacker(ResourceUnpackerOptions options)
|
||||||
|
{
|
||||||
|
return CreateResourceUnpacker(ActiveManifest, options);
|
||||||
|
}
|
||||||
|
public ResourceUnpackerOperation CreateResourceUnpacker(PackageManifest manifest, ResourceUnpackerOptions options)
|
||||||
{
|
{
|
||||||
List<BundleInfo> unpcakList;
|
List<BundleInfo> unpcakList;
|
||||||
if (options.Tags == null)
|
if (options.Tags == null)
|
||||||
unpcakList = GetUnpackListByAll(ActiveManifest);
|
unpcakList = GetUnpackListByAll(manifest);
|
||||||
else
|
else
|
||||||
unpcakList = GetUnpackListByTags(ActiveManifest, options.Tags);
|
unpcakList = GetUnpackListByTags(manifest, options.Tags);
|
||||||
|
|
||||||
var operation = new ResourceUnpackerOperation(PackageName, unpcakList, options.MaximumConcurrency, options.FailedTryAgain);
|
var operation = new ResourceUnpackerOperation(PackageName, unpcakList, options.MaximumConcurrency, options.FailedTryAgain);
|
||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ResourceImporterOperation CreateResourceImporter(BundleImporterOptions options)
|
public ResourceImporterOperation CreateResourceImporter(BundleImporterOptions options)
|
||||||
{
|
{
|
||||||
List<BundleInfo> importerList = GetImporterListByBundleInfos(ActiveManifest, options.BundleInfos);
|
return CreateResourceImporter(ActiveManifest, options);
|
||||||
|
}
|
||||||
|
public ResourceImporterOperation CreateResourceImporter(PackageManifest manifest, BundleImporterOptions options)
|
||||||
|
{
|
||||||
|
List<BundleInfo> importerList = GetImporterListByBundleInfos(manifest, options.BundleInfos);
|
||||||
var operation = new ResourceImporterOperation(PackageName, importerList, options.MaximumConcurrency, options.FailedTryAgain);
|
var operation = new ResourceImporterOperation(PackageName, importerList, options.MaximumConcurrency, options.FailedTryAgain);
|
||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal List<BundleInfo> GetDownloadListByAll(PackageManifest manifest)
|
private List<BundleInfo> GetDownloadListByAll(PackageManifest manifest)
|
||||||
{
|
{
|
||||||
if (manifest == null)
|
if (manifest == null)
|
||||||
return new List<BundleInfo>();
|
return new List<BundleInfo>();
|
||||||
@@ -195,7 +262,7 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
internal List<BundleInfo> GetDownloadListByTags(PackageManifest manifest, string[] tags)
|
private List<BundleInfo> GetDownloadListByTags(PackageManifest manifest, string[] tags)
|
||||||
{
|
{
|
||||||
if (manifest == null)
|
if (manifest == null)
|
||||||
return new List<BundleInfo>();
|
return new List<BundleInfo>();
|
||||||
@@ -228,7 +295,7 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
internal List<BundleInfo> GetDownloadListByAssetInfos(PackageManifest manifest, AssetInfo[] assetInfos, bool recursiveDownload)
|
private List<BundleInfo> GetDownloadListByAssetInfos(PackageManifest manifest, AssetInfo[] assetInfos, bool recursiveDownload)
|
||||||
{
|
{
|
||||||
if (manifest == null)
|
if (manifest == null)
|
||||||
return new List<BundleInfo>();
|
return new List<BundleInfo>();
|
||||||
@@ -303,7 +370,7 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
internal List<BundleInfo> GetUnpackListByAll(PackageManifest manifest)
|
private List<BundleInfo> GetUnpackListByAll(PackageManifest manifest)
|
||||||
{
|
{
|
||||||
if (manifest == null)
|
if (manifest == null)
|
||||||
return new List<BundleInfo>();
|
return new List<BundleInfo>();
|
||||||
@@ -323,7 +390,7 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
internal List<BundleInfo> GetUnpackListByTags(PackageManifest manifest, string[] tags)
|
private List<BundleInfo> GetUnpackListByTags(PackageManifest manifest, string[] tags)
|
||||||
{
|
{
|
||||||
if (manifest == null)
|
if (manifest == null)
|
||||||
return new List<BundleInfo>();
|
return new List<BundleInfo>();
|
||||||
@@ -346,7 +413,7 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
internal List<BundleInfo> GetImporterListByBundleInfos(PackageManifest manifest, ImportBundleInfo[] fileInfos)
|
private List<BundleInfo> GetImporterListByBundleInfos(PackageManifest manifest, ImportBundleInfo[] fileInfos)
|
||||||
{
|
{
|
||||||
if (manifest == null)
|
if (manifest == null)
|
||||||
return new List<BundleInfo>();
|
return new List<BundleInfo>();
|
||||||
@@ -401,35 +468,5 @@ namespace YooAsset
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 获取主文件系统
|
|
||||||
/// 说明:文件系统列表里,最后一个属于主文件系统
|
|
||||||
/// </summary>
|
|
||||||
public IFileSystem GetMainFileSystem()
|
|
||||||
{
|
|
||||||
int count = FileSystems.Count;
|
|
||||||
if (count == 0)
|
|
||||||
return null;
|
|
||||||
return FileSystems[count - 1];
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 获取资源包所属文件系统
|
|
||||||
/// </summary>
|
|
||||||
public IFileSystem GetBelongFileSystem(PackageBundle packageBundle)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < FileSystems.Count; i++)
|
|
||||||
{
|
|
||||||
IFileSystem fileSystem = FileSystems[i];
|
|
||||||
if (fileSystem.Belong(packageBundle))
|
|
||||||
{
|
|
||||||
return fileSystem;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
YooLogger.Error($"Can not found belong file system : {packageBundle.BundleName}");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6,12 +6,12 @@ namespace YooAsset
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 清理模式
|
/// 清理模式
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string ClearMode { private set; get; }
|
public string ClearMode { set; get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 附加参数
|
/// 附加参数
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public object ClearParam { private set; get; }
|
public object ClearParam { set; get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 资源清单
|
/// 资源清单
|
||||||
|
|||||||
@@ -2,101 +2,153 @@
|
|||||||
namespace YooAsset
|
namespace YooAsset
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 下载器结束
|
/// 下载完成事件参数
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public struct DownloaderFinishData
|
public struct DownloadFinishedEventArgs
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 所属包裹名称
|
/// 所属包裹名称
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string PackageName;
|
public string PackageName { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 是否成功
|
/// 是否成功
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool Succeed;
|
public bool IsSuccess { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 如果下载失败,获取的错误信息。
|
||||||
|
/// </summary>
|
||||||
|
public string ErrorInfo { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 创建表示成功下载的事件参数
|
||||||
|
/// </summary>
|
||||||
|
internal static DownloadFinishedEventArgs CreateSuccess(string packageName)
|
||||||
|
{
|
||||||
|
var args = new DownloadFinishedEventArgs();
|
||||||
|
args.PackageName = packageName;
|
||||||
|
args.IsSuccess = true;
|
||||||
|
args.ErrorInfo = null;
|
||||||
|
return args;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 创建表示失败下载的事件参数
|
||||||
|
/// </summary>
|
||||||
|
internal static DownloadFinishedEventArgs CreateFailure(string packageName, string errorInfo)
|
||||||
|
{
|
||||||
|
var args = new DownloadFinishedEventArgs();
|
||||||
|
args.PackageName = packageName;
|
||||||
|
args.IsSuccess = false;
|
||||||
|
args.ErrorInfo = errorInfo;
|
||||||
|
return args;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 下载器相关的更新数据
|
/// 下载完成事件委托
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public struct DownloadUpdateData
|
public delegate void DownloadFinishedEventHandler(DownloadFinishedEventArgs args);
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 下载进度更新事件参数
|
||||||
|
/// </summary>
|
||||||
|
public struct DownloadProgressChangedEventArgs
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 所属包裹名称
|
/// 所属包裹名称
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string PackageName;
|
public string PackageName { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 下载进度 (0-1f)
|
/// 下载进度 (0-1f)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public float Progress;
|
public float Progress { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 下载文件总数
|
/// 下载文件总数
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int TotalDownloadCount;
|
public int TotalDownloadCount { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 当前完成的下载文件数量
|
|
||||||
/// </summary>
|
|
||||||
public int CurrentDownloadCount;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 下载数据总大小(单位:字节)
|
/// 下载数据总大小(单位:字节)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public long TotalDownloadBytes;
|
public long TotalDownloadBytes { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 当前完成的下载文件数量
|
||||||
|
/// </summary>
|
||||||
|
public int CurrentDownloadCount { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 当前完成的下载数据大小(单位:字节)
|
/// 当前完成的下载数据大小(单位:字节)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public long CurrentDownloadBytes;
|
public long CurrentDownloadBytes { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 下载器相关的错误数据
|
/// 下载进度更新事件委托
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public struct DownloadErrorData
|
public delegate void DownloadProgressChangedEventHandler(DownloadProgressChangedEventArgs args);
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 下载错误事件参数
|
||||||
|
/// </summary>
|
||||||
|
public struct DownloadErrorEventArgs
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 所属包裹名称
|
/// 所属包裹名称
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string PackageName;
|
public string PackageName { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 下载失败的文件名称
|
/// 下载失败的文件名称
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string FileName;
|
public string FileName { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 错误信息
|
/// 错误信息
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string ErrorInfo;
|
public string ErrorInfo { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 下载器相关的文件数据
|
/// 下载错误事件委托
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public struct DownloadFileData
|
public delegate void DownloadErrorEventHandler(DownloadErrorEventArgs args);
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 开始下载单个文件事件参数
|
||||||
|
/// </summary>
|
||||||
|
public struct DownloadFileStartedEventArgs
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 所属包裹名称
|
/// 所属包裹名称
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string PackageName;
|
public string PackageName { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 资源包名称
|
/// 资源包名称
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string BundleName;
|
public string BundleName { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 文件名称
|
/// 文件名称
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string FileName;
|
public string FileName { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 文件大小
|
/// 文件大小
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public long FileSize;
|
public long FileSize { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 开始下载单个文件事件委托
|
||||||
|
/// </summary>
|
||||||
|
public delegate void DownloadFileStartedEventHandler(DownloadFileStartedEventArgs args);
|
||||||
}
|
}
|
||||||
@@ -15,29 +15,6 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
|
|
||||||
private const int MAX_LOADER_COUNT = 64;
|
private const int MAX_LOADER_COUNT = 64;
|
||||||
|
|
||||||
#region 委托定义
|
|
||||||
/// <summary>
|
|
||||||
/// 下载器结束
|
|
||||||
/// </summary>
|
|
||||||
public delegate void DownloaderFinish(DownloaderFinishData data);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 下载进度更新
|
|
||||||
/// </summary>
|
|
||||||
public delegate void DownloadUpdate(DownloadUpdateData data);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 下载发生错误
|
|
||||||
/// </summary>
|
|
||||||
public delegate void DownloadError(DownloadErrorData data);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 开始下载某个文件
|
|
||||||
/// </summary>
|
|
||||||
public delegate void DownloadFileBegin(DownloadFileData data);
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
private readonly string _packageName;
|
private readonly string _packageName;
|
||||||
private readonly int _maximumConcurrency;
|
private readonly int _maximumConcurrency;
|
||||||
private readonly int _failedTryAgain;
|
private readonly int _failedTryAgain;
|
||||||
@@ -82,24 +59,24 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 当下载器结束(无论成功或失败)
|
/// 下载完成事件委托(无论成功或失败)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public DownloaderFinish DownloadFinishCallback { set; get; }
|
public DownloadFinishedEventHandler DownloadFinishedHandler { set; get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 当下载进度发生变化
|
/// 下载进度更新事件委托
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public DownloadUpdate DownloadUpdateCallback { set; get; }
|
public DownloadProgressChangedEventHandler DownloadProgressChangedHandler { set; get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 当下载器发生错误
|
/// 下载错误事件委托
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public DownloadError DownloadErrorCallback { set; get; }
|
public DownloadErrorEventHandler DownloadErrorHandler { set; get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 当开始下载某个文件
|
/// 开始下载单个文件事件委托
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public DownloadFileBegin DownloadFileBeginCallback { set; get; }
|
public DownloadFileStartedEventHandler DownloadFileStartedHandler { set; get; }
|
||||||
|
|
||||||
|
|
||||||
internal DownloaderOperation(string packageName, List<BundleInfo> downloadList, int maximumConcurrency, int failedTryAgain)
|
internal DownloaderOperation(string packageName, List<BundleInfo> downloadList, int maximumConcurrency, int failedTryAgain)
|
||||||
@@ -130,12 +107,10 @@ namespace YooAsset
|
|||||||
Status = EOperationStatus.Failed;
|
Status = EOperationStatus.Failed;
|
||||||
Error = "Download bundle list is null.";
|
Error = "Download bundle list is null.";
|
||||||
|
|
||||||
if (DownloadFinishCallback != null)
|
if (DownloadFinishedHandler != null)
|
||||||
{
|
{
|
||||||
var data = new DownloaderFinishData();
|
var args = DownloadFinishedEventArgs.CreateFailure(_packageName, Error);
|
||||||
data.PackageName = _packageName;
|
DownloadFinishedHandler.Invoke(args);
|
||||||
data.Succeed = false;
|
|
||||||
DownloadFinishCallback.Invoke(data);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (_bundleInfoList.Count == 0)
|
else if (_bundleInfoList.Count == 0)
|
||||||
@@ -144,12 +119,10 @@ namespace YooAsset
|
|||||||
Status = EOperationStatus.Succeed;
|
Status = EOperationStatus.Succeed;
|
||||||
Progress = 1f;
|
Progress = 1f;
|
||||||
|
|
||||||
if (DownloadFinishCallback != null)
|
if (DownloadFinishedHandler != null)
|
||||||
{
|
{
|
||||||
var data = new DownloaderFinishData();
|
var args = DownloadFinishedEventArgs.CreateSuccess(_packageName);
|
||||||
data.PackageName = _packageName;
|
DownloadFinishedHandler.Invoke(args);
|
||||||
data.Succeed = true;
|
|
||||||
DownloadFinishCallback.Invoke(data);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -200,16 +173,16 @@ namespace YooAsset
|
|||||||
else
|
else
|
||||||
Progress = (float)_lastDownloadBytes / TotalDownloadBytes;
|
Progress = (float)_lastDownloadBytes / TotalDownloadBytes;
|
||||||
|
|
||||||
if (DownloadUpdateCallback != null)
|
if (DownloadProgressChangedHandler != null)
|
||||||
{
|
{
|
||||||
var data = new DownloadUpdateData();
|
var data = new DownloadProgressChangedEventArgs();
|
||||||
data.PackageName = _packageName;
|
data.PackageName = _packageName;
|
||||||
data.Progress = Progress;
|
data.Progress = Progress;
|
||||||
data.TotalDownloadCount = TotalDownloadCount;
|
data.TotalDownloadCount = TotalDownloadCount;
|
||||||
data.CurrentDownloadCount = _lastDownloadCount;
|
|
||||||
data.TotalDownloadBytes = TotalDownloadBytes;
|
data.TotalDownloadBytes = TotalDownloadBytes;
|
||||||
|
data.CurrentDownloadCount = _lastDownloadCount;
|
||||||
data.CurrentDownloadBytes = _lastDownloadBytes;
|
data.CurrentDownloadBytes = _lastDownloadBytes;
|
||||||
DownloadUpdateCallback.Invoke(data);
|
DownloadProgressChangedHandler.Invoke(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -231,14 +204,14 @@ namespace YooAsset
|
|||||||
_downloaders.Add(downloader);
|
_downloaders.Add(downloader);
|
||||||
_bundleInfoList.RemoveAt(index);
|
_bundleInfoList.RemoveAt(index);
|
||||||
|
|
||||||
if (DownloadFileBeginCallback != null)
|
if (DownloadFileStartedHandler != null)
|
||||||
{
|
{
|
||||||
var data = new DownloadFileData();
|
var data = new DownloadFileStartedEventArgs();
|
||||||
data.PackageName = _packageName;
|
data.PackageName = _packageName;
|
||||||
data.BundleName = bundleInfo.Bundle.BundleName;
|
data.BundleName = bundleInfo.Bundle.BundleName;
|
||||||
data.FileName = bundleInfo.Bundle.FileName;
|
data.FileName = bundleInfo.Bundle.FileName;
|
||||||
data.FileSize = bundleInfo.Bundle.FileSize;
|
data.FileSize = bundleInfo.Bundle.FileSize;
|
||||||
DownloadFileBeginCallback.Invoke(data);
|
DownloadFileStartedHandler.Invoke(data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -260,21 +233,19 @@ namespace YooAsset
|
|||||||
Status = EOperationStatus.Failed;
|
Status = EOperationStatus.Failed;
|
||||||
Error = $"Failed to download file : {bundleName}";
|
Error = $"Failed to download file : {bundleName}";
|
||||||
|
|
||||||
if (DownloadErrorCallback != null)
|
if (DownloadErrorHandler != null)
|
||||||
{
|
{
|
||||||
var data = new DownloadErrorData();
|
var data = new DownloadErrorEventArgs();
|
||||||
data.PackageName = _packageName;
|
data.PackageName = _packageName;
|
||||||
data.FileName = bundleName;
|
data.FileName = bundleName;
|
||||||
data.ErrorInfo = failedDownloader.Error;
|
data.ErrorInfo = failedDownloader.Error;
|
||||||
DownloadErrorCallback.Invoke(data);
|
DownloadErrorHandler.Invoke(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DownloadFinishCallback != null)
|
if (DownloadFinishedHandler != null)
|
||||||
{
|
{
|
||||||
var data = new DownloaderFinishData();
|
var args = DownloadFinishedEventArgs.CreateFailure(_packageName, failedDownloader.Error);
|
||||||
data.PackageName = _packageName;
|
DownloadFinishedHandler.Invoke(args);
|
||||||
data.Succeed = false;
|
|
||||||
DownloadFinishCallback.Invoke(data);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -283,12 +254,10 @@ namespace YooAsset
|
|||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
Status = EOperationStatus.Succeed;
|
Status = EOperationStatus.Succeed;
|
||||||
|
|
||||||
if (DownloadFinishCallback != null)
|
if (DownloadFinishedHandler != null)
|
||||||
{
|
{
|
||||||
var data = new DownloaderFinishData();
|
var args = DownloadFinishedEventArgs.CreateSuccess(_packageName);
|
||||||
data.PackageName = _packageName;
|
DownloadFinishedHandler.Invoke(args);
|
||||||
data.Succeed = true;
|
|
||||||
DownloadFinishCallback.Invoke(data);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -409,10 +378,10 @@ namespace YooAsset
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 创建空的下载器
|
/// 创建空的下载器
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal static ResourceDownloaderOperation CreateEmptyDownloader(string packageName, int maximumConcurrency, int failedTryAgain)
|
internal static ResourceDownloaderOperation CreateEmptyDownloader(string packageName)
|
||||||
{
|
{
|
||||||
List<BundleInfo> downloadList = new List<BundleInfo>();
|
List<BundleInfo> downloadList = new List<BundleInfo>();
|
||||||
var operation = new ResourceDownloaderOperation(packageName, downloadList, maximumConcurrency, failedTryAgain);
|
var operation = new ResourceDownloaderOperation(packageName, downloadList, 1, 1);
|
||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -426,10 +395,10 @@ namespace YooAsset
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 创建空的解压器
|
/// 创建空的解压器
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal static ResourceUnpackerOperation CreateEmptyUnpacker(string packageName, int upackingMaxNumber, int failedTryAgain)
|
internal static ResourceUnpackerOperation CreateEmptyUnpacker(string packageName)
|
||||||
{
|
{
|
||||||
List<BundleInfo> downloadList = new List<BundleInfo>();
|
List<BundleInfo> downloadList = new List<BundleInfo>();
|
||||||
var operation = new ResourceUnpackerOperation(packageName, downloadList, upackingMaxNumber, failedTryAgain);
|
var operation = new ResourceUnpackerOperation(packageName, downloadList, 1, 1);
|
||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -443,10 +412,10 @@ namespace YooAsset
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 创建空的导入器
|
/// 创建空的导入器
|
||||||
/// </summary>
|
/// </summary>
|
||||||
internal static ResourceImporterOperation CreateEmptyImporter(string packageName, int upackingMaxNumber, int failedTryAgain)
|
internal static ResourceImporterOperation CreateEmptyImporter(string packageName)
|
||||||
{
|
{
|
||||||
List<BundleInfo> downloadList = new List<BundleInfo>();
|
List<BundleInfo> downloadList = new List<BundleInfo>();
|
||||||
var operation = new ResourceImporterOperation(packageName, downloadList, upackingMaxNumber, failedTryAgain);
|
var operation = new ResourceImporterOperation(packageName, downloadList, 1, 1);
|
||||||
return operation;
|
return operation;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,23 +9,23 @@ namespace YooAsset
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 最大并发数量
|
/// 最大并发数量
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int MaximumConcurrency { private set; get; }
|
public int MaximumConcurrency { set; get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 失败后的重试次数
|
/// 失败后的重试次数
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int FailedTryAgain { private set; get; }
|
public int FailedTryAgain { set; get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 下载资源对象所属资源包内所有资源对象依赖的资源包
|
/// 下载资源对象所属资源包内所有资源对象依赖的资源包
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool DownloadBundleDependencies { private set; get; }
|
public bool DownloadBundleDependencies { set; get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 资源信息列表
|
/// 资源信息列表
|
||||||
/// 说明:如果列表为NULL,则下载所有资产
|
/// 说明:如果列表为NULL,则下载所有资产
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public AssetInfo[] AssetInfos { private set; get; }
|
public AssetInfo[] AssetInfos { set; get; }
|
||||||
|
|
||||||
public BundleDownloaderOptions(AssetInfo assetInfo, bool downloadDependencies, int maximumConcurrency, int failedTryAgain)
|
public BundleDownloaderOptions(AssetInfo assetInfo, bool downloadDependencies, int maximumConcurrency, int failedTryAgain)
|
||||||
{
|
{
|
||||||
@@ -51,18 +51,18 @@ namespace YooAsset
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 最大并发数量
|
/// 最大并发数量
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int MaximumConcurrency { private set; get; }
|
public int MaximumConcurrency { set; get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 失败后的重试次数
|
/// 失败后的重试次数
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int FailedTryAgain { private set; get; }
|
public int FailedTryAgain { set; get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 资源标签列表
|
/// 资源标签列表
|
||||||
/// 说明:如果列表为NULL,则下载所有资产
|
/// 说明:如果列表为NULL,则下载所有资产
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string[] Tags { private set; get; }
|
public string[] Tags { set; get; }
|
||||||
|
|
||||||
public ResourceDownloaderOptions(int maximumConcurrency, int failedTryAgain)
|
public ResourceDownloaderOptions(int maximumConcurrency, int failedTryAgain)
|
||||||
{
|
{
|
||||||
@@ -92,18 +92,18 @@ namespace YooAsset
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 最大并发数量
|
/// 最大并发数量
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int MaximumConcurrency { private set; get; }
|
public int MaximumConcurrency { set; get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 失败后的重试次数
|
/// 失败后的重试次数
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int FailedTryAgain { private set; get; }
|
public int FailedTryAgain { set; get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 资源标签列表
|
/// 资源标签列表
|
||||||
/// 说明:如果列表为NULL,则解压所有资产
|
/// 说明:如果列表为NULL,则解压所有资产
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string[] Tags { private set; get; }
|
public string[] Tags { set; get; }
|
||||||
|
|
||||||
public ResourceUnpackerOptions(int maximumConcurrency, int failedTryAgain)
|
public ResourceUnpackerOptions(int maximumConcurrency, int failedTryAgain)
|
||||||
{
|
{
|
||||||
@@ -133,17 +133,17 @@ namespace YooAsset
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 最大并发数量
|
/// 最大并发数量
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int MaximumConcurrency { private set; get; }
|
public int MaximumConcurrency { set; get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 失败后的重试次数
|
/// 失败后的重试次数
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int FailedTryAgain { private set; get; }
|
public int FailedTryAgain { set; get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 资源包信息列表
|
/// 资源包信息列表
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ImportBundleInfo[] BundleInfos { private set; get; }
|
public ImportBundleInfo[] BundleInfos { set; get; }
|
||||||
|
|
||||||
public BundleImporterOptions(ImportBundleInfo[] bundleInfos, int maximumConcurrency, int failedTryAgain)
|
public BundleImporterOptions(ImportBundleInfo[] bundleInfos, int maximumConcurrency, int failedTryAgain)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -76,7 +76,7 @@ namespace YooAsset
|
|||||||
if (_loadPackageManifestOp.Status == EOperationStatus.Succeed)
|
if (_loadPackageManifestOp.Status == EOperationStatus.Succeed)
|
||||||
{
|
{
|
||||||
_steps = ESteps.Done;
|
_steps = ESteps.Done;
|
||||||
_host.ActiveManifest = _loadPackageManifestOp.Manifest;
|
_host.SetActiveManifest(_loadPackageManifestOp.Manifest);
|
||||||
Status = EOperationStatus.Succeed;
|
Status = EOperationStatus.Succeed;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -6,12 +6,12 @@ namespace YooAsset
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 包裹版本
|
/// 包裹版本
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string PackageVersion { private set; get; }
|
public string PackageVersion { set; get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 超时时间
|
/// 超时时间
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int Timeout { private set; get; }
|
public int Timeout { set; get; }
|
||||||
|
|
||||||
public LoadPackageManifestOptions(string packageVersion, int timeout)
|
public LoadPackageManifestOptions(string packageVersion, int timeout)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ namespace YooAsset
|
|||||||
|
|
||||||
private readonly FileSystemHost _host;
|
private readonly FileSystemHost _host;
|
||||||
private readonly PreDownloadContentOptions _options;
|
private readonly PreDownloadContentOptions _options;
|
||||||
private readonly int _timeout;
|
|
||||||
private FSLoadPackageManifestOperation _loadPackageManifestOp;
|
private FSLoadPackageManifestOperation _loadPackageManifestOp;
|
||||||
private PackageManifest _manifest;
|
private PackageManifest _manifest;
|
||||||
private ESteps _steps = ESteps.None;
|
private ESteps _steps = ESteps.None;
|
||||||
@@ -96,109 +95,32 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 创建资源下载器,用于下载当前资源版本所有的资源包文件
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="downloadingMaxNumber">同时下载的最大文件数</param>
|
|
||||||
/// <param name="failedTryAgain">下载失败的重试次数</param>
|
|
||||||
public ResourceDownloaderOperation CreateResourceDownloader(int downloadingMaxNumber, int failedTryAgain)
|
|
||||||
{
|
|
||||||
if (Status != EOperationStatus.Succeed)
|
|
||||||
{
|
|
||||||
YooLogger.Warning($"{nameof(PreDownloadContentOperation)} status is not succeed !");
|
|
||||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_host.PackageName, downloadingMaxNumber, failedTryAgain);
|
|
||||||
}
|
|
||||||
|
|
||||||
List<BundleInfo> downloadList = _host.GetDownloadListByAll(_manifest);
|
|
||||||
var operation = new ResourceDownloaderOperation(_host.PackageName, downloadList, downloadingMaxNumber, failedTryAgain);
|
|
||||||
return operation;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 创建资源下载器,用于下载指定的资源标签关联的资源包文件
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="tag">资源标签</param>
|
|
||||||
/// <param name="downloadingMaxNumber">同时下载的最大文件数</param>
|
|
||||||
/// <param name="failedTryAgain">下载失败的重试次数</param>
|
|
||||||
public ResourceDownloaderOperation CreateResourceDownloader(string tag, int downloadingMaxNumber, int failedTryAgain)
|
|
||||||
{
|
|
||||||
if (Status != EOperationStatus.Succeed)
|
|
||||||
{
|
|
||||||
YooLogger.Warning($"{nameof(PreDownloadContentOperation)} status is not succeed !");
|
|
||||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_host.PackageName, downloadingMaxNumber, failedTryAgain);
|
|
||||||
}
|
|
||||||
|
|
||||||
List<BundleInfo> downloadList = _host.GetDownloadListByTags(_manifest, new string[] { tag });
|
|
||||||
var operation = new ResourceDownloaderOperation(_host.PackageName, downloadList, downloadingMaxNumber, failedTryAgain);
|
|
||||||
return operation;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 创建资源下载器,用于下载指定的资源标签列表关联的资源包文件
|
/// 创建资源下载器,用于下载指定的资源标签列表关联的资源包文件
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="tags">资源标签列表</param>
|
public ResourceDownloaderOperation CreateResourceDownloader(ResourceDownloaderOptions options)
|
||||||
/// <param name="downloadingMaxNumber">同时下载的最大文件数</param>
|
|
||||||
/// <param name="failedTryAgain">下载失败的重试次数</param>
|
|
||||||
public ResourceDownloaderOperation CreateResourceDownloader(string[] tags, int downloadingMaxNumber, int failedTryAgain)
|
|
||||||
{
|
{
|
||||||
if (Status != EOperationStatus.Succeed)
|
if (Status != EOperationStatus.Succeed)
|
||||||
{
|
{
|
||||||
YooLogger.Warning($"{nameof(PreDownloadContentOperation)} status is not succeed !");
|
YooLogger.Error($"{nameof(PreDownloadContentOperation)} status is not succeed !");
|
||||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_host.PackageName, downloadingMaxNumber, failedTryAgain);
|
return ResourceDownloaderOperation.CreateEmptyDownloader(_host.PackageName);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<BundleInfo> downloadList = _host.GetDownloadListByTags(_manifest, tags);
|
return _host.CreateResourceDownloader(_manifest, options);
|
||||||
var operation = new ResourceDownloaderOperation(_host.PackageName, downloadList, downloadingMaxNumber, failedTryAgain);
|
|
||||||
return operation;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 创建资源下载器,用于下载指定的资源依赖的资源包文件
|
/// 创建资源下载器,用于下载指定的资源信息列表依赖的资源包文件
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="location">资源定位地址</param>
|
public ResourceDownloaderOperation CreateBundleDownloader(BundleDownloaderOptions options)
|
||||||
/// <param name="downloadingMaxNumber">同时下载的最大文件数</param>
|
|
||||||
/// <param name="failedTryAgain">下载失败的重试次数</param>
|
|
||||||
public ResourceDownloaderOperation CreateBundleDownloader(string location, bool recursiveDownload, int downloadingMaxNumber, int failedTryAgain)
|
|
||||||
{
|
{
|
||||||
if (Status != EOperationStatus.Succeed)
|
if (Status != EOperationStatus.Succeed)
|
||||||
{
|
{
|
||||||
YooLogger.Warning($"{nameof(PreDownloadContentOperation)} status is not succeed !");
|
YooLogger.Error($"{nameof(PreDownloadContentOperation)} status is not succeed !");
|
||||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_host.PackageName, downloadingMaxNumber, failedTryAgain);
|
return ResourceDownloaderOperation.CreateEmptyDownloader(_host.PackageName);
|
||||||
}
|
}
|
||||||
|
|
||||||
List<AssetInfo> assetInfos = new List<AssetInfo>();
|
return _host.CreateResourceDownloader(_manifest, options);
|
||||||
var assetInfo = _manifest.ConvertLocationToAssetInfo(location, null);
|
|
||||||
assetInfos.Add(assetInfo);
|
|
||||||
|
|
||||||
List<BundleInfo> downloadList = _host.GetDownloadListByAssetInfos(_manifest, assetInfos.ToArray(), recursiveDownload);
|
|
||||||
var operation = new ResourceDownloaderOperation(_host.PackageName, downloadList, downloadingMaxNumber, failedTryAgain);
|
|
||||||
return operation;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 创建资源下载器,用于下载指定的资源列表依赖的资源包文件
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="locations">资源定位地址列表</param>
|
|
||||||
/// <param name="downloadingMaxNumber">同时下载的最大文件数</param>
|
|
||||||
/// <param name="failedTryAgain">下载失败的重试次数</param>
|
|
||||||
public ResourceDownloaderOperation CreateBundleDownloader(string[] locations, bool recursiveDownload, int downloadingMaxNumber, int failedTryAgain)
|
|
||||||
{
|
|
||||||
if (Status != EOperationStatus.Succeed)
|
|
||||||
{
|
|
||||||
YooLogger.Warning($"{nameof(PreDownloadContentOperation)} status is not succeed !");
|
|
||||||
return ResourceDownloaderOperation.CreateEmptyDownloader(_host.PackageName, downloadingMaxNumber, failedTryAgain);
|
|
||||||
}
|
|
||||||
|
|
||||||
List<AssetInfo> assetInfos = new List<AssetInfo>(locations.Length);
|
|
||||||
foreach (var location in locations)
|
|
||||||
{
|
|
||||||
var assetInfo = _manifest.ConvertLocationToAssetInfo(location, null);
|
|
||||||
assetInfos.Add(assetInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
List<BundleInfo> downloadList = _host.GetDownloadListByAssetInfos(_manifest, assetInfos.ToArray(), recursiveDownload);
|
|
||||||
var operation = new ResourceDownloaderOperation(_host.PackageName, downloadList, downloadingMaxNumber, failedTryAgain);
|
|
||||||
return operation;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6,12 +6,12 @@ namespace YooAsset
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 预下载的包裹版本
|
/// 预下载的包裹版本
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string PackageVersion { private set; get; }
|
public string PackageVersion { set; get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 资源清单请求超时时间
|
/// 资源清单请求超时时间
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int Timeout { private set; get; }
|
public int Timeout { set; get; }
|
||||||
|
|
||||||
public PreDownloadContentOptions(string packageVersion, int timeout)
|
public PreDownloadContentOptions(string packageVersion, int timeout)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -6,12 +6,12 @@ namespace YooAsset
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// 在URL末尾添加时间戳
|
/// 在URL末尾添加时间戳
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool AppendTimeTicks { private set; get; }
|
public bool AppendTimeTicks { set; get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 超时时间
|
/// 超时时间
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int Timeout { private set; get; }
|
public int Timeout { set; get; }
|
||||||
|
|
||||||
public RequestPackageVersionOptions(bool appendTimeTicks, int timeout)
|
public RequestPackageVersionOptions(bool appendTimeTicks, int timeout)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -285,7 +285,7 @@ namespace YooAsset
|
|||||||
{
|
{
|
||||||
DebugCheckInitialize();
|
DebugCheckInitialize();
|
||||||
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, null);
|
AssetInfo assetInfo = ConvertLocationToAssetInfo(location, null);
|
||||||
return IsNeedDownloadFromRemoteInternal(assetInfo);
|
return _fileSystemHost.IsNeedDownloadFromRemoteInternal(assetInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -295,7 +295,7 @@ namespace YooAsset
|
|||||||
public bool IsNeedDownloadFromRemote(AssetInfo assetInfo)
|
public bool IsNeedDownloadFromRemote(AssetInfo assetInfo)
|
||||||
{
|
{
|
||||||
DebugCheckInitialize();
|
DebugCheckInitialize();
|
||||||
return IsNeedDownloadFromRemoteInternal(assetInfo);
|
return _fileSystemHost.IsNeedDownloadFromRemoteInternal(assetInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -380,28 +380,6 @@ namespace YooAsset
|
|||||||
string assetPath = _fileSystemHost.ActiveManifest.TryMappingToAssetPath(location);
|
string assetPath = _fileSystemHost.ActiveManifest.TryMappingToAssetPath(location);
|
||||||
return string.IsNullOrEmpty(assetPath) == false;
|
return string.IsNullOrEmpty(assetPath) == false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool IsNeedDownloadFromRemoteInternal(AssetInfo assetInfo)
|
|
||||||
{
|
|
||||||
if (assetInfo.IsInvalid)
|
|
||||||
{
|
|
||||||
YooLogger.Warning(assetInfo.Error);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
BundleInfo bundleInfo = _fileSystemHost.GetMainBundleInfo(assetInfo);
|
|
||||||
if (bundleInfo.IsNeedDownloadFromRemote())
|
|
||||||
return true;
|
|
||||||
|
|
||||||
List<BundleInfo> depends = _fileSystemHost.GetDependBundleInfos(assetInfo);
|
|
||||||
foreach (var depend in depends)
|
|
||||||
{
|
|
||||||
if (depend.IsNeedDownloadFromRemote())
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region 原生文件
|
#region 原生文件
|
||||||
@@ -866,11 +844,11 @@ namespace YooAsset
|
|||||||
DebugCheckInitialize();
|
DebugCheckInitialize();
|
||||||
return _fileSystemHost.CreateResourceDownloader(options);
|
return _fileSystemHost.CreateResourceDownloader(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 创建资源下载器,用于下载指定的资源信息列表依赖的资源包文件
|
/// 创建资源下载器,用于下载指定的资源信息列表依赖的资源包文件
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public ResourceDownloaderOperation CreateBundleDownloader(BundleDownloaderOptions options)
|
public ResourceDownloaderOperation CreateResourceDownloader(BundleDownloaderOptions options)
|
||||||
{
|
{
|
||||||
DebugCheckInitialize();
|
DebugCheckInitialize();
|
||||||
return _fileSystemHost.CreateResourceDownloader(options);
|
return _fileSystemHost.CreateResourceDownloader(options);
|
||||||
|
|||||||
@@ -233,15 +233,6 @@ namespace YooAsset
|
|||||||
}
|
}
|
||||||
|
|
||||||
#region 系统参数
|
#region 系统参数
|
||||||
/// <summary>
|
|
||||||
/// 设置下载系统参数,自定义下载请求
|
|
||||||
/// </summary>
|
|
||||||
[Obsolete("This method is deprecated. Please use FileSystemParametersDefine.UNITY_WEB_REQUEST_CREATOR instead.", true)]
|
|
||||||
public static void SetDownloadSystemUnityWebRequest(UnityWebRequestCreator createDelegate)
|
|
||||||
{
|
|
||||||
throw new NotImplementedException();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 设置异步系统参数,每帧执行消耗的最大时间切片(单位:毫秒)
|
/// 设置异步系统参数,每帧执行消耗的最大时间切片(单位:毫秒)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@@ -337,7 +337,7 @@ public static class CompatibleResourcePackage
|
|||||||
{
|
{
|
||||||
var assetInfo = package.ConvertLocationToAssetInfo(location, null);
|
var assetInfo = package.ConvertLocationToAssetInfo(location, null);
|
||||||
var options = new BundleDownloaderOptions(assetInfo, recursiveDownload, downloadingMaxNumber, failedTryAgain);
|
var options = new BundleDownloaderOptions(assetInfo, recursiveDownload, downloadingMaxNumber, failedTryAgain);
|
||||||
return package.CreateBundleDownloader(options);
|
return package.CreateResourceDownloader(options);
|
||||||
}
|
}
|
||||||
public static ResourceDownloaderOperation CreateBundleDownloader(this ResourcePackage package, string location, int downloadingMaxNumber, int failedTryAgain)
|
public static ResourceDownloaderOperation CreateBundleDownloader(this ResourcePackage package, string location, int downloadingMaxNumber, int failedTryAgain)
|
||||||
{
|
{
|
||||||
@@ -357,7 +357,7 @@ public static class CompatibleResourcePackage
|
|||||||
}
|
}
|
||||||
|
|
||||||
var options = new BundleDownloaderOptions(assetInfos.ToArray(), recursiveDownload, downloadingMaxNumber, failedTryAgain);
|
var options = new BundleDownloaderOptions(assetInfos.ToArray(), recursiveDownload, downloadingMaxNumber, failedTryAgain);
|
||||||
return package.CreateBundleDownloader(options);
|
return package.CreateResourceDownloader(options);
|
||||||
}
|
}
|
||||||
public static ResourceDownloaderOperation CreateBundleDownloader(this ResourcePackage package, string[] locations, int downloadingMaxNumber, int failedTryAgain)
|
public static ResourceDownloaderOperation CreateBundleDownloader(this ResourcePackage package, string[] locations, int downloadingMaxNumber, int failedTryAgain)
|
||||||
{
|
{
|
||||||
@@ -371,7 +371,7 @@ public static class CompatibleResourcePackage
|
|||||||
{
|
{
|
||||||
AssetInfo[] assetInfos = new AssetInfo[] { assetInfo };
|
AssetInfo[] assetInfos = new AssetInfo[] { assetInfo };
|
||||||
var options = new BundleDownloaderOptions(assetInfos, recursiveDownload, downloadingMaxNumber, failedTryAgain);
|
var options = new BundleDownloaderOptions(assetInfos, recursiveDownload, downloadingMaxNumber, failedTryAgain);
|
||||||
return package.CreateBundleDownloader(options);
|
return package.CreateResourceDownloader(options);
|
||||||
}
|
}
|
||||||
public static ResourceDownloaderOperation CreateBundleDownloader(this ResourcePackage package, AssetInfo assetInfo, int downloadingMaxNumber, int failedTryAgain)
|
public static ResourceDownloaderOperation CreateBundleDownloader(this ResourcePackage package, AssetInfo assetInfo, int downloadingMaxNumber, int failedTryAgain)
|
||||||
{
|
{
|
||||||
@@ -384,7 +384,7 @@ public static class CompatibleResourcePackage
|
|||||||
public static ResourceDownloaderOperation CreateBundleDownloader(this ResourcePackage package, AssetInfo[] assetInfos, bool recursiveDownload, int downloadingMaxNumber, int failedTryAgain)
|
public static ResourceDownloaderOperation CreateBundleDownloader(this ResourcePackage package, AssetInfo[] assetInfos, bool recursiveDownload, int downloadingMaxNumber, int failedTryAgain)
|
||||||
{
|
{
|
||||||
var options = new BundleDownloaderOptions(assetInfos, recursiveDownload, downloadingMaxNumber, failedTryAgain);
|
var options = new BundleDownloaderOptions(assetInfos, recursiveDownload, downloadingMaxNumber, failedTryAgain);
|
||||||
return package.CreateBundleDownloader(options);
|
return package.CreateResourceDownloader(options);
|
||||||
}
|
}
|
||||||
public static ResourceDownloaderOperation CreateBundleDownloader(this ResourcePackage package, AssetInfo[] assetInfos, int downloadingMaxNumber, int failedTryAgain)
|
public static ResourceDownloaderOperation CreateBundleDownloader(this ResourcePackage package, AssetInfo[] assetInfos, int downloadingMaxNumber, int failedTryAgain)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ public class PatchEventDefine
|
|||||||
public long TotalDownloadSizeBytes;
|
public long TotalDownloadSizeBytes;
|
||||||
public long CurrentDownloadSizeBytes;
|
public long CurrentDownloadSizeBytes;
|
||||||
|
|
||||||
public static void SendEventMessage(DownloadUpdateData updateData)
|
public static void SendEventMessage(DownloadProgressChangedEventArgs updateData)
|
||||||
{
|
{
|
||||||
var msg = new DownloadUpdate();
|
var msg = new DownloadUpdate();
|
||||||
msg.TotalDownloadCount = updateData.TotalDownloadCount;
|
msg.TotalDownloadCount = updateData.TotalDownloadCount;
|
||||||
@@ -100,7 +100,7 @@ public class PatchEventDefine
|
|||||||
public string FileName;
|
public string FileName;
|
||||||
public string Error;
|
public string Error;
|
||||||
|
|
||||||
public static void SendEventMessage(DownloadErrorData errorData)
|
public static void SendEventMessage(DownloadErrorEventArgs errorData)
|
||||||
{
|
{
|
||||||
var msg = new WebFileDownloadFailed();
|
var msg = new WebFileDownloadFailed();
|
||||||
msg.FileName = errorData.FileName;
|
msg.FileName = errorData.FileName;
|
||||||
|
|||||||
@@ -26,8 +26,8 @@ public class FsmDownloadPackageFiles : IStateNode
|
|||||||
private IEnumerator BeginDownload()
|
private IEnumerator BeginDownload()
|
||||||
{
|
{
|
||||||
var downloader = (ResourceDownloaderOperation)_machine.GetBlackboardValue("Downloader");
|
var downloader = (ResourceDownloaderOperation)_machine.GetBlackboardValue("Downloader");
|
||||||
downloader.DownloadErrorCallback = PatchEventDefine.WebFileDownloadFailed.SendEventMessage;
|
downloader.DownloadErrorHandler = PatchEventDefine.WebFileDownloadFailed.SendEventMessage;
|
||||||
downloader.DownloadUpdateCallback = PatchEventDefine.DownloadUpdate.SendEventMessage;
|
downloader.DownloadProgressChangedHandler = PatchEventDefine.DownloadUpdate.SendEventMessage;
|
||||||
downloader.BeginDownload();
|
downloader.BeginDownload();
|
||||||
yield return downloader;
|
yield return downloader;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user