refactor : 重构代码
This commit is contained in:
@@ -12,7 +12,7 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 当前激活的清单
|
||||
/// </summary>
|
||||
public PackageManifest ActiveManifest { set; get; }
|
||||
public PackageManifest ActiveManifest { private set; get; }
|
||||
|
||||
|
||||
public FileSystemHost(string packageName)
|
||||
@@ -65,6 +65,44 @@ namespace YooAsset
|
||||
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 资源包相关
|
||||
private BundleInfo CreateBundleInfo(PackageBundle packageBundle)
|
||||
{
|
||||
@@ -80,10 +118,6 @@ namespace YooAsset
|
||||
|
||||
throw new YooFileSystemException($"Can not found belong file system : {packageBundle.BundleName}");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取主资源包信息
|
||||
/// </summary>
|
||||
public BundleInfo GetMainBundleInfo(AssetInfo assetInfo)
|
||||
{
|
||||
if (assetInfo == null || assetInfo.IsInvalid)
|
||||
@@ -93,20 +127,12 @@ namespace YooAsset
|
||||
var packageBundle = ActiveManifest.GetMainPackageBundle(assetInfo.Asset);
|
||||
return CreateBundleInfo(packageBundle);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取主资源包名称
|
||||
/// </summary>
|
||||
public string GetMainBundleName(int bundleID)
|
||||
{
|
||||
// 注意:如果清单里未找到资源包会抛出异常!
|
||||
var packageBundle = ActiveManifest.GetMainPackageBundle(bundleID);
|
||||
return packageBundle.BundleName;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取依赖的资源包信息集合
|
||||
/// </summary>
|
||||
public List<BundleInfo> GetDependBundleInfos(AssetInfo assetInfo)
|
||||
{
|
||||
if (assetInfo == null || assetInfo.IsInvalid)
|
||||
@@ -135,47 +161,88 @@ namespace YooAsset
|
||||
#endregion
|
||||
|
||||
#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)
|
||||
{
|
||||
return CreateResourceDownloader(ActiveManifest, options);
|
||||
}
|
||||
public ResourceDownloaderOperation CreateResourceDownloader(PackageManifest manifest, ResourceDownloaderOptions options)
|
||||
{
|
||||
List<BundleInfo> downloadList;
|
||||
if (options.Tags == null)
|
||||
downloadList = GetDownloadListByAll(ActiveManifest);
|
||||
downloadList = GetDownloadListByAll(manifest);
|
||||
else
|
||||
downloadList = GetDownloadListByTags(ActiveManifest, options.Tags);
|
||||
downloadList = GetDownloadListByTags(manifest, options.Tags);
|
||||
|
||||
var operation = new ResourceDownloaderOperation(PackageName, downloadList, options.MaximumConcurrency, options.FailedTryAgain);
|
||||
return operation;
|
||||
}
|
||||
|
||||
public ResourceDownloaderOperation CreateResourceDownloader(BundleDownloaderOptions options)
|
||||
{
|
||||
return CreateResourceDownloader(ActiveManifest, options);
|
||||
}
|
||||
public ResourceDownloaderOperation CreateResourceDownloader(PackageManifest manifest, BundleDownloaderOptions options)
|
||||
{
|
||||
List<BundleInfo> downloadList;
|
||||
if (options.AssetInfos == null)
|
||||
downloadList = GetDownloadListByAll(ActiveManifest);
|
||||
downloadList = GetDownloadListByAll(manifest);
|
||||
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);
|
||||
return operation;
|
||||
}
|
||||
|
||||
public ResourceUnpackerOperation CreateResourceUnpacker(ResourceUnpackerOptions options)
|
||||
{
|
||||
return CreateResourceUnpacker(ActiveManifest, options);
|
||||
}
|
||||
public ResourceUnpackerOperation CreateResourceUnpacker(PackageManifest manifest, ResourceUnpackerOptions options)
|
||||
{
|
||||
List<BundleInfo> unpcakList;
|
||||
if (options.Tags == null)
|
||||
unpcakList = GetUnpackListByAll(ActiveManifest);
|
||||
unpcakList = GetUnpackListByAll(manifest);
|
||||
else
|
||||
unpcakList = GetUnpackListByTags(ActiveManifest, options.Tags);
|
||||
unpcakList = GetUnpackListByTags(manifest, options.Tags);
|
||||
|
||||
var operation = new ResourceUnpackerOperation(PackageName, unpcakList, options.MaximumConcurrency, options.FailedTryAgain);
|
||||
return operation;
|
||||
}
|
||||
|
||||
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);
|
||||
return operation;
|
||||
}
|
||||
|
||||
internal List<BundleInfo> GetDownloadListByAll(PackageManifest manifest)
|
||||
private List<BundleInfo> GetDownloadListByAll(PackageManifest manifest)
|
||||
{
|
||||
if (manifest == null)
|
||||
return new List<BundleInfo>();
|
||||
@@ -195,7 +262,7 @@ namespace YooAsset
|
||||
}
|
||||
return result;
|
||||
}
|
||||
internal List<BundleInfo> GetDownloadListByTags(PackageManifest manifest, string[] tags)
|
||||
private List<BundleInfo> GetDownloadListByTags(PackageManifest manifest, string[] tags)
|
||||
{
|
||||
if (manifest == null)
|
||||
return new List<BundleInfo>();
|
||||
@@ -228,7 +295,7 @@ namespace YooAsset
|
||||
}
|
||||
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)
|
||||
return new List<BundleInfo>();
|
||||
@@ -303,7 +370,7 @@ namespace YooAsset
|
||||
}
|
||||
return result;
|
||||
}
|
||||
internal List<BundleInfo> GetUnpackListByAll(PackageManifest manifest)
|
||||
private List<BundleInfo> GetUnpackListByAll(PackageManifest manifest)
|
||||
{
|
||||
if (manifest == null)
|
||||
return new List<BundleInfo>();
|
||||
@@ -323,7 +390,7 @@ namespace YooAsset
|
||||
}
|
||||
return result;
|
||||
}
|
||||
internal List<BundleInfo> GetUnpackListByTags(PackageManifest manifest, string[] tags)
|
||||
private List<BundleInfo> GetUnpackListByTags(PackageManifest manifest, string[] tags)
|
||||
{
|
||||
if (manifest == null)
|
||||
return new List<BundleInfo>();
|
||||
@@ -346,7 +413,7 @@ namespace YooAsset
|
||||
}
|
||||
return result;
|
||||
}
|
||||
internal List<BundleInfo> GetImporterListByBundleInfos(PackageManifest manifest, ImportBundleInfo[] fileInfos)
|
||||
private List<BundleInfo> GetImporterListByBundleInfos(PackageManifest manifest, ImportBundleInfo[] fileInfos)
|
||||
{
|
||||
if (manifest == null)
|
||||
return new List<BundleInfo>();
|
||||
@@ -401,35 +468,5 @@ namespace YooAsset
|
||||
return result;
|
||||
}
|
||||
#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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user