refactor : 重构代码

This commit is contained in:
何冠峰
2026-01-16 10:28:01 +08:00
parent 2b6e7856e7
commit b0e85017d2
100 changed files with 1042 additions and 1582 deletions

View File

@@ -19,7 +19,7 @@ namespace YooAsset.Editor
buildParameters.BuildOutputRoot = AssetBundleBuilderHelper.GetDefaultBuildOutputRoot(); buildParameters.BuildOutputRoot = AssetBundleBuilderHelper.GetDefaultBuildOutputRoot();
buildParameters.BuildinFileRoot = AssetBundleBuilderHelper.GetStreamingAssetsRoot(); buildParameters.BuildinFileRoot = AssetBundleBuilderHelper.GetStreamingAssetsRoot();
buildParameters.BuildPipeline = EBuildPipeline.EditorSimulateBuildPipeline.ToString(); buildParameters.BuildPipeline = EBuildPipeline.EditorSimulateBuildPipeline.ToString();
buildParameters.BuildBundleType = (int)EBuildBundleType.VirtualBundle; buildParameters.BuildBundleType = (int)EBundleType.VirtualBundle;
buildParameters.BuildTarget = EditorUserBuildSettings.activeBuildTarget; buildParameters.BuildTarget = EditorUserBuildSettings.activeBuildTarget;
buildParameters.PackageName = packageName; buildParameters.PackageName = packageName;
buildParameters.PackageVersion = "Simulate"; buildParameters.PackageVersion = "Simulate";

View File

@@ -96,7 +96,7 @@ namespace YooAsset.Editor
/// <summary> /// <summary>
/// 资源包加密服务类 /// 资源包加密服务类
/// </summary> /// </summary>
public IEncryptionServices EncryptionServices; public IBundleEncryptionServices EncryptionServices;
/// <summary> /// <summary>
/// 资源清单加密服务类 /// 资源清单加密服务类
@@ -146,7 +146,7 @@ namespace YooAsset.Editor
string message = BuildLogger.GetErrorMessage(ErrorCode.BuildPipelineIsNullOrEmpty, "Build pipeline is null or empty !"); string message = BuildLogger.GetErrorMessage(ErrorCode.BuildPipelineIsNullOrEmpty, "Build pipeline is null or empty !");
throw new Exception(message); throw new Exception(message);
} }
if (BuildBundleType == (int)EBuildBundleType.Unknown) if (BuildBundleType == (int)EBundleType.Unknown)
{ {
string message = BuildLogger.GetErrorMessage(ErrorCode.BuildBundleTypeIsUnknown, $"Build bundle type is unknown {BuildBundleType} !"); string message = BuildLogger.GetErrorMessage(ErrorCode.BuildBundleTypeIsUnknown, $"Build bundle type is unknown {BuildBundleType} !");
throw new Exception(message); throw new Exception(message);

View File

@@ -15,7 +15,7 @@ namespace YooAsset.Editor
string buildinRootDirectory = buildParametersContext.GetBuildinRootDirectory(); string buildinRootDirectory = buildParametersContext.GetBuildinRootDirectory();
string buildPackageName = buildParametersContext.Parameters.PackageName; string buildPackageName = buildParametersContext.Parameters.PackageName;
var manifestServices = buildParametersContext.Parameters.ManifestRestoreServices; var manifestServices = buildParametersContext.Parameters.ManifestRestoreServices;
CatalogTools.CreateCatalogFile(manifestServices, buildPackageName, buildinRootDirectory); CatalogFileHelper.CreateFile(manifestServices, buildPackageName, buildinRootDirectory);
// 刷新目录 // 刷新目录
AssetDatabase.Refresh(); AssetDatabase.Refresh();

View File

@@ -31,7 +31,7 @@ namespace YooAsset.Editor
// 创建新补丁清单 // 创建新补丁清单
PackageManifest manifest = new PackageManifest(); PackageManifest manifest = new PackageManifest();
manifest.FileVersion = ManifestDefine.FileVersion; manifest.FileVersion = PackageManifestDefine.FileVersion;
manifest.EnableAddressable = buildMapContext.Command.EnableAddressable; manifest.EnableAddressable = buildMapContext.Command.EnableAddressable;
manifest.SupportExtensionless = buildMapContext.Command.SupportExtensionless; manifest.SupportExtensionless = buildMapContext.Command.SupportExtensionless;
manifest.LocationToLower = buildMapContext.Command.LocationToLower; manifest.LocationToLower = buildMapContext.Command.LocationToLower;
@@ -71,7 +71,7 @@ namespace YooAsset.Editor
{ {
string fileName = YooAssetSettingsData.GetManifestJsonFileName(buildParameters.PackageName, buildParameters.PackageVersion); string fileName = YooAssetSettingsData.GetManifestJsonFileName(buildParameters.PackageName, buildParameters.PackageVersion);
string filePath = $"{packageOutputDirectory}/{fileName}"; string filePath = $"{packageOutputDirectory}/{fileName}";
ManifestTools.SerializeToJson(filePath, manifest); PackageManifestTools.SerializeToJson(filePath, manifest);
BuildLogger.Log($"Create package manifest file: {filePath}"); BuildLogger.Log($"Create package manifest file: {filePath}");
} }
@@ -81,7 +81,7 @@ namespace YooAsset.Editor
{ {
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(buildParameters.PackageName, buildParameters.PackageVersion); string fileName = YooAssetSettingsData.GetManifestBinaryFileName(buildParameters.PackageName, buildParameters.PackageVersion);
packagePath = $"{packageOutputDirectory}/{fileName}"; packagePath = $"{packageOutputDirectory}/{fileName}";
ManifestTools.SerializeToBinary(packagePath, manifest, buildParameters.ManifestProcessServices); PackageManifestTools.SerializeToBinary(packagePath, manifest, buildParameters.ManifestProcessServices);
packageHash = HashUtility.FileCRC32(packagePath); packageHash = HashUtility.FileCRC32(packagePath);
BuildLogger.Log($"Create package manifest file: {packagePath}"); BuildLogger.Log($"Create package manifest file: {packagePath}");
} }
@@ -106,7 +106,7 @@ namespace YooAsset.Editor
{ {
ManifestContext manifestContext = new ManifestContext(); ManifestContext manifestContext = new ManifestContext();
byte[] bytesData = FileUtility.ReadAllBytes(packagePath); byte[] bytesData = FileUtility.ReadAllBytes(packagePath);
manifestContext.Manifest = ManifestTools.DeserializeFromBinary(bytesData, buildParameters.ManifestRestoreServices); manifestContext.Manifest = PackageManifestTools.DeserializeFromBinary(bytesData, buildParameters.ManifestRestoreServices);
context.SetContextObject(manifestContext); context.SetContextObject(manifestContext);
} }
} }

View File

@@ -24,7 +24,7 @@ namespace YooAsset.Editor
string pipelineOutputDirectory = buildParametersContext.GetPipelineOutputDirectory(); string pipelineOutputDirectory = buildParametersContext.GetPipelineOutputDirectory();
foreach (var bundleInfo in buildMapContext.Collection) foreach (var bundleInfo in buildMapContext.Collection)
{ {
EncryptFileInfo fileInfo = new EncryptFileInfo(); EncryptBundleInfo fileInfo = new EncryptBundleInfo();
fileInfo.BundleName = bundleInfo.BundleName; fileInfo.BundleName = bundleInfo.BundleName;
fileInfo.FileLoadPath = $"{pipelineOutputDirectory}/{bundleInfo.BundleName}"; fileInfo.FileLoadPath = $"{pipelineOutputDirectory}/{bundleInfo.BundleName}";
var encryptResult = encryptionServices.Encrypt(fileInfo); var encryptResult = encryptionServices.Encrypt(fileInfo);

View File

@@ -54,8 +54,8 @@ namespace YooAsset.Editor
{ {
string bundleName = bundleInfo.BundleName; string bundleName = bundleInfo.BundleName;
string fileHash = bundleInfo.PackageFileHash; string fileHash = bundleInfo.PackageFileHash;
string fileExtension = ManifestTools.GetRemoteBundleFileExtension(bundleName); string fileExtension = PackageManifestTools.GetRemoteBundleFileExtension(bundleName);
string fileName = ManifestTools.GetRemoteBundleFileName(outputNameStyle, bundleName, fileExtension, fileHash); string fileName = PackageManifestTools.GetRemoteBundleFileName(outputNameStyle, bundleName, fileExtension, fileHash);
bundleInfo.PackageDestFilePath = $"{packageOutputDirectory}/{fileName}"; bundleInfo.PackageDestFilePath = $"{packageOutputDirectory}/{fileName}";
} }
} }

View File

@@ -1,9 +1,9 @@
 
namespace YooAsset.Editor namespace YooAsset.Editor
{ {
public class EncryptionNone : IEncryptionServices public class EncryptionNone : IBundleEncryptionServices
{ {
public EncryptResult Encrypt(EncryptFileInfo fileInfo) public EncryptResult Encrypt(EncryptBundleInfo fileInfo)
{ {
throw new System.NotImplementedException(); throw new System.NotImplementedException();
} }

View File

@@ -46,13 +46,13 @@ namespace YooAsset.Editor
/// <summary> /// <summary>
/// 创建资源包加密服务类实例 /// 创建资源包加密服务类实例
/// </summary> /// </summary>
protected IEncryptionServices CreateEncryptionServicesInstance() protected IBundleEncryptionServices CreateEncryptionServicesInstance()
{ {
var className = AssetBundleBuilderSetting.GetPackageEncyptionServicesClassName(PackageName, PipelineName); var className = AssetBundleBuilderSetting.GetPackageEncyptionServicesClassName(PackageName, PipelineName);
var classTypes = EditorTools.GetAssignableTypes(typeof(IEncryptionServices)); var classTypes = EditorTools.GetAssignableTypes(typeof(IBundleEncryptionServices));
var classType = classTypes.Find(x => x.FullName.Equals(className)); var classType = classTypes.Find(x => x.FullName.Equals(className));
if (classType != null) if (classType != null)
return (IEncryptionServices)Activator.CreateInstance(classType); return (IBundleEncryptionServices)Activator.CreateInstance(classType);
else else
return null; return null;
} }
@@ -184,7 +184,7 @@ namespace YooAsset.Editor
protected PopupField<Type> CreateEncryptionServicesField(VisualElement container) protected PopupField<Type> CreateEncryptionServicesField(VisualElement container)
{ {
// 资源包加密服务类 // 资源包加密服务类
var classTypes = EditorTools.GetAssignableTypes(typeof(IEncryptionServices)); var classTypes = EditorTools.GetAssignableTypes(typeof(IBundleEncryptionServices));
if (classTypes.Count > 0) if (classTypes.Count > 0)
{ {
var className = AssetBundleBuilderSetting.GetPackageEncyptionServicesClassName(PackageName, PipelineName); var className = AssetBundleBuilderSetting.GetPackageEncyptionServicesClassName(PackageName, PipelineName);

View File

@@ -109,7 +109,7 @@ namespace YooAsset.Editor
buildParameters.BuildOutputRoot = AssetBundleBuilderHelper.GetDefaultBuildOutputRoot(); buildParameters.BuildOutputRoot = AssetBundleBuilderHelper.GetDefaultBuildOutputRoot();
buildParameters.BuildinFileRoot = AssetBundleBuilderHelper.GetStreamingAssetsRoot(); buildParameters.BuildinFileRoot = AssetBundleBuilderHelper.GetStreamingAssetsRoot();
buildParameters.BuildPipeline = PipelineName.ToString(); buildParameters.BuildPipeline = PipelineName.ToString();
buildParameters.BuildBundleType = (int)EBuildBundleType.AssetBundle; buildParameters.BuildBundleType = (int)EBundleType.AssetBundle;
buildParameters.BuildTarget = BuildTarget; buildParameters.BuildTarget = BuildTarget;
buildParameters.PackageName = PackageName; buildParameters.PackageName = PackageName;
buildParameters.PackageVersion = _buildVersionField.value; buildParameters.PackageVersion = _buildVersionField.value;

View File

@@ -66,7 +66,7 @@ namespace YooAsset.Editor
buildParameters.BuildOutputRoot = AssetBundleBuilderHelper.GetDefaultBuildOutputRoot(); buildParameters.BuildOutputRoot = AssetBundleBuilderHelper.GetDefaultBuildOutputRoot();
buildParameters.BuildinFileRoot = AssetBundleBuilderHelper.GetStreamingAssetsRoot(); buildParameters.BuildinFileRoot = AssetBundleBuilderHelper.GetStreamingAssetsRoot();
buildParameters.BuildPipeline = PipelineName.ToString(); buildParameters.BuildPipeline = PipelineName.ToString();
buildParameters.BuildBundleType = (int)EBuildBundleType.VirtualBundle; buildParameters.BuildBundleType = (int)EBundleType.VirtualBundle;
buildParameters.BuildTarget = BuildTarget; buildParameters.BuildTarget = BuildTarget;
buildParameters.PackageName = PackageName; buildParameters.PackageName = PackageName;
buildParameters.PackageVersion = _buildVersionField.value; buildParameters.PackageVersion = _buildVersionField.value;

View File

@@ -103,7 +103,7 @@ namespace YooAsset.Editor
buildParameters.BuildOutputRoot = AssetBundleBuilderHelper.GetDefaultBuildOutputRoot(); buildParameters.BuildOutputRoot = AssetBundleBuilderHelper.GetDefaultBuildOutputRoot();
buildParameters.BuildinFileRoot = AssetBundleBuilderHelper.GetStreamingAssetsRoot(); buildParameters.BuildinFileRoot = AssetBundleBuilderHelper.GetStreamingAssetsRoot();
buildParameters.BuildPipeline = PipelineName.ToString(); buildParameters.BuildPipeline = PipelineName.ToString();
buildParameters.BuildBundleType = (int)EBuildBundleType.RawBundle; buildParameters.BuildBundleType = (int)EBundleType.RawBundle;
buildParameters.BuildTarget = BuildTarget; buildParameters.BuildTarget = BuildTarget;
buildParameters.PackageName = PackageName; buildParameters.PackageName = PackageName;
buildParameters.PackageVersion = _buildVersionField.value; buildParameters.PackageVersion = _buildVersionField.value;

View File

@@ -109,7 +109,7 @@ namespace YooAsset.Editor
buildParameters.BuildOutputRoot = AssetBundleBuilderHelper.GetDefaultBuildOutputRoot(); buildParameters.BuildOutputRoot = AssetBundleBuilderHelper.GetDefaultBuildOutputRoot();
buildParameters.BuildinFileRoot = AssetBundleBuilderHelper.GetStreamingAssetsRoot(); buildParameters.BuildinFileRoot = AssetBundleBuilderHelper.GetStreamingAssetsRoot();
buildParameters.BuildPipeline = PipelineName.ToString(); buildParameters.BuildPipeline = PipelineName.ToString();
buildParameters.BuildBundleType = (int)EBuildBundleType.AssetBundle; buildParameters.BuildBundleType = (int)EBundleType.AssetBundle;
buildParameters.BuildTarget = BuildTarget; buildParameters.BuildTarget = BuildTarget;
buildParameters.PackageName = PackageName; buildParameters.PackageName = PackageName;
buildParameters.PackageVersion = _buildVersionField.value; buildParameters.PackageVersion = _buildVersionField.value;

View File

@@ -277,7 +277,7 @@ namespace YooAsset.Editor
if (dependTableData.BundleInfo.Encrypted) if (dependTableData.BundleInfo.Encrypted)
return; return;
if (_buildReport.Summary.BuildBundleType == (int)EBuildBundleType.AssetBundle) if (_buildReport.Summary.BuildBundleType == (int)EBundleType.AssetBundle)
{ {
string rootDirectory = Path.GetDirectoryName(_reportFilePath); string rootDirectory = Path.GetDirectoryName(_reportFilePath);
string filePath = $"{rootDirectory}/{dependTableData.BundleInfo.FileName}"; string filePath = $"{rootDirectory}/{dependTableData.BundleInfo.FileName}";

View File

@@ -348,7 +348,7 @@ namespace YooAsset.Editor
if (bundleTableData.BundleInfo.Encrypted) if (bundleTableData.BundleInfo.Encrypted)
return; return;
if (_buildReport.Summary.BuildBundleType == (int)EBuildBundleType.AssetBundle) if (_buildReport.Summary.BuildBundleType == (int)EBundleType.AssetBundle)
{ {
string rootDirectory = Path.GetDirectoryName(_reportFilePath); string rootDirectory = Path.GetDirectoryName(_reportFilePath);
string filePath = $"{rootDirectory}/{bundleTableData.BundleInfo.FileName}"; string filePath = $"{rootDirectory}/{bundleTableData.BundleInfo.FileName}";

View File

@@ -3,9 +3,9 @@ using System.Collections.Generic;
namespace YooAsset namespace YooAsset
{ {
/// <summary> /// <summary>
/// 导入文件的信息 /// 导入的资源包信息
/// </summary> /// </summary>
public struct ImportFileInfo public struct ImportBundleInfo
{ {
/// <summary> /// <summary>
/// 本地文件路径 /// 本地文件路径

View File

@@ -1,7 +1,7 @@
 
namespace YooAsset namespace YooAsset
{ {
internal class CatalogDefine internal class CatalogFileDefine
{ {
/// <summary> /// <summary>
/// 文件极限大小100MB /// 文件极限大小100MB

View File

@@ -5,14 +5,14 @@ using UnityEngine;
namespace YooAsset namespace YooAsset
{ {
internal static class CatalogTools internal static class CatalogFileHelper
{ {
#if UNITY_EDITOR #if UNITY_EDITOR
/// <summary> /// <summary>
/// 生成包裹的内置资源目录文件 /// 生成包裹的内置资源目录文件
/// 说明:根据指定目录下的文件生成清单文件。 /// 说明:根据指定目录下的文件生成清单文件。
/// </summary> /// </summary>
public static bool CreateCatalogFile(IManifestRestoreServices services, string packageName, string packageDirectory) public static bool CreateFile(IManifestRestoreServices services, string packageName, string packageDirectory)
{ {
// 获取资源清单版本 // 获取资源清单版本
string packageVersion; string packageVersion;
@@ -40,7 +40,7 @@ namespace YooAsset
} }
var binaryData = FileUtility.ReadAllBytes(manifestFilePath); var binaryData = FileUtility.ReadAllBytes(manifestFilePath);
packageManifest = ManifestTools.DeserializeFromBinary(binaryData, services); packageManifest = PackageManifestTools.DeserializeFromBinary(binaryData, services);
} }
// 获取文件名映射关系 // 获取文件名映射关系
@@ -54,7 +54,7 @@ namespace YooAsset
// 创建内置清单实例 // 创建内置清单实例
var buildinFileCatalog = new DefaultBuildinFileCatalog(); var buildinFileCatalog = new DefaultBuildinFileCatalog();
buildinFileCatalog.FileVersion = CatalogDefine.FileVersion; buildinFileCatalog.FileVersion = CatalogFileDefine.FileVersion;
buildinFileCatalog.PackageName = packageName; buildinFileCatalog.PackageName = packageName;
buildinFileCatalog.PackageVersion = packageVersion; buildinFileCatalog.PackageVersion = packageVersion;
@@ -122,11 +122,11 @@ namespace YooAsset
/// <summary> /// <summary>
/// 生成空的包裹内置资源目录文件 /// 生成空的包裹内置资源目录文件
/// </summary> /// </summary>
public static bool CreateEmptyCatalogFile(string packageName, string packageVersion, string outputPath) public static bool CreateEmptyFile(string packageName, string packageVersion, string outputPath)
{ {
// 创建内置清单实例 // 创建内置清单实例
var buildinFileCatalog = new DefaultBuildinFileCatalog(); var buildinFileCatalog = new DefaultBuildinFileCatalog();
buildinFileCatalog.FileVersion = CatalogDefine.FileVersion; buildinFileCatalog.FileVersion = CatalogFileDefine.FileVersion;
buildinFileCatalog.PackageName = packageName; buildinFileCatalog.PackageName = packageName;
buildinFileCatalog.PackageVersion = packageVersion; buildinFileCatalog.PackageVersion = packageVersion;
@@ -173,13 +173,13 @@ namespace YooAsset
using (FileStream fs = new FileStream(savePath, FileMode.Create)) using (FileStream fs = new FileStream(savePath, FileMode.Create))
{ {
// 创建缓存器 // 创建缓存器
BufferWriter buffer = new BufferWriter(CatalogDefine.FileMaxSize); BufferWriter buffer = new BufferWriter(CatalogFileDefine.FileMaxSize);
// 写入文件标记 // 写入文件标记
buffer.WriteUInt32(CatalogDefine.FileSign); buffer.WriteUInt32(CatalogFileDefine.FileSign);
// 写入文件版本 // 写入文件版本
buffer.WriteUTF8(CatalogDefine.FileVersion); buffer.WriteUTF8(CatalogFileDefine.FileVersion);
// 写入文件头信息 // 写入文件头信息
buffer.WriteUTF8(catalog.PackageName); buffer.WriteUTF8(catalog.PackageName);
@@ -213,13 +213,13 @@ namespace YooAsset
// 读取文件标记 // 读取文件标记
uint fileSign = buffer.ReadUInt32(); uint fileSign = buffer.ReadUInt32();
if (fileSign != CatalogDefine.FileSign) if (fileSign != CatalogFileDefine.FileSign)
throw new Exception("Invalid catalog file !"); throw new Exception("Invalid catalog file !");
// 读取文件版本 // 读取文件版本
string fileVersion = buffer.ReadUTF8(); string fileVersion = buffer.ReadUTF8();
if (fileVersion != CatalogDefine.FileVersion) if (fileVersion != CatalogFileDefine.FileVersion)
throw new Exception($"The catalog file version are not compatible : {fileVersion} != {CatalogDefine.FileVersion}"); throw new Exception($"The catalog file version are not compatible : {fileVersion} != {CatalogFileDefine.FileVersion}");
DefaultBuildinFileCatalog catalog = new DefaultBuildinFileCatalog(); DefaultBuildinFileCatalog catalog = new DefaultBuildinFileCatalog();
{ {

View File

@@ -107,12 +107,12 @@ namespace YooAsset
/// <summary> /// <summary>
/// 自定义参数:解密服务接口的实例类 /// 自定义参数:解密服务接口的实例类
/// </summary> /// </summary>
public IDecryptionServices DecryptionServices { private set; get; } public IBundleDecryptionServices BundleDecryptionServices { private set; get; }
/// <summary> /// <summary>
/// 自定义参数:资源清单服务类 /// 自定义参数:资源清单服务类
/// </summary> /// </summary>
public IManifestRestoreServices ManifestServices { private set; get; } public IManifestRestoreServices ManifestRestoreServices { private set; get; }
/// <summary> /// <summary>
/// 自定义参数:拷贝内置文件接口的实例类 /// 自定义参数:拷贝内置文件接口的实例类
@@ -139,29 +139,30 @@ namespace YooAsset
var operation = new DBFSLoadPackageManifestOperation(this, options.PackageVersion); var operation = new DBFSLoadPackageManifestOperation(this, options.PackageVersion);
return operation; return operation;
} }
public virtual FSClearCacheFilesOperation ClearCacheFilesAsync(PackageManifest manifest, ClearCacheFilesOptions options) public virtual FSClearCacheFilesOperation ClearCacheFilesAsync(ClearCacheFilesOptions options)
{ {
return _unpackFileSystem.ClearCacheFilesAsync(manifest, options); return _unpackFileSystem.ClearCacheFilesAsync(options);
} }
public virtual FSDownloadFileOperation DownloadFileAsync(PackageBundle bundle, DownloadFileOptions options) public virtual FSDownloadFileOperation DownloadFileAsync(DownloadFileOptions options)
{ {
// 注意:业务层的解压器会依赖该方法 // 注意:业务层的解压器会依赖该方法
options.ImportFilePath = GetBuildinFileLoadPath(bundle); options.ImportFilePath = GetBuildinFileLoadPath(options.Bundle);
return _unpackFileSystem.DownloadFileAsync(bundle, options); return _unpackFileSystem.DownloadFileAsync(options);
} }
public virtual FSLoadBundleOperation LoadBundleFile(PackageBundle bundle) public virtual FSLoadBundleOperation LoadBundleAsync(LoadBundleOptions options)
{ {
PackageBundle bundle = options.Bundle;
if (IsUnpackBundleFile(bundle)) if (IsUnpackBundleFile(bundle))
{ {
return _unpackFileSystem.LoadBundleFile(bundle); return _unpackFileSystem.LoadBundleAsync(options);
} }
if (bundle.BundleType == (int)EBuildBundleType.AssetBundle) if (bundle.BundleType == (int)EBundleType.AssetBundle)
{ {
var operation = new DBFSLoadAssetBundleOperation(this, bundle); var operation = new DBFSLoadAssetBundleOperation(this, bundle);
return operation; return operation;
} }
else if (bundle.BundleType == (int)EBuildBundleType.RawBundle) else if (bundle.BundleType == (int)EBundleType.RawBundle)
{ {
var operation = new DBFSLoadRawBundleOperation(this, bundle); var operation = new DBFSLoadRawBundleOperation(this, bundle);
return operation; return operation;
@@ -224,13 +225,13 @@ namespace YooAsset
{ {
UnpackFileSystemRoot = (string)value; UnpackFileSystemRoot = (string)value;
} }
else if (name == FileSystemParametersDefine.DECRYPTION_SERVICES) else if (name == FileSystemParametersDefine.BUNDLE_DECRYPTION_SERVICES)
{ {
DecryptionServices = (IDecryptionServices)value; BundleDecryptionServices = (IBundleDecryptionServices)value;
} }
else if (name == FileSystemParametersDefine.MANIFEST_SERVICES) else if (name == FileSystemParametersDefine.MANIFEST_RESTORE_SERVICES)
{ {
ManifestServices = (IManifestRestoreServices)value; ManifestRestoreServices = (IManifestRestoreServices)value;
} }
else if (name == FileSystemParametersDefine.COPY_LOCAL_FILE_SERVICES) else if (name == FileSystemParametersDefine.COPY_LOCAL_FILE_SERVICES)
{ {
@@ -264,7 +265,7 @@ namespace YooAsset
_unpackFileSystem.SetParameter(FileSystemParametersDefine.FILE_VERIFY_LEVEL, FileVerifyLevel); _unpackFileSystem.SetParameter(FileSystemParametersDefine.FILE_VERIFY_LEVEL, FileVerifyLevel);
_unpackFileSystem.SetParameter(FileSystemParametersDefine.FILE_VERIFY_MAX_CONCURRENCY, FileVerifyMaxConcurrency); _unpackFileSystem.SetParameter(FileSystemParametersDefine.FILE_VERIFY_MAX_CONCURRENCY, FileVerifyMaxConcurrency);
_unpackFileSystem.SetParameter(FileSystemParametersDefine.APPEND_FILE_EXTENSION, AppendFileExtension); _unpackFileSystem.SetParameter(FileSystemParametersDefine.APPEND_FILE_EXTENSION, AppendFileExtension);
_unpackFileSystem.SetParameter(FileSystemParametersDefine.DECRYPTION_SERVICES, DecryptionServices); _unpackFileSystem.SetParameter(FileSystemParametersDefine.BUNDLE_DECRYPTION_SERVICES, BundleDecryptionServices);
_unpackFileSystem.SetParameter(FileSystemParametersDefine.COPY_LOCAL_FILE_SERVICES, CopyLocalFileServices); _unpackFileSystem.SetParameter(FileSystemParametersDefine.COPY_LOCAL_FILE_SERVICES, CopyLocalFileServices);
_unpackFileSystem.OnCreate(packageName, UnpackFileSystemRoot); _unpackFileSystem.OnCreate(packageName, UnpackFileSystemRoot);
} }
@@ -409,7 +410,7 @@ namespace YooAsset
if (bundle.Encrypted) if (bundle.Encrypted)
return true; return true;
if (bundle.BundleType == (int)EBuildBundleType.RawBundle) if (bundle.BundleType == (int)EBundleType.RawBundle)
return true; return true;
return false; return false;
@@ -479,31 +480,31 @@ namespace YooAsset
/// <summary> /// <summary>
/// 加载加密的资源文件 /// 加载加密的资源文件
/// </summary> /// </summary>
public DecryptResult LoadEncryptedAssetBundle(PackageBundle bundle) public DecryptSyncResult LoadEncryptedBundleSync(PackageBundle bundle)
{ {
string filePath = GetBuildinFileLoadPath(bundle); string filePath = GetBuildinFileLoadPath(bundle);
var fileInfo = new DecryptFileInfo() var bundleInfo = new DecryptBundleInfo()
{ {
BundleName = bundle.BundleName, BundleName = bundle.BundleName,
FileLoadCRC = bundle.UnityCRC, FileLoadCRC = bundle.UnityCRC,
FileLoadPath = filePath, FileLoadPath = filePath,
}; };
return DecryptionServices.LoadAssetBundle(fileInfo); return BundleDecryptionServices.LoadAssetBundleSync(bundleInfo);
} }
/// <summary> /// <summary>
/// 加载加密的资源文件 /// 加载加密的资源文件
/// </summary> /// </summary>
public DecryptResult LoadEncryptedAssetBundleAsync(PackageBundle bundle) public DecryptAsyncResult LoadEncryptedBundleAsync(PackageBundle bundle)
{ {
string filePath = GetBuildinFileLoadPath(bundle); string filePath = GetBuildinFileLoadPath(bundle);
var fileInfo = new DecryptFileInfo() var bundleInfo = new DecryptBundleInfo()
{ {
BundleName = bundle.BundleName, BundleName = bundle.BundleName,
FileLoadCRC = bundle.UnityCRC, FileLoadCRC = bundle.UnityCRC,
FileLoadPath = filePath, FileLoadPath = filePath,
}; };
return DecryptionServices.LoadAssetBundleAsync(fileInfo); return BundleDecryptionServices.LoadAssetBundleAsync(bundleInfo);
} }
#endregion #endregion
} }

View File

@@ -44,11 +44,11 @@ namespace YooAsset
{ {
if (_bundle.Encrypted) if (_bundle.Encrypted)
{ {
if (_fileSystem.DecryptionServices == null) if (_fileSystem.BundleDecryptionServices == null)
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = $"The {nameof(IDecryptionServices)} is null !"; Error = $"The {nameof(IBundleDecryptionServices)} is null !";
YooLogger.Error(Error); YooLogger.Error(Error);
return; return;
} }
@@ -58,7 +58,7 @@ namespace YooAsset
{ {
if (_bundle.Encrypted) if (_bundle.Encrypted)
{ {
var decryptResult = _fileSystem.LoadEncryptedAssetBundle(_bundle); var decryptResult = _fileSystem.LoadEncryptedBundleSync(_bundle);
_assetBundle = decryptResult.Result; _assetBundle = decryptResult.Result;
_managedStream = decryptResult.ManagedStream; _managedStream = decryptResult.ManagedStream;
} }
@@ -72,7 +72,7 @@ namespace YooAsset
{ {
if (_bundle.Encrypted) if (_bundle.Encrypted)
{ {
var decryptResult = _fileSystem.LoadEncryptedAssetBundleAsync(_bundle); var decryptResult = _fileSystem.LoadEncryptedBundleAsync(_bundle);
_createRequest = decryptResult.CreateRequest; _createRequest = decryptResult.CreateRequest;
_managedStream = decryptResult.ManagedStream; _managedStream = decryptResult.ManagedStream;
} }

View File

@@ -82,7 +82,7 @@ namespace YooAsset
{ {
try try
{ {
Catalog = CatalogTools.DeserializeFromBinary(_fileData); Catalog = CatalogFileHelper.DeserializeFromBinary(_fileData);
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Succeed; Status = EOperationStatus.Succeed;
} }

View File

@@ -86,7 +86,7 @@ namespace YooAsset
if (_steps == ESteps.VerifyFileData) if (_steps == ESteps.VerifyFileData)
{ {
if (ManifestTools.VerifyManifestData(_fileData, _packageHash)) if (PackageManifestTools.VerifyManifestData(_fileData, _packageHash))
{ {
_steps = ESteps.LoadManifest; _steps = ESteps.LoadManifest;
} }
@@ -102,7 +102,7 @@ namespace YooAsset
{ {
if (_deserializer == null) if (_deserializer == null)
{ {
_deserializer = new DeserializeManifestOperation(_fileSystem.ManifestServices, _fileData); _deserializer = new DeserializeManifestOperation(_fileSystem.ManifestRestoreServices, _fileData);
_deserializer.StartOperation(); _deserializer.StartOperation();
AddChildOperation(_deserializer); AddChildOperation(_deserializer);
} }

View File

@@ -129,12 +129,12 @@ namespace YooAsset
/// <summary> /// <summary>
/// 自定义参数:解密服务接口的实例类 /// 自定义参数:解密服务接口的实例类
/// </summary> /// </summary>
public IDecryptionServices DecryptionServices { private set; get; } public IBundleDecryptionServices BundleDecryptionServices { private set; get; }
/// <summary> /// <summary>
/// 自定义参数:资源清单服务类 /// 自定义参数:资源清单服务类
/// </summary> /// </summary>
public IManifestRestoreServices ManifestServices { private set; get; } public IManifestRestoreServices ManifestRestoreServices { private set; get; }
/// <summary> /// <summary>
/// 自定义参数:拷贝内置文件接口的实例类 /// 自定义参数:拷贝内置文件接口的实例类
@@ -161,7 +161,7 @@ namespace YooAsset
var operation = new DCFSLoadPackageManifestOperation(this, options.PackageVersion, options.Timeout); var operation = new DCFSLoadPackageManifestOperation(this, options.PackageVersion, options.Timeout);
return operation; return operation;
} }
public virtual FSClearCacheFilesOperation ClearCacheFilesAsync(PackageManifest manifest, ClearCacheFilesOptions options) public virtual FSClearCacheFilesOperation ClearCacheFilesAsync(ClearCacheFilesOptions options)
{ {
if (options.ClearMode == EFileClearMode.ClearAllBundleFiles.ToString()) if (options.ClearMode == EFileClearMode.ClearAllBundleFiles.ToString())
{ {
@@ -170,17 +170,17 @@ namespace YooAsset
} }
else if (options.ClearMode == EFileClearMode.ClearUnusedBundleFiles.ToString()) else if (options.ClearMode == EFileClearMode.ClearUnusedBundleFiles.ToString())
{ {
var operation = new ClearUnusedCacheBundleFilesOperation(this, manifest); var operation = new ClearUnusedCacheBundleFilesOperation(this, options.Manifest);
return operation; return operation;
} }
else if (options.ClearMode == EFileClearMode.ClearBundleFilesByLocations.ToString()) else if (options.ClearMode == EFileClearMode.ClearBundleFilesByLocations.ToString())
{ {
var operation = new ClearCacheBundleFilesByLocationsOperaiton(this, manifest, options.ClearParam); var operation = new ClearCacheBundleFilesByLocationsOperaiton(this, options.Manifest, options.ClearParam);
return operation; return operation;
} }
else if (options.ClearMode == EFileClearMode.ClearBundleFilesByTags.ToString()) else if (options.ClearMode == EFileClearMode.ClearBundleFilesByTags.ToString())
{ {
var operation = new ClearCacheBundleFilesByTagsOperaiton(this, manifest, options.ClearParam); var operation = new ClearCacheBundleFilesByTagsOperaiton(this, options.Manifest, options.ClearParam);
return operation; return operation;
} }
else if (options.ClearMode == EFileClearMode.ClearAllManifestFiles.ToString()) else if (options.ClearMode == EFileClearMode.ClearAllManifestFiles.ToString())
@@ -190,7 +190,7 @@ namespace YooAsset
} }
else if (options.ClearMode == EFileClearMode.ClearUnusedManifestFiles.ToString()) else if (options.ClearMode == EFileClearMode.ClearUnusedManifestFiles.ToString())
{ {
var operation = new ClearUnusedCacheManifestFilesOperation(this, manifest); var operation = new ClearUnusedCacheManifestFilesOperation(this, options.Manifest);
return operation; return operation;
} }
else else
@@ -200,9 +200,10 @@ namespace YooAsset
return operation; return operation;
} }
} }
public virtual FSDownloadFileOperation DownloadFileAsync(PackageBundle bundle, DownloadFileOptions options) public virtual FSDownloadFileOperation DownloadFileAsync(DownloadFileOptions options)
{ {
// 获取下载地址 // 获取下载地址
PackageBundle bundle = options.Bundle;
if (string.IsNullOrEmpty(options.ImportFilePath)) if (string.IsNullOrEmpty(options.ImportFilePath))
{ {
// 注意:如果是解压文件系统类,这里会返回本地内置文件的下载路径 // 注意:如果是解压文件系统类,这里会返回本地内置文件的下载路径
@@ -217,17 +218,18 @@ namespace YooAsset
options.SetURL(mainURL, mainURL); options.SetURL(mainURL, mainURL);
} }
var downloader = new DownloadPackageBundleOperation(this, bundle, options); var downloader = new DownloadPackageBundleOperation(this, options);
return downloader; return downloader;
} }
public virtual FSLoadBundleOperation LoadBundleFile(PackageBundle bundle) public virtual FSLoadBundleOperation LoadBundleAsync(LoadBundleOptions options)
{ {
if (bundle.BundleType == (int)EBuildBundleType.AssetBundle) PackageBundle bundle = options.Bundle;
if (bundle.BundleType == (int)EBundleType.AssetBundle)
{ {
var operation = new DCFSLoadAssetBundleOperation(this, bundle); var operation = new DCFSLoadAssetBundleOperation(this, bundle);
return operation; return operation;
} }
else if (bundle.BundleType == (int)EBuildBundleType.RawBundle) else if (bundle.BundleType == (int)EBundleType.RawBundle)
{ {
var operation = new DCFSLoadRawBundleOperation(this, bundle); var operation = new DCFSLoadRawBundleOperation(this, bundle);
return operation; return operation;
@@ -315,13 +317,13 @@ namespace YooAsset
{ {
ResumeDownloadResponseCodes = (List<long>)value; ResumeDownloadResponseCodes = (List<long>)value;
} }
else if (name == FileSystemParametersDefine.DECRYPTION_SERVICES) else if (name == FileSystemParametersDefine.BUNDLE_DECRYPTION_SERVICES)
{ {
DecryptionServices = (IDecryptionServices)value; BundleDecryptionServices = (IBundleDecryptionServices)value;
} }
else if (name == FileSystemParametersDefine.MANIFEST_SERVICES) else if (name == FileSystemParametersDefine.MANIFEST_RESTORE_SERVICES)
{ {
ManifestServices = (IManifestRestoreServices)value; ManifestRestoreServices = (IManifestRestoreServices)value;
} }
else if (name == FileSystemParametersDefine.COPY_LOCAL_FILE_SERVICES) else if (name == FileSystemParametersDefine.COPY_LOCAL_FILE_SERVICES)
{ {
@@ -403,20 +405,20 @@ namespace YooAsset
if (bundle.Encrypted) if (bundle.Encrypted)
{ {
if (DecryptionServices == null) if (BundleDecryptionServices == null)
{ {
YooLogger.Error($"The {nameof(IDecryptionServices)} is null !"); YooLogger.Error($"The {nameof(IBundleDecryptionServices)} is null !");
return null; return null;
} }
string filePath = GetCacheBundleFileLoadPath(bundle); string filePath = GetCacheBundleFileLoadPath(bundle);
var fileInfo = new DecryptFileInfo() var bundleInfo = new DecryptBundleInfo()
{ {
BundleName = bundle.BundleName, BundleName = bundle.BundleName,
FileLoadCRC = bundle.UnityCRC, FileLoadCRC = bundle.UnityCRC,
FileLoadPath = filePath, FileLoadPath = filePath,
}; };
return DecryptionServices.ReadFileData(fileInfo); return BundleDecryptionServices.ReadFileData(bundleInfo);
} }
else else
{ {
@@ -431,20 +433,20 @@ namespace YooAsset
if (bundle.Encrypted) if (bundle.Encrypted)
{ {
if (DecryptionServices == null) if (BundleDecryptionServices == null)
{ {
YooLogger.Error($"The {nameof(IDecryptionServices)} is null !"); YooLogger.Error($"The {nameof(IBundleDecryptionServices)} is null !");
return null; return null;
} }
string filePath = GetCacheBundleFileLoadPath(bundle); string filePath = GetCacheBundleFileLoadPath(bundle);
var fileInfo = new DecryptFileInfo() var bundleInfo = new DecryptBundleInfo()
{ {
BundleName = bundle.BundleName, BundleName = bundle.BundleName,
FileLoadCRC = bundle.UnityCRC, FileLoadCRC = bundle.UnityCRC,
FileLoadPath = filePath, FileLoadPath = filePath,
}; };
return DecryptionServices.ReadFileText(fileInfo); return BundleDecryptionServices.ReadFileText(bundleInfo);
} }
else else
{ {
@@ -649,46 +651,46 @@ namespace YooAsset
/// <summary> /// <summary>
/// 加载加密资源文件 /// 加载加密资源文件
/// </summary> /// </summary>
public DecryptResult LoadEncryptedAssetBundle(PackageBundle bundle) public DecryptSyncResult LoadEncryptedBundleSync(PackageBundle bundle)
{ {
string filePath = GetCacheBundleFileLoadPath(bundle); string filePath = GetCacheBundleFileLoadPath(bundle);
var fileInfo = new DecryptFileInfo() var bundleInfo = new DecryptBundleInfo()
{ {
BundleName = bundle.BundleName, BundleName = bundle.BundleName,
FileLoadCRC = bundle.UnityCRC, FileLoadCRC = bundle.UnityCRC,
FileLoadPath = filePath, FileLoadPath = filePath,
}; };
return DecryptionServices.LoadAssetBundle(fileInfo); return BundleDecryptionServices.LoadAssetBundleSync(bundleInfo);
} }
/// <summary> /// <summary>
/// 加载加密资源文件 /// 加载加密资源文件
/// </summary> /// </summary>
public DecryptResult LoadEncryptedAssetBundleAsync(PackageBundle bundle) public DecryptAsyncResult LoadEncryptedBundleAsync(PackageBundle bundle)
{ {
string filePath = GetCacheBundleFileLoadPath(bundle); string filePath = GetCacheBundleFileLoadPath(bundle);
var fileInfo = new DecryptFileInfo() var bundleInfo = new DecryptBundleInfo()
{ {
BundleName = bundle.BundleName, BundleName = bundle.BundleName,
FileLoadCRC = bundle.UnityCRC, FileLoadCRC = bundle.UnityCRC,
FileLoadPath = filePath, FileLoadPath = filePath,
}; };
return DecryptionServices.LoadAssetBundleAsync(fileInfo); return BundleDecryptionServices.LoadAssetBundleAsync(bundleInfo);
} }
/// <summary> /// <summary>
/// 加载加密资源文件 /// 加载加密资源文件
/// </summary> /// </summary>
public DecryptResult LoadEncryptedAssetBundleFallback(PackageBundle bundle) public DecryptSyncResult LoadEncryptedBundleFallback(PackageBundle bundle)
{ {
string filePath = GetCacheBundleFileLoadPath(bundle); string filePath = GetCacheBundleFileLoadPath(bundle);
var fileInfo = new DecryptFileInfo() var bundleInfo = new DecryptBundleInfo()
{ {
BundleName = bundle.BundleName, BundleName = bundle.BundleName,
FileLoadCRC = bundle.UnityCRC, FileLoadCRC = bundle.UnityCRC,
FileLoadPath = filePath, FileLoadPath = filePath,
}; };
return DecryptionServices.LoadAssetBundleFallback(fileInfo); return BundleDecryptionServices.LoadAssetBundleFallback(bundleInfo);
} }
#endregion #endregion
} }

View File

@@ -79,8 +79,8 @@ namespace YooAsset
{ {
if (_downloadFileOp == null) if (_downloadFileOp == null)
{ {
DownloadFileOptions options = new DownloadFileOptions(int.MaxValue); DownloadFileOptions options = new DownloadFileOptions(_bundle, int.MaxValue);
_downloadFileOp = _fileSystem.DownloadFileAsync(_bundle, options); _downloadFileOp = _fileSystem.DownloadFileAsync(options);
_downloadFileOp.StartOperation(); _downloadFileOp.StartOperation();
AddChildOperation(_downloadFileOp); AddChildOperation(_downloadFileOp);
} }
@@ -127,11 +127,11 @@ namespace YooAsset
{ {
if (_bundle.Encrypted) if (_bundle.Encrypted)
{ {
if (_fileSystem.DecryptionServices == null) if (_fileSystem.BundleDecryptionServices == null)
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = $"The {nameof(IDecryptionServices)} is null !"; Error = $"The {nameof(IBundleDecryptionServices)} is null !";
YooLogger.Error(Error); YooLogger.Error(Error);
return; return;
} }
@@ -141,7 +141,7 @@ namespace YooAsset
{ {
if (_bundle.Encrypted) if (_bundle.Encrypted)
{ {
var decryptResult = _fileSystem.LoadEncryptedAssetBundle(_bundle); var decryptResult = _fileSystem.LoadEncryptedBundleSync(_bundle);
_assetBundle = decryptResult.Result; _assetBundle = decryptResult.Result;
_managedStream = decryptResult.ManagedStream; _managedStream = decryptResult.ManagedStream;
} }
@@ -155,7 +155,7 @@ namespace YooAsset
{ {
if (_bundle.Encrypted) if (_bundle.Encrypted)
{ {
var decryptResult = _fileSystem.LoadEncryptedAssetBundleAsync(_bundle); var decryptResult = _fileSystem.LoadEncryptedBundleAsync(_bundle);
_createRequest = decryptResult.CreateRequest; _createRequest = decryptResult.CreateRequest;
_managedStream = decryptResult.ManagedStream; _managedStream = decryptResult.ManagedStream;
} }
@@ -202,7 +202,7 @@ namespace YooAsset
{ {
if (_bundle.Encrypted) if (_bundle.Encrypted)
{ {
var decryptResult = _fileSystem.LoadEncryptedAssetBundleFallback(_bundle); var decryptResult = _fileSystem.LoadEncryptedBundleFallback(_bundle);
_assetBundle = decryptResult.Result; _assetBundle = decryptResult.Result;
if (_assetBundle != null) if (_assetBundle != null)
{ {
@@ -348,8 +348,8 @@ namespace YooAsset
{ {
if (_downloadFileOp == null) if (_downloadFileOp == null)
{ {
DownloadFileOptions options = new DownloadFileOptions(int.MaxValue); DownloadFileOptions options = new DownloadFileOptions(_bundle, int.MaxValue);
_downloadFileOp = _fileSystem.DownloadFileAsync(_bundle, options); _downloadFileOp = _fileSystem.DownloadFileAsync(options);
_downloadFileOp.StartOperation(); _downloadFileOp.StartOperation();
AddChildOperation(_downloadFileOp); AddChildOperation(_downloadFileOp);
} }

View File

@@ -26,7 +26,7 @@ namespace YooAsset
private ESteps _steps = ESteps.None; private ESteps _steps = ESteps.None;
internal DownloadPackageBundleOperation(DefaultCacheFileSystem fileSystem, PackageBundle bundle, DownloadFileOptions options) : base(bundle) internal DownloadPackageBundleOperation(DefaultCacheFileSystem fileSystem, DownloadFileOptions options) : base(options.Bundle)
{ {
_fileSystem = fileSystem; _fileSystem = fileSystem;
_options = options; _options = options;

View File

@@ -59,7 +59,7 @@ namespace YooAsset
if (_steps == ESteps.VerifyFileData) if (_steps == ESteps.VerifyFileData)
{ {
if (ManifestTools.VerifyManifestData(_fileData, _packageHash)) if (PackageManifestTools.VerifyManifestData(_fileData, _packageHash))
{ {
_steps = ESteps.LoadManifest; _steps = ESteps.LoadManifest;
} }
@@ -75,7 +75,7 @@ namespace YooAsset
{ {
if (_deserializer == null) if (_deserializer == null)
{ {
_deserializer = new DeserializeManifestOperation(_fileSystem.ManifestServices, _fileData); _deserializer = new DeserializeManifestOperation(_fileSystem.ManifestRestoreServices, _fileData);
_deserializer.StartOperation(); _deserializer.StartOperation();
AddChildOperation(_deserializer); AddChildOperation(_deserializer);
} }

View File

@@ -93,21 +93,22 @@ namespace YooAsset
var operation = new DEFSLoadPackageManifestOperation(this, options.PackageVersion); var operation = new DEFSLoadPackageManifestOperation(this, options.PackageVersion);
return operation; return operation;
} }
public virtual FSClearCacheFilesOperation ClearCacheFilesAsync(PackageManifest manifest, ClearCacheFilesOptions options) public virtual FSClearCacheFilesOperation ClearCacheFilesAsync(ClearCacheFilesOptions options)
{ {
var operation = new FSClearCacheFilesCompleteOperation(); var operation = new FSClearCacheFilesCompleteOperation();
return operation; return operation;
} }
public virtual FSDownloadFileOperation DownloadFileAsync(PackageBundle bundle, DownloadFileOptions options) public virtual FSDownloadFileOperation DownloadFileAsync(DownloadFileOptions options)
{ {
string mainURL = bundle.BundleName; string mainURL = options.Bundle.BundleName;
options.SetURL(mainURL, mainURL); options.SetURL(mainURL, mainURL);
var downloader = new DownloadVirtualBundleOperation(this, bundle, options); var downloader = new DownloadVirtualBundleOperation(this, options);
return downloader; return downloader;
} }
public virtual FSLoadBundleOperation LoadBundleFile(PackageBundle bundle) public virtual FSLoadBundleOperation LoadBundleAsync(LoadBundleOptions options)
{ {
if (bundle.BundleType == (int)EBuildBundleType.VirtualBundle) PackageBundle bundle = options.Bundle;
if (bundle.BundleType == (int)EBundleType.VirtualBundle)
{ {
var operation = new DEFSLoadBundleOperation(this, bundle); var operation = new DEFSLoadBundleOperation(this, bundle);
return operation; return operation;

View File

@@ -64,8 +64,8 @@ namespace YooAsset
{ {
if (_downloadFileOp == null) if (_downloadFileOp == null)
{ {
DownloadFileOptions options = new DownloadFileOptions(int.MaxValue); DownloadFileOptions options = new DownloadFileOptions(_bundle, int.MaxValue);
_downloadFileOp = _fileSystem.DownloadFileAsync(_bundle, options); _downloadFileOp = _fileSystem.DownloadFileAsync(options);
_downloadFileOp.StartOperation(); _downloadFileOp.StartOperation();
AddChildOperation(_downloadFileOp); AddChildOperation(_downloadFileOp);
} }

View File

@@ -25,7 +25,7 @@ namespace YooAsset
private ESteps _steps = ESteps.None; private ESteps _steps = ESteps.None;
internal DownloadVirtualBundleOperation(DefaultEditorFileSystem fileSystem, PackageBundle bundle, DownloadFileOptions options) : base(bundle) internal DownloadVirtualBundleOperation(DefaultEditorFileSystem fileSystem, DownloadFileOptions options) : base(options.Bundle)
{ {
_fileSystem = fileSystem; _fileSystem = fileSystem;
_options = options; _options = options;

View File

@@ -59,7 +59,7 @@ namespace YooAsset
if (_steps == ESteps.VerifyFileData) if (_steps == ESteps.VerifyFileData)
{ {
if (ManifestTools.VerifyManifestData(_fileData, _packageHash)) if (PackageManifestTools.VerifyManifestData(_fileData, _packageHash))
{ {
_steps = ESteps.LoadManifest; _steps = ESteps.LoadManifest;
} }

View File

@@ -61,12 +61,12 @@ namespace YooAsset
/// <summary> /// <summary>
/// 自定义参数:解密服务接口的实例类 /// 自定义参数:解密服务接口的实例类
/// </summary> /// </summary>
public IWebDecryptionServices DecryptionServices { private set; get; } public IWebBundleDecryptionServices BundleDecryptionServices { private set; get; }
/// <summary> /// <summary>
/// 自定义参数:资源清单服务类 /// 自定义参数:资源清单服务类
/// </summary> /// </summary>
public IManifestRestoreServices ManifestServices { private set; get; } public IManifestRestoreServices ManifestRestoreServices { private set; get; }
#endregion #endregion
@@ -88,18 +88,19 @@ namespace YooAsset
var operation = new DWRFSLoadPackageManifestOperation(this, options.PackageVersion, options.Timeout); var operation = new DWRFSLoadPackageManifestOperation(this, options.PackageVersion, options.Timeout);
return operation; return operation;
} }
public virtual FSClearCacheFilesOperation ClearCacheFilesAsync(PackageManifest manifest, ClearCacheFilesOptions options) public virtual FSClearCacheFilesOperation ClearCacheFilesAsync(ClearCacheFilesOptions options)
{ {
var operation = new FSClearCacheFilesCompleteOperation(); var operation = new FSClearCacheFilesCompleteOperation();
return operation; return operation;
} }
public virtual FSDownloadFileOperation DownloadFileAsync(PackageBundle bundle, DownloadFileOptions options) public virtual FSDownloadFileOperation DownloadFileAsync(DownloadFileOptions options)
{ {
throw new System.NotImplementedException(); throw new System.NotImplementedException();
} }
public virtual FSLoadBundleOperation LoadBundleFile(PackageBundle bundle) public virtual FSLoadBundleOperation LoadBundleAsync(LoadBundleOptions options)
{ {
if (bundle.BundleType == (int)EBuildBundleType.AssetBundle) PackageBundle bundle = options.Bundle;
if (bundle.BundleType == (int)EBundleType.AssetBundle)
{ {
var operation = new DWRFSLoadAssetBundleOperation(this, bundle); var operation = new DWRFSLoadAssetBundleOperation(this, bundle);
return operation; return operation;
@@ -130,13 +131,13 @@ namespace YooAsset
{ {
RemoteServices = (IRemoteServices)value; RemoteServices = (IRemoteServices)value;
} }
else if (name == FileSystemParametersDefine.DECRYPTION_SERVICES) else if (name == FileSystemParametersDefine.BUNDLE_DECRYPTION_SERVICES)
{ {
DecryptionServices = (IWebDecryptionServices)value; BundleDecryptionServices = (IWebBundleDecryptionServices)value;
} }
else if (name == FileSystemParametersDefine.MANIFEST_SERVICES) else if (name == FileSystemParametersDefine.MANIFEST_RESTORE_SERVICES)
{ {
ManifestServices = (IManifestRestoreServices)value; ManifestRestoreServices = (IManifestRestoreServices)value;
} }
else else
{ {

View File

@@ -36,18 +36,18 @@ namespace YooAsset
{ {
string mainURL = _fileSystem.RemoteServices.GetRemoteMainURL(_bundle.FileName); string mainURL = _fileSystem.RemoteServices.GetRemoteMainURL(_bundle.FileName);
string fallbackURL = _fileSystem.RemoteServices.GetRemoteFallbackURL(_bundle.FileName); string fallbackURL = _fileSystem.RemoteServices.GetRemoteFallbackURL(_bundle.FileName);
DownloadFileOptions options = new DownloadFileOptions(int.MaxValue); DownloadFileOptions options = new DownloadFileOptions(_bundle, int.MaxValue);
options.SetURL(mainURL, fallbackURL); options.SetURL(mainURL, fallbackURL);
if (_bundle.Encrypted) if (_bundle.Encrypted)
{ {
_loadWebAssetBundleOp = new LoadWebEncryptAssetBundleOperation(_bundle, options, _fileSystem.DecryptionServices, _fileSystem.DownloadBackend); _loadWebAssetBundleOp = new LoadWebEncryptAssetBundleOperation(options, _fileSystem.BundleDecryptionServices, _fileSystem.DownloadBackend);
_loadWebAssetBundleOp.StartOperation(); _loadWebAssetBundleOp.StartOperation();
AddChildOperation(_loadWebAssetBundleOp); AddChildOperation(_loadWebAssetBundleOp);
} }
else else
{ {
_loadWebAssetBundleOp = new LoadWebNormalAssetBundleOperation(_bundle, options, _fileSystem.DisableUnityWebCache, _fileSystem.DownloadBackend); _loadWebAssetBundleOp = new LoadWebNormalAssetBundleOperation(options, _fileSystem.DisableUnityWebCache, _fileSystem.DownloadBackend);
_loadWebAssetBundleOp.StartOperation(); _loadWebAssetBundleOp.StartOperation();
AddChildOperation(_loadWebAssetBundleOp); AddChildOperation(_loadWebAssetBundleOp);
} }

View File

@@ -65,7 +65,7 @@ namespace YooAsset
{ {
string packageHash = _requestWebPackageHashOp.PackageHash; string packageHash = _requestWebPackageHashOp.PackageHash;
string packageName = _fileSystem.PackageName; string packageName = _fileSystem.PackageName;
var manifestServices = _fileSystem.ManifestServices; var manifestServices = _fileSystem.ManifestRestoreServices;
var remoteServices = _fileSystem.RemoteServices; var remoteServices = _fileSystem.RemoteServices;
var downloadBackend = _fileSystem.DownloadBackend; var downloadBackend = _fileSystem.DownloadBackend;
_loadWebPackageManifestOp = new LoadWebPackageManifestOperation(manifestServices, remoteServices, downloadBackend, packageName, _packageVersion, packageHash, _timeout); _loadWebPackageManifestOp = new LoadWebPackageManifestOperation(manifestServices, remoteServices, downloadBackend, packageName, _packageVersion, packageHash, _timeout);

View File

@@ -70,12 +70,12 @@ namespace YooAsset
/// <summary> /// <summary>
/// 自定义参数:解密服务接口的实例类 /// 自定义参数:解密服务接口的实例类
/// </summary> /// </summary>
public IWebDecryptionServices DecryptionServices { private set; get; } public IWebBundleDecryptionServices BundleDecryptionServices { private set; get; }
/// <summary> /// <summary>
/// 自定义参数:资源清单服务类 /// 自定义参数:资源清单服务类
/// </summary> /// </summary>
public IManifestRestoreServices ManifestServices { private set; get; } public IManifestRestoreServices ManifestRestoreServices { private set; get; }
#endregion #endregion
@@ -97,18 +97,19 @@ namespace YooAsset
var operation = new DWSFSLoadPackageManifestOperation(this, options.PackageVersion, options.Timeout); var operation = new DWSFSLoadPackageManifestOperation(this, options.PackageVersion, options.Timeout);
return operation; return operation;
} }
public virtual FSClearCacheFilesOperation ClearCacheFilesAsync(PackageManifest manifest, ClearCacheFilesOptions options) public virtual FSClearCacheFilesOperation ClearCacheFilesAsync(ClearCacheFilesOptions options)
{ {
var operation = new FSClearCacheFilesCompleteOperation(); var operation = new FSClearCacheFilesCompleteOperation();
return operation; return operation;
} }
public virtual FSDownloadFileOperation DownloadFileAsync(PackageBundle bundle, DownloadFileOptions options) public virtual FSDownloadFileOperation DownloadFileAsync(DownloadFileOptions options)
{ {
throw new System.NotImplementedException(); throw new System.NotImplementedException();
} }
public virtual FSLoadBundleOperation LoadBundleFile(PackageBundle bundle) public virtual FSLoadBundleOperation LoadBundleAsync(LoadBundleOptions options)
{ {
if (bundle.BundleType == (int)EBuildBundleType.AssetBundle) PackageBundle bundle = options.Bundle;
if (bundle.BundleType == (int)EBundleType.AssetBundle)
{ {
var operation = new DWSFSLoadAssetBundleOperation(this, bundle); var operation = new DWSFSLoadAssetBundleOperation(this, bundle);
return operation; return operation;
@@ -135,13 +136,13 @@ namespace YooAsset
{ {
DisableUnityWebCache = Convert.ToBoolean(value); DisableUnityWebCache = Convert.ToBoolean(value);
} }
else if (name == FileSystemParametersDefine.DECRYPTION_SERVICES) else if (name == FileSystemParametersDefine.BUNDLE_DECRYPTION_SERVICES)
{ {
DecryptionServices = (IWebDecryptionServices)value; BundleDecryptionServices = (IWebBundleDecryptionServices)value;
} }
else if (name == FileSystemParametersDefine.MANIFEST_SERVICES) else if (name == FileSystemParametersDefine.MANIFEST_RESTORE_SERVICES)
{ {
ManifestServices = (IManifestRestoreServices)value; ManifestRestoreServices = (IManifestRestoreServices)value;
} }
else else
{ {

View File

@@ -36,18 +36,18 @@ namespace YooAsset
{ {
string fileLoadPath = _fileSystem.GetWebFileLoadPath(_bundle); string fileLoadPath = _fileSystem.GetWebFileLoadPath(_bundle);
string mainURL = DownloadSystemHelper.ConvertToWWWPath(fileLoadPath); string mainURL = DownloadSystemHelper.ConvertToWWWPath(fileLoadPath);
DownloadFileOptions options = new DownloadFileOptions(int.MaxValue); DownloadFileOptions options = new DownloadFileOptions(_bundle, int.MaxValue);
options.SetURL(mainURL, mainURL); options.SetURL(mainURL, mainURL);
if (_bundle.Encrypted) if (_bundle.Encrypted)
{ {
_loadWebAssetBundleOp = new LoadWebEncryptAssetBundleOperation(_bundle, options, _fileSystem.DecryptionServices, _fileSystem.DownloadBackend); _loadWebAssetBundleOp = new LoadWebEncryptAssetBundleOperation(options, _fileSystem.BundleDecryptionServices, _fileSystem.DownloadBackend);
_loadWebAssetBundleOp.StartOperation(); _loadWebAssetBundleOp.StartOperation();
AddChildOperation(_loadWebAssetBundleOp); AddChildOperation(_loadWebAssetBundleOp);
} }
else else
{ {
_loadWebAssetBundleOp = new LoadWebNormalAssetBundleOperation(_bundle, options, _fileSystem.DisableUnityWebCache, _fileSystem.DownloadBackend); _loadWebAssetBundleOp = new LoadWebNormalAssetBundleOperation(options, _fileSystem.DisableUnityWebCache, _fileSystem.DownloadBackend);
_loadWebAssetBundleOp.StartOperation(); _loadWebAssetBundleOp.StartOperation();
AddChildOperation(_loadWebAssetBundleOp); AddChildOperation(_loadWebAssetBundleOp);
} }

View File

@@ -61,7 +61,7 @@ namespace YooAsset
{ {
try try
{ {
var catalog = CatalogTools.DeserializeFromBinary(_webDataRequestOp.Result); var catalog = CatalogFileHelper.DeserializeFromBinary(_webDataRequestOp.Result);
if (catalog.PackageName != _fileSystem.PackageName) if (catalog.PackageName != _fileSystem.PackageName)
{ {
_steps = ESteps.Done; _steps = ESteps.Done;

View File

@@ -70,7 +70,7 @@ namespace YooAsset
if (_steps == ESteps.VerifyFileData) if (_steps == ESteps.VerifyFileData)
{ {
if (ManifestTools.VerifyManifestData(_webDataRequestOp.Result, _packageHash)) if (PackageManifestTools.VerifyManifestData(_webDataRequestOp.Result, _packageHash))
{ {
_steps = ESteps.LoadManifest; _steps = ESteps.LoadManifest;
} }
@@ -86,7 +86,7 @@ namespace YooAsset
{ {
if (_deserializer == null) if (_deserializer == null)
{ {
_deserializer = new DeserializeManifestOperation(_fileSystem.ManifestServices, _webDataRequestOp.Result); _deserializer = new DeserializeManifestOperation(_fileSystem.ManifestRestoreServices, _webDataRequestOp.Result);
_deserializer.StartOperation(); _deserializer.StartOperation();
AddChildOperation(_deserializer); AddChildOperation(_deserializer);
} }

View File

@@ -83,11 +83,11 @@ namespace YooAsset
/// </summary> /// </summary>
/// <param name="decryptionServices">加密文件解密服务类</param> /// <param name="decryptionServices">加密文件解密服务类</param>
/// <param name="packageRoot">文件系统的根目录</param> /// <param name="packageRoot">文件系统的根目录</param>
public static FileSystemParameters CreateDefaultBuildinFileSystemParameters(IDecryptionServices decryptionServices = null, string packageRoot = null) public static FileSystemParameters CreateDefaultBuildinFileSystemParameters(IBundleDecryptionServices decryptionServices = null, string packageRoot = null)
{ {
string fileSystemClass = typeof(DefaultBuildinFileSystem).FullName; string fileSystemClass = typeof(DefaultBuildinFileSystem).FullName;
var fileSystemParams = new FileSystemParameters(fileSystemClass, packageRoot); var fileSystemParams = new FileSystemParameters(fileSystemClass, packageRoot);
fileSystemParams.AddParameter(FileSystemParametersDefine.DECRYPTION_SERVICES, decryptionServices); fileSystemParams.AddParameter(FileSystemParametersDefine.BUNDLE_DECRYPTION_SERVICES, decryptionServices);
return fileSystemParams; return fileSystemParams;
} }
@@ -97,12 +97,12 @@ namespace YooAsset
/// <param name="remoteServices">远端资源地址查询服务类</param> /// <param name="remoteServices">远端资源地址查询服务类</param>
/// <param name="decryptionServices">加密文件解密服务类</param> /// <param name="decryptionServices">加密文件解密服务类</param>
/// <param name="packageRoot">文件系统的根目录</param> /// <param name="packageRoot">文件系统的根目录</param>
public static FileSystemParameters CreateDefaultCacheFileSystemParameters(IRemoteServices remoteServices, IDecryptionServices decryptionServices = null, string packageRoot = null) public static FileSystemParameters CreateDefaultCacheFileSystemParameters(IRemoteServices remoteServices, IBundleDecryptionServices decryptionServices = null, string packageRoot = null)
{ {
string fileSystemClass = typeof(DefaultCacheFileSystem).FullName; string fileSystemClass = typeof(DefaultCacheFileSystem).FullName;
var fileSystemParams = new FileSystemParameters(fileSystemClass, packageRoot); var fileSystemParams = new FileSystemParameters(fileSystemClass, packageRoot);
fileSystemParams.AddParameter(FileSystemParametersDefine.REMOTE_SERVICES, remoteServices); fileSystemParams.AddParameter(FileSystemParametersDefine.REMOTE_SERVICES, remoteServices);
fileSystemParams.AddParameter(FileSystemParametersDefine.DECRYPTION_SERVICES, decryptionServices); fileSystemParams.AddParameter(FileSystemParametersDefine.BUNDLE_DECRYPTION_SERVICES, decryptionServices);
return fileSystemParams; return fileSystemParams;
} }
@@ -111,11 +111,11 @@ namespace YooAsset
/// </summary> /// </summary>
/// <param name="decryptionServices">加密文件解密服务类</param> /// <param name="decryptionServices">加密文件解密服务类</param>
/// <param name="disableUnityWebCache">禁用Unity的网络缓存</param> /// <param name="disableUnityWebCache">禁用Unity的网络缓存</param>
public static FileSystemParameters CreateDefaultWebServerFileSystemParameters(IWebDecryptionServices decryptionServices = null, bool disableUnityWebCache = false) public static FileSystemParameters CreateDefaultWebServerFileSystemParameters(IWebBundleDecryptionServices decryptionServices = null, bool disableUnityWebCache = false)
{ {
string fileSystemClass = typeof(DefaultWebServerFileSystem).FullName; string fileSystemClass = typeof(DefaultWebServerFileSystem).FullName;
var fileSystemParams = new FileSystemParameters(fileSystemClass, null); var fileSystemParams = new FileSystemParameters(fileSystemClass, null);
fileSystemParams.AddParameter(FileSystemParametersDefine.DECRYPTION_SERVICES, decryptionServices); fileSystemParams.AddParameter(FileSystemParametersDefine.BUNDLE_DECRYPTION_SERVICES, decryptionServices);
fileSystemParams.AddParameter(FileSystemParametersDefine.DISABLE_UNITY_WEB_CACHE, disableUnityWebCache); fileSystemParams.AddParameter(FileSystemParametersDefine.DISABLE_UNITY_WEB_CACHE, disableUnityWebCache);
return fileSystemParams; return fileSystemParams;
} }
@@ -126,12 +126,12 @@ namespace YooAsset
/// <param name="remoteServices">远端资源地址查询服务类</param> /// <param name="remoteServices">远端资源地址查询服务类</param>
/// <param name="decryptionServices">加密文件解密服务类</param> /// <param name="decryptionServices">加密文件解密服务类</param>
/// <param name="disableUnityWebCache">禁用Unity的网络缓存</param> /// <param name="disableUnityWebCache">禁用Unity的网络缓存</param>
public static FileSystemParameters CreateDefaultWebRemoteFileSystemParameters(IRemoteServices remoteServices, IWebDecryptionServices decryptionServices = null, bool disableUnityWebCache = false) public static FileSystemParameters CreateDefaultWebRemoteFileSystemParameters(IRemoteServices remoteServices, IWebBundleDecryptionServices decryptionServices = null, bool disableUnityWebCache = false)
{ {
string fileSystemClass = typeof(DefaultWebRemoteFileSystem).FullName; string fileSystemClass = typeof(DefaultWebRemoteFileSystem).FullName;
var fileSystemParams = new FileSystemParameters(fileSystemClass, null); var fileSystemParams = new FileSystemParameters(fileSystemClass, null);
fileSystemParams.AddParameter(FileSystemParametersDefine.REMOTE_SERVICES, remoteServices); fileSystemParams.AddParameter(FileSystemParametersDefine.REMOTE_SERVICES, remoteServices);
fileSystemParams.AddParameter(FileSystemParametersDefine.DECRYPTION_SERVICES, decryptionServices); fileSystemParams.AddParameter(FileSystemParametersDefine.BUNDLE_DECRYPTION_SERVICES, decryptionServices);
fileSystemParams.AddParameter(FileSystemParametersDefine.DISABLE_UNITY_WEB_CACHE, disableUnityWebCache); fileSystemParams.AddParameter(FileSystemParametersDefine.DISABLE_UNITY_WEB_CACHE, disableUnityWebCache);
return fileSystemParams; return fileSystemParams;
} }

View File

@@ -7,102 +7,127 @@ namespace YooAsset
/// 初始化的时候缓存文件校验级别 <see cref=EFileVerifyLevel> /// 初始化的时候缓存文件校验级别 <see cref=EFileVerifyLevel>
/// </summary> /// </summary>
public const string FILE_VERIFY_LEVEL = "FILE_VERIFY_LEVEL"; public const string FILE_VERIFY_LEVEL = "FILE_VERIFY_LEVEL";
/// <summary> /// <summary>
/// 初始化的时候缓存文件校验最大并发数 <see cref=int> /// 初始化的时候缓存文件校验最大并发数 <see cref=int>
/// </summary> /// </summary>
public const string FILE_VERIFY_MAX_CONCURRENCY = "FILE_VERIFY_MAX_CONCURRENCY"; public const string FILE_VERIFY_MAX_CONCURRENCY = "FILE_VERIFY_MAX_CONCURRENCY";
/// <summary> /// <summary>
/// 覆盖安装缓存清理模式 <see cref=EOverwriteInstallClearMode> /// 覆盖安装缓存清理模式 <see cref=EOverwriteInstallClearMode>
/// </summary> /// </summary>
public const string INSTALL_CLEAR_MODE = "INSTALL_CLEAR_MODE"; public const string INSTALL_CLEAR_MODE = "INSTALL_CLEAR_MODE";
/// <summary> /// <summary>
/// 远端资源地址查询服务类 <see cref=IRemoteServices> /// 远端资源地址查询服务类 <see cref=IRemoteServices>
/// </summary> /// </summary>
public const string REMOTE_SERVICES = "REMOTE_SERVICES"; public const string REMOTE_SERVICES = "REMOTE_SERVICES";
/// <summary> /// <summary>
/// 解密服务接口的实例类 <see cref=IDecryptionServices> /// 解密服务接口的实例类 <see cref=IBundleDecryptionServices>
/// </summary> /// </summary>
public const string DECRYPTION_SERVICES = "DECRYPTION_SERVICES"; public const string BUNDLE_DECRYPTION_SERVICES = "BUNDLE_DECRYPTION_SERVICES";
/// <summary> /// <summary>
/// 资源清单服务类 <see cref=IManifestRestoreServices> /// 资源清单服务类 <see cref=IManifestRestoreServices>
/// </summary> /// </summary>
public const string MANIFEST_SERVICES = "MANIFEST_SERVICES"; public const string MANIFEST_RESTORE_SERVICES = "MANIFEST_RESTORE_SERVICES";
/// <summary> /// <summary>
/// 数据文件追加文件格式 <see cref=bool> /// 数据文件追加文件格式 <see cref=bool>
/// </summary> /// </summary>
public const string APPEND_FILE_EXTENSION = "APPEND_FILE_EXTENSION"; public const string APPEND_FILE_EXTENSION = "APPEND_FILE_EXTENSION";
/// <summary> /// <summary>
/// 禁用Catalog目录查询文件 <see cref=bool> /// 禁用Catalog目录查询文件 <see cref=bool>
/// </summary> /// </summary>
public const string DISABLE_CATALOG_FILE = "DISABLE_CATALOG_FILE"; public const string DISABLE_CATALOG_FILE = "DISABLE_CATALOG_FILE";
/// <summary> /// <summary>
/// 禁用Unity的网络缓存 <see cref=bool> /// 禁用Unity的网络缓存 <see cref=bool>
/// </summary> /// </summary>
public const string DISABLE_UNITY_WEB_CACHE = "DISABLE_UNITY_WEB_CACHE"; public const string DISABLE_UNITY_WEB_CACHE = "DISABLE_UNITY_WEB_CACHE";
/// <summary> /// <summary>
/// 禁用边玩边下机制 <see cref=bool> /// 禁用边玩边下机制 <see cref=bool>
/// </summary> /// </summary>
public const string DISABLE_ONDEMAND_DOWNLOAD = "DISABLE_ONDEMAND_DOWNLOAD"; public const string DISABLE_ONDEMAND_DOWNLOAD = "DISABLE_ONDEMAND_DOWNLOAD";
/// <summary> /// <summary>
/// UnityWebRequest 创建委托 <see cref=UnityWebRequestCreator> /// UnityWebRequest 创建委托 <see cref=UnityWebRequestCreator>
/// </summary> /// </summary>
public const string UNITY_WEB_REQUEST_CREATOR = "UNITY_WEB_REQUEST_CREATOR"; public const string UNITY_WEB_REQUEST_CREATOR = "UNITY_WEB_REQUEST_CREATOR";
/// <summary> /// <summary>
/// 下载后台接口 <see cref=IDownloadBackend> /// 下载后台接口 <see cref=IDownloadBackend>
/// </summary> /// </summary>
public const string DOWNLOAD_BACKEND = "DOWNLOAD_BACKEND"; public const string DOWNLOAD_BACKEND = "DOWNLOAD_BACKEND";
/// <summary> /// <summary>
/// 最大并发连接数 默认值10推荐范围 1-32 <see cref=int> /// 最大并发连接数 默认值10推荐范围 1-32 <see cref=int>
/// </summary> /// </summary>
public const string DOWNLOAD_MAX_CONCURRENCY = "DOWNLOAD_MAX_CONCURRENCY"; public const string DOWNLOAD_MAX_CONCURRENCY = "DOWNLOAD_MAX_CONCURRENCY";
/// <summary> /// <summary>
/// 每帧发起的最大请求数 默认值5推荐范围 1-10<see cref=int> /// 每帧发起的最大请求数 默认值5推荐范围 1-10<see cref=int>
/// </summary> /// </summary>
public const string DOWNLOAD_MAX_REQUEST_PER_FRAME = "DOWNLOAD_MAX_REQUEST_PER_FRAME"; public const string DOWNLOAD_MAX_REQUEST_PER_FRAME = "DOWNLOAD_MAX_REQUEST_PER_FRAME";
/// <summary> /// <summary>
/// 下载任务的看门狗机制监控时间 <see cref=int> /// 下载任务的看门狗机制监控时间 <see cref=int>
/// </summary> /// </summary>
public const string DOWNLOAD_WATCH_DOG_TIME = "DOWNLOAD_WATCH_DOG_TIME"; public const string DOWNLOAD_WATCH_DOG_TIME = "DOWNLOAD_WATCH_DOG_TIME";
/// <summary> /// <summary>
/// 启用断点续传的最小尺寸 <see cref=long> /// 启用断点续传的最小尺寸 <see cref=long>
/// </summary> /// </summary>
public const string RESUME_DOWNLOAD_MINMUM_SIZE = "RESUME_DOWNLOAD_MINMUM_SIZE"; public const string RESUME_DOWNLOAD_MINMUM_SIZE = "RESUME_DOWNLOAD_MINMUM_SIZE";
/// <summary> /// <summary>
/// 断点续传下载器关注的错误码 <see cref=List<long>> /// 断点续传下载器关注的错误码 <see cref=List<long>>
/// </summary> /// </summary>
public const string RESUME_DOWNLOAD_RESPONSE_CODES = "RESUME_DOWNLOAD_RESPONSE_CODES"; public const string RESUME_DOWNLOAD_RESPONSE_CODES = "RESUME_DOWNLOAD_RESPONSE_CODES";
/// <summary> /// <summary>
/// 模拟WebGL平台模式 <see cref=bool> /// 模拟WebGL平台模式 <see cref=bool>
/// </summary> /// </summary>
public const string VIRTUAL_WEBGL_MODE = "VIRTUAL_WEBGL_MODE"; public const string VIRTUAL_WEBGL_MODE = "VIRTUAL_WEBGL_MODE";
/// <summary> /// <summary>
/// 模拟虚拟下载模式 <see cref=bool> /// 模拟虚拟下载模式 <see cref=bool>
/// </summary> /// </summary>
public const string VIRTUAL_DOWNLOAD_MODE = "VIRTUAL_DOWNLOAD_MODE"; public const string VIRTUAL_DOWNLOAD_MODE = "VIRTUAL_DOWNLOAD_MODE";
/// <summary> /// <summary>
/// 模拟虚拟下载的网速(单位:字节) <see cref=int> /// 模拟虚拟下载的网速(单位:字节) <see cref=int>
/// </summary> /// </summary>
public const string VIRTUAL_DOWNLOAD_SPEED = "VIRTUAL_DOWNLOAD_SPEED"; public const string VIRTUAL_DOWNLOAD_SPEED = "VIRTUAL_DOWNLOAD_SPEED";
/// <summary> /// <summary>
/// 异步模拟加载最小帧数 <see cref=int> /// 异步模拟加载最小帧数 <see cref=int>
/// </summary> /// </summary>
public const string ASYNC_SIMULATE_MIN_FRAME = "ASYNC_SIMULATE_MIN_FRAME"; public const string ASYNC_SIMULATE_MIN_FRAME = "ASYNC_SIMULATE_MIN_FRAME";
/// <summary> /// <summary>
/// 异步模拟加载最大帧数 <see cref=int> /// 异步模拟加载最大帧数 <see cref=int>
/// </summary> /// </summary>
public const string ASYNC_SIMULATE_MAX_FRAME = "ASYNC_SIMULATE_MAX_FRAME"; public const string ASYNC_SIMULATE_MAX_FRAME = "ASYNC_SIMULATE_MAX_FRAME";
/// <summary> /// <summary>
/// 拷贝内置清单 <see cref=bool> /// 拷贝内置清单 <see cref=bool>
/// </summary> /// </summary>
public const string COPY_BUILDIN_PACKAGE_MANIFEST = "COPY_BUILDIN_PACKAGE_MANIFEST"; public const string COPY_BUILDIN_PACKAGE_MANIFEST = "COPY_BUILDIN_PACKAGE_MANIFEST";
/// <summary> /// <summary>
/// 拷贝内置清单的目标目录 <see cref=string> /// 拷贝内置清单的目标目录 <see cref=string>
/// </summary> /// </summary>
public const string COPY_BUILDIN_PACKAGE_MANIFEST_DEST_ROOT = "COPY_BUILDIN_PACKAGE_MANIFEST_DEST_ROOT"; public const string COPY_BUILDIN_PACKAGE_MANIFEST_DEST_ROOT = "COPY_BUILDIN_PACKAGE_MANIFEST_DEST_ROOT";
/// <summary> /// <summary>
/// 拷贝内置文件接口的实例类 <see cref=ICopyLocalFileServices> /// 拷贝内置文件接口的实例类 <see cref=ICopyLocalFileServices>
/// </summary> /// </summary>
public const string COPY_LOCAL_FILE_SERVICES = "COPY_LOCAL_FILE_SERVICES"; public const string COPY_LOCAL_FILE_SERVICES = "COPY_LOCAL_FILE_SERVICES";
/// <summary> /// <summary>
/// 解压文件系统的根目录 <see cref=string> /// 解压文件系统的根目录 <see cref=string>
/// </summary> /// </summary>

View File

@@ -37,17 +37,17 @@ namespace YooAsset
/// <summary> /// <summary>
/// 清理缓存文件 /// 清理缓存文件
/// </summary> /// </summary>
FSClearCacheFilesOperation ClearCacheFilesAsync(PackageManifest manifest, ClearCacheFilesOptions options); FSClearCacheFilesOperation ClearCacheFilesAsync(ClearCacheFilesOptions options);
/// <summary> /// <summary>
/// 下载Bundle文件 /// 下载Bundle文件
/// </summary> /// </summary>
FSDownloadFileOperation DownloadFileAsync(PackageBundle bundle, DownloadFileOptions options); FSDownloadFileOperation DownloadFileAsync(DownloadFileOptions options);
/// <summary> /// <summary>
/// 加载Bundle文件 /// 加载Bundle文件
/// </summary> /// </summary>
FSLoadBundleOperation LoadBundleFile(PackageBundle bundle); FSLoadBundleOperation LoadBundleAsync(LoadBundleOptions options);
/// <summary> /// <summary>

View File

@@ -1,54 +1,6 @@
 
namespace YooAsset namespace YooAsset
{ {
internal class DownloadFileOptions
{
/// <summary>
/// 失败后重试次数
/// </summary>
public readonly int FailedTryAgain;
/// <summary>
/// 主资源地址
/// </summary>
public string MainURL { private set; get; }
/// <summary>
/// 备用资源地址
/// </summary>
public string FallbackURL { private set; get; }
/// <summary>
/// 拷贝的本地文件路径
/// </summary>
public string ImportFilePath { set; get; }
public DownloadFileOptions(int failedTryAgain)
{
FailedTryAgain = failedTryAgain;
}
/// <summary>
/// 设置下载地址
/// </summary>
public void SetURL(string mainURL, string fallbackURL)
{
MainURL = mainURL;
FallbackURL = fallbackURL;
}
/// <summary>
/// 是否有效
/// </summary>
public bool IsValid()
{
if (string.IsNullOrEmpty(MainURL) || string.IsNullOrEmpty(FallbackURL))
return false;
return true;
}
}
internal abstract class FSDownloadFileOperation : AsyncOperationBase internal abstract class FSDownloadFileOperation : AsyncOperationBase
{ {
public PackageBundle Bundle { private set; get; } public PackageBundle Bundle { private set; get; }

View File

@@ -0,0 +1,60 @@

namespace YooAsset
{
internal struct DownloadFileOptions
{
/// <summary>
/// 资源包
/// </summary>
public readonly PackageBundle Bundle;
/// <summary>
/// 失败后重试次数
/// </summary>
public readonly int FailedTryAgain;
/// <summary>
/// 主资源地址
/// </summary>
public string MainURL { private set; get; }
/// <summary>
/// 备用资源地址
/// </summary>
public string FallbackURL { private set; get; }
/// <summary>
/// 拷贝的本地文件路径
/// </summary>
public string ImportFilePath { set; get; }
public DownloadFileOptions(PackageBundle bundle, int failedTryAgain)
{
Bundle = bundle;
FailedTryAgain = failedTryAgain;
MainURL = null;
FallbackURL = null;
ImportFilePath = null;
}
/// <summary>
/// 设置下载地址
/// </summary>
public void SetURL(string mainURL, string fallbackURL)
{
MainURL = mainURL;
FallbackURL = fallbackURL;
}
/// <summary>
/// 是否有效
/// </summary>
public bool IsValid()
{
if (string.IsNullOrEmpty(MainURL) || string.IsNullOrEmpty(FallbackURL))
return false;
return true;
}
}
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: 9143514bc9d4f3e4aa9a50a7cfb08d21 guid: ae6a979ad693ddf488c7a0f387c6ea76
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2

View File

@@ -0,0 +1,16 @@

namespace YooAsset
{
internal struct LoadBundleOptions
{
/// <summary>
/// 资源包
/// </summary>
public readonly PackageBundle Bundle;
public LoadBundleOptions(PackageBundle bundle)
{
Bundle = bundle;
}
}
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: 70420213c551a2b4b8cf014067699b07 guid: 3d4cf0ce3cf4c794fa2d40665d5f3147
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2

View File

@@ -13,9 +13,8 @@ namespace YooAsset
Done, Done,
} }
private readonly PackageBundle _bundle;
private readonly DownloadFileOptions _options; private readonly DownloadFileOptions _options;
private readonly IWebDecryptionServices _decryptionServices; private readonly IWebBundleDecryptionServices _decryptionServices;
private readonly IDownloadBackend _downloadBackend; private readonly IDownloadBackend _downloadBackend;
private IDownloadBytesRequest _unityWebDataRequestOp; private IDownloadBytesRequest _unityWebDataRequestOp;
@@ -24,9 +23,8 @@ namespace YooAsset
private int _failedTryAgain; private int _failedTryAgain;
private ESteps _steps = ESteps.None; private ESteps _steps = ESteps.None;
internal LoadWebEncryptAssetBundleOperation(PackageBundle bundle, DownloadFileOptions options, IWebDecryptionServices decryptionServices, IDownloadBackend downloadBackend) internal LoadWebEncryptAssetBundleOperation(DownloadFileOptions options, IWebBundleDecryptionServices decryptionServices, IDownloadBackend downloadBackend)
{ {
_bundle = bundle;
_options = options; _options = options;
_failedTryAgain = options.FailedTryAgain; _failedTryAgain = options.FailedTryAgain;
_decryptionServices = decryptionServices; _decryptionServices = decryptionServices;
@@ -48,7 +46,7 @@ namespace YooAsset
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
Error = $"The {nameof(IWebDecryptionServices)} is null !"; Error = $"The {nameof(IWebBundleDecryptionServices)} is null !";
YooLogger.Error(Error); YooLogger.Error(Error);
return; return;
} }
@@ -124,11 +122,11 @@ namespace YooAsset
/// </summary> /// </summary>
private AssetBundle LoadEncryptedAssetBundle(byte[] fileData) private AssetBundle LoadEncryptedAssetBundle(byte[] fileData)
{ {
var fileInfo = new WebDecryptFileInfo(); var fileInfo = new WebDecryptBundleInfo();
fileInfo.BundleName = _bundle.BundleName; fileInfo.BundleName = _options.Bundle.BundleName;
fileInfo.FileLoadCRC = _bundle.UnityCRC; fileInfo.FileLoadCRC = _options.Bundle.UnityCRC;
fileInfo.FileData = fileData; fileInfo.FileData = fileData;
var decryptResult = _decryptionServices.LoadAssetBundle(fileInfo); var decryptResult = _decryptionServices.LoadAssetBundleSync(fileInfo);
return decryptResult.Result; return decryptResult.Result;
} }

View File

@@ -13,7 +13,6 @@ namespace YooAsset
Done, Done,
} }
private readonly PackageBundle _bundle;
private readonly DownloadFileOptions _options; private readonly DownloadFileOptions _options;
private readonly bool _disableUnityWebCache; private readonly bool _disableUnityWebCache;
private readonly IDownloadBackend _downloadBackend; private readonly IDownloadBackend _downloadBackend;
@@ -25,9 +24,8 @@ namespace YooAsset
private ESteps _steps = ESteps.None; private ESteps _steps = ESteps.None;
internal LoadWebNormalAssetBundleOperation(PackageBundle bundle, DownloadFileOptions options, bool disableUnityWebCache, IDownloadBackend downloadBackend) internal LoadWebNormalAssetBundleOperation(DownloadFileOptions options, bool disableUnityWebCache, IDownloadBackend downloadBackend)
{ {
_bundle = bundle;
_options = options; _options = options;
_failedTryAgain = options.FailedTryAgain; _failedTryAgain = options.FailedTryAgain;
_disableUnityWebCache = disableUnityWebCache; _disableUnityWebCache = disableUnityWebCache;
@@ -46,7 +44,7 @@ namespace YooAsset
if (_steps == ESteps.CreateRequest) if (_steps == ESteps.CreateRequest)
{ {
string url = GetRequestURL(); string url = GetRequestURL();
var args = new DownloadAssetBundleRequestArgs(url, 0, 0, _disableUnityWebCache, _bundle.FileHash, _bundle.UnityCRC); var args = new DownloadAssetBundleRequestArgs(url, 0, 0, _disableUnityWebCache, _options.Bundle.FileHash, _options.Bundle.UnityCRC);
_unityAssetBundleRequestOp = _downloadBackend.CreateAssetBundleRequest(args); _unityAssetBundleRequestOp = _downloadBackend.CreateAssetBundleRequest(args);
_unityAssetBundleRequestOp.SendRequest(); _unityAssetBundleRequestOp.SendRequest();
_steps = ESteps.CheckRequest; _steps = ESteps.CheckRequest;

View File

@@ -80,7 +80,7 @@ internal class LoadWebPackageManifestOperation : AsyncOperationBase
if (_steps == ESteps.VerifyFileData) if (_steps == ESteps.VerifyFileData)
{ {
if (ManifestTools.VerifyManifestData(_webDataRequestOp.Result, _packageHash)) if (PackageManifestTools.VerifyManifestData(_webDataRequestOp.Result, _packageHash))
{ {
_steps = ESteps.LoadManifest; _steps = ESteps.LoadManifest;
} }

View File

@@ -1,9 +1,9 @@
 
namespace YooAsset namespace YooAsset
{ {
public class EditorSimulateModeHelper public class EditorSimulateBuildInvoker
{ {
public static PackageInvokeBuildResult SimulateBuild(string packageName) public static PackageInvokeBuildResult Build(string packageName)
{ {
var buildParam = new PackageInvokeBuildParam(packageName); var buildParam = new PackageInvokeBuildParam(packageName);
buildParam.BuildPipelineName = "EditorSimulateBuildPipeline"; buildParam.BuildPipelineName = "EditorSimulateBuildPipeline";

View File

@@ -76,62 +76,48 @@ namespace YooAsset
/// </summary> /// </summary>
public GameObject InstantiateSync() public GameObject InstantiateSync()
{ {
return InstantiateSyncInternal(false, Vector3.zero, Quaternion.identity, null, false); var options = new InstantiateOptions(true);
return InstantiateSyncInternal(options);
} }
public GameObject InstantiateSync(Transform parent)
/// <summary>
/// 同步初始化游戏对象
/// </summary>
public GameObject InstantiateSync(InstantiateOptions options)
{ {
return InstantiateSyncInternal(false, Vector3.zero, Quaternion.identity, parent, false); return InstantiateSyncInternal(options);
}
public GameObject InstantiateSync(Transform parent, bool worldPositionStays)
{
return InstantiateSyncInternal(false, Vector3.zero, Quaternion.identity, parent, worldPositionStays);
}
public GameObject InstantiateSync(Vector3 position, Quaternion rotation)
{
return InstantiateSyncInternal(true, position, rotation, null, false);
}
public GameObject InstantiateSync(Vector3 position, Quaternion rotation, Transform parent)
{
return InstantiateSyncInternal(true, position, rotation, parent, false);
} }
/// <summary> /// <summary>
/// 异步初始化游戏对象 /// 异步初始化游戏对象
/// </summary> /// </summary>
public InstantiateOperation InstantiateAsync(bool actived = true) public InstantiateOperation InstantiateAsync()
{ {
return InstantiateAsyncInternal(false, Vector3.zero, Quaternion.identity, null, false, actived); var options = new InstantiateOptions(true);
} return InstantiateAsyncInternal(options);
public InstantiateOperation InstantiateAsync(Transform parent, bool actived = true)
{
return InstantiateAsyncInternal(false, Vector3.zero, Quaternion.identity, parent, false, actived);
}
public InstantiateOperation InstantiateAsync(Transform parent, bool worldPositionStays, bool actived = true)
{
return InstantiateAsyncInternal(false, Vector3.zero, Quaternion.identity, parent, worldPositionStays, actived);
}
public InstantiateOperation InstantiateAsync(Vector3 position, Quaternion rotation, bool actived = true)
{
return InstantiateAsyncInternal(true, position, rotation, null, false, actived);
}
public InstantiateOperation InstantiateAsync(Vector3 position, Quaternion rotation, Transform parent, bool actived = true)
{
return InstantiateAsyncInternal(true, position, rotation, parent, false, actived);
} }
private GameObject InstantiateSyncInternal(bool setPositionAndRotation, Vector3 position, Quaternion rotation, Transform parent, bool worldPositionStays) /// <summary>
/// 异步初始化游戏对象
/// </summary>
public InstantiateOperation InstantiateAsync(InstantiateOptions options)
{
return InstantiateAsyncInternal(options);
}
private GameObject InstantiateSyncInternal(InstantiateOptions options)
{ {
if (IsValidWithWarning == false) if (IsValidWithWarning == false)
return null; return null;
if (Provider.AssetObject == null) if (Provider.AssetObject == null)
return null; return null;
return InstantiateOperation.InstantiateInternal(Provider.AssetObject, setPositionAndRotation, position, rotation, parent, worldPositionStays); return InstantiateOperation.InstantiateInternal(Provider.AssetObject, options);
} }
private InstantiateOperation InstantiateAsyncInternal(bool setPositionAndRotation, Vector3 position, Quaternion rotation, Transform parent, bool worldPositionStays, bool actived) private InstantiateOperation InstantiateAsyncInternal(InstantiateOptions options)
{ {
string packageName = GetAssetInfo().PackageName; string packageName = GetAssetInfo().PackageName;
InstantiateOperation operation = new InstantiateOperation(this, setPositionAndRotation, position, rotation, parent, worldPositionStays, actived); InstantiateOperation operation = new InstantiateOperation(this, options);
OperationSystem.StartOperation(packageName, operation); OperationSystem.StartOperation(packageName, operation);
return operation; return operation;
} }

View File

@@ -116,7 +116,7 @@ namespace YooAsset
/// 异步卸载场景对象 /// 异步卸载场景对象
/// 注意场景卸载成功后会自动释放该handle的引用计数 /// 注意场景卸载成功后会自动释放该handle的引用计数
/// </summary> /// </summary>
public UnloadSceneOperation UnloadAsync() public UnloadSceneOperation UnloadSceneAsync()
{ {
string packageName = GetAssetInfo().PackageName; string packageName = GetAssetInfo().PackageName;

View File

@@ -14,12 +14,7 @@ namespace YooAsset
} }
private readonly AssetHandle _handle; private readonly AssetHandle _handle;
private readonly bool _setPositionAndRotation; private readonly InstantiateOptions _options;
private readonly Vector3 _position;
private readonly Quaternion _rotation;
private readonly Transform _parent;
private readonly bool _worldPositionStays;
private readonly bool _actived;
private ESteps _steps = ESteps.None; private ESteps _steps = ESteps.None;
#if UNITY_2023_3_OR_NEWER #if UNITY_2023_3_OR_NEWER
@@ -32,16 +27,10 @@ namespace YooAsset
public GameObject Result = null; public GameObject Result = null;
internal InstantiateOperation(AssetHandle handle, bool setPositionAndRotation, Vector3 position, Quaternion rotation, internal InstantiateOperation(AssetHandle handle, InstantiateOptions options)
Transform parent, bool worldPositionStays, bool actived)
{ {
_handle = handle; _handle = handle;
_setPositionAndRotation = setPositionAndRotation; _options = options;
_position = position;
_rotation = rotation;
_parent = parent;
_worldPositionStays = worldPositionStays;
_actived = actived;
} }
internal override void InternalStart() internal override void InternalStart()
{ {
@@ -90,8 +79,8 @@ namespace YooAsset
if (_steps == ESteps.CloneSync) if (_steps == ESteps.CloneSync)
{ {
// 实例化游戏对象 // 实例化游戏对象
Result = InstantiateInternal(_handle.AssetObject, _setPositionAndRotation, _position, _rotation, _parent, _worldPositionStays); Result = InstantiateInternal(_handle.AssetObject, _options);
if (_actived == false) if (_options.Actived == false)
Result.SetActive(false); Result.SetActive(false);
_steps = ESteps.Done; _steps = ESteps.Done;
@@ -103,7 +92,7 @@ namespace YooAsset
{ {
if (_instantiateAsync == null) if (_instantiateAsync == null)
{ {
_instantiateAsync = InstantiateAsyncInternal(_handle.AssetObject, _setPositionAndRotation, _position, _rotation, _parent, _worldPositionStays); _instantiateAsync = InstantiateAsyncInternal(_handle.AssetObject, _options);
} }
if (IsWaitForAsyncComplete) if (IsWaitForAsyncComplete)
@@ -117,7 +106,7 @@ namespace YooAsset
Result = _instantiateAsync.Result[0] as GameObject; Result = _instantiateAsync.Result[0] as GameObject;
if (Result != null) if (Result != null)
{ {
if (_actived == false) if (_options.Actived == false)
Result.SetActive(false); Result.SetActive(false);
_steps = ESteps.Done; _steps = ESteps.Done;
@@ -165,22 +154,22 @@ namespace YooAsset
/// <summary> /// <summary>
/// 同步实例化 /// 同步实例化
/// </summary> /// </summary>
internal static GameObject InstantiateInternal(UnityEngine.Object assetObject, bool setPositionAndRotation, Vector3 position, Quaternion rotation, Transform parent, bool worldPositionStays) internal static GameObject InstantiateInternal(UnityEngine.Object assetObject, InstantiateOptions options)
{ {
if (assetObject == null) if (assetObject == null)
return null; return null;
if (setPositionAndRotation) if (options.SetPositionAndRotation)
{ {
if (parent != null) if (options.Parent != null)
return UnityEngine.Object.Instantiate(assetObject as GameObject, position, rotation, parent); return UnityEngine.Object.Instantiate(assetObject as GameObject, options.Position, options.Rotation, options.Parent);
else else
return UnityEngine.Object.Instantiate(assetObject as GameObject, position, rotation); return UnityEngine.Object.Instantiate(assetObject as GameObject, options.Position, options.Rotation);
} }
else else
{ {
if (parent != null) if (options.Parent != null)
return UnityEngine.Object.Instantiate(assetObject as GameObject, parent, worldPositionStays); return UnityEngine.Object.Instantiate(assetObject as GameObject, options.Parent, options.InWorldSpace);
else else
return UnityEngine.Object.Instantiate(assetObject as GameObject); return UnityEngine.Object.Instantiate(assetObject as GameObject);
} }
@@ -192,19 +181,19 @@ namespace YooAsset
/// 注意Unity2022.3.20f1及以上版本生效 /// 注意Unity2022.3.20f1及以上版本生效
/// https://docs.unity3d.com/2022.3/Documentation/ScriptReference/Object.InstantiateAsync.html /// https://docs.unity3d.com/2022.3/Documentation/ScriptReference/Object.InstantiateAsync.html
/// </summary> /// </summary>
internal static AsyncInstantiateOperation InstantiateAsyncInternal(UnityEngine.Object assetObject, bool setPositionAndRotation, Vector3 position, Quaternion rotation, Transform parent, bool worldPositionStays) internal static AsyncInstantiateOperation InstantiateAsyncInternal(UnityEngine.Object assetObject, InstantiateOptions options)
{ {
if (setPositionAndRotation) if (options.SetPositionAndRotation)
{ {
if (parent != null) if (options.Parent != null)
return UnityEngine.Object.InstantiateAsync(assetObject as GameObject, parent, position, rotation); return UnityEngine.Object.InstantiateAsync(assetObject as GameObject, options.Parent, options.Position, options.Rotation);
else else
return UnityEngine.Object.InstantiateAsync(assetObject as GameObject, position, rotation); return UnityEngine.Object.InstantiateAsync(assetObject as GameObject, options.Position, options.Rotation);
} }
else else
{ {
if (parent != null) if (options.Parent != null)
return UnityEngine.Object.InstantiateAsync(assetObject as GameObject, parent); return UnityEngine.Object.InstantiateAsync(assetObject as GameObject, options.Parent);
else else
return UnityEngine.Object.InstantiateAsync(assetObject as GameObject); return UnityEngine.Object.InstantiateAsync(assetObject as GameObject);
} }

View File

@@ -0,0 +1,77 @@
using UnityEngine;
namespace YooAsset
{
public struct InstantiateOptions
{
/// <summary>
/// 是否激活实例化对象
/// </summary>
public bool Actived { private set; get; }
/// <summary>
/// 将指定给新对象的父对象
/// </summary>
public Transform Parent { private set; get; }
/// <summary>
/// 分配父对象时, 定位新对象关系。
/// true 在世界空间中定位新对象。
/// false 相对于父对象来设置新对象。
/// </summary>
public bool InWorldSpace { private set; get; }
/// <summary>
/// 新对象的位置
/// </summary>
public Vector3 Position { private set; get; }
/// <summary>
/// 新对象的方向
/// </summary>
public Quaternion Rotation { private set; get; }
internal bool SetPositionAndRotation { private set; get; }
public InstantiateOptions(bool actived)
{
Actived = actived;
Parent = null;
InWorldSpace = false;
SetPositionAndRotation = false;
Position = Vector3.zero;
Rotation = Quaternion.identity;
}
public InstantiateOptions(bool actived, Transform parent, bool inWorldSpace)
{
Actived = actived;
Parent = parent;
InWorldSpace = inWorldSpace;
SetPositionAndRotation = false;
Position = Vector3.zero;
Rotation = Quaternion.identity;
}
public InstantiateOptions(bool actived, Transform parent, Vector3 position, Quaternion rotation)
{
Actived = actived;
Parent = parent;
InWorldSpace = false;
SetPositionAndRotation = true;
Position = position;
Rotation = rotation;
}
public InstantiateOptions(bool actived, Vector3 position, Quaternion rotation)
{
Actived = actived;
Parent = null;
InWorldSpace = false;
SetPositionAndRotation = true;
Position = position;
Rotation = rotation;
}
}
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: 4629f36c31a96214b9057827c6a283cf guid: 7432581e3bde71648adef94499c7a398
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2

View File

@@ -4,7 +4,7 @@ using System.Collections.Generic;
namespace YooAsset namespace YooAsset
{ {
internal class LoadBundleFileOperation : AsyncOperationBase internal class LoadBundleOperation : AsyncOperationBase
{ {
private enum ESteps private enum ESteps
{ {
@@ -51,7 +51,7 @@ namespace YooAsset
public BundleResult Result { set; get; } public BundleResult Result { set; get; }
internal LoadBundleFileOperation(ResourceManager resourceManager, BundleInfo bundleInfo) internal LoadBundleOperation(ResourceManager resourceManager, BundleInfo bundleInfo)
{ {
_resManager = resourceManager; _resManager = resourceManager;
LoadBundleInfo = bundleInfo; LoadBundleInfo = bundleInfo;
@@ -85,7 +85,7 @@ namespace YooAsset
{ {
// 统计计数增加 // 统计计数增加
_resManager.BundleLoadingCounter++; _resManager.BundleLoadingCounter++;
_loadBundleOp = LoadBundleInfo.LoadBundleFile(); _loadBundleOp = LoadBundleInfo.CreateBundleLoader();
_loadBundleOp.StartOperation(); _loadBundleOp.StartOperation();
AddChildOperation(_loadBundleOp); AddChildOperation(_loadBundleOp);
} }

View File

@@ -1,6 +1,5 @@
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine;
namespace YooAsset namespace YooAsset
{ {
@@ -14,19 +13,19 @@ namespace YooAsset
} }
private readonly ResourceManager _resManager; private readonly ResourceManager _resManager;
private readonly int _loopCount; private readonly UnloadUnusedAssetsOptions _options;
private int _loopCounter = 0; private int _loopCounter = 0;
private ESteps _steps = ESteps.None; private ESteps _steps = ESteps.None;
internal UnloadUnusedAssetsOperation(ResourceManager resourceManager, int loopCount) internal UnloadUnusedAssetsOperation(ResourceManager resourceManager, UnloadUnusedAssetsOptions options)
{ {
_resManager = resourceManager; _resManager = resourceManager;
_loopCount = loopCount; _options = options;
} }
internal override void InternalStart() internal override void InternalStart()
{ {
_steps = ESteps.UnloadUnused; _steps = ESteps.UnloadUnused;
_loopCounter = _loopCount; _loopCounter = _options.LoopCount;
} }
internal override void InternalUpdate() internal override void InternalUpdate()
{ {
@@ -57,7 +56,7 @@ namespace YooAsset
} }
internal override string InternalGetDesc() internal override string InternalGetDesc()
{ {
return $"LoopCount : {_loopCount}"; return $"LoopCount : {_options.LoopCount}";
} }
/// <summary> /// <summary>
@@ -65,7 +64,7 @@ namespace YooAsset
/// </summary> /// </summary>
private void LoopUnloadUnused() private void LoopUnloadUnused()
{ {
var removeList = new List<LoadBundleFileOperation>(_resManager.LoaderDic.Count); var removeList = new List<LoadBundleOperation>(_resManager.LoaderDic.Count);
// 注意:优先销毁资源提供者 // 注意:优先销毁资源提供者
foreach (var loader in _resManager.LoaderDic.Values) foreach (var loader in _resManager.LoaderDic.Values)

View File

@@ -0,0 +1,16 @@

namespace YooAsset
{
public struct UnloadUnusedAssetsOptions
{
/// <summary>
/// 循环迭代次数
/// </summary>
public int LoopCount { private set; get; }
public UnloadUnusedAssetsOptions(int loopCount)
{
LoopCount = loopCount;
}
}
}

View File

@@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: 2db868c2aaaee8e42a7f035117e747c4 guid: 33a033398461486429728fc87b8b9840
MonoImporter: MonoImporter:
externalObjects: {} externalObjects: {}
serializedVersion: 2 serializedVersion: 2

View File

@@ -80,8 +80,8 @@ namespace YooAsset
private ESteps _steps = ESteps.None; private ESteps _steps = ESteps.None;
protected readonly ResourceManager _resManager; protected readonly ResourceManager _resManager;
private readonly LoadBundleFileOperation _mainBundleLoader; private readonly LoadBundleOperation _mainBundleLoader;
private readonly List<LoadBundleFileOperation> _bundleLoaders = new List<LoadBundleFileOperation>(10); private readonly List<LoadBundleOperation> _bundleLoaders = new List<LoadBundleOperation>(10);
private readonly HashSet<HandleBase> _handles = new HashSet<HandleBase>(); private readonly HashSet<HandleBase> _handles = new HashSet<HandleBase>();
public ProviderOperation(ResourceManager manager, string providerGUID, AssetInfo assetInfo) public ProviderOperation(ResourceManager manager, string providerGUID, AssetInfo assetInfo)

View File

@@ -10,12 +10,12 @@ namespace YooAsset
internal class ResourceManager internal class ResourceManager
{ {
internal readonly Dictionary<string, ProviderOperation> ProviderDic = new Dictionary<string, ProviderOperation>(5000); internal readonly Dictionary<string, ProviderOperation> ProviderDic = new Dictionary<string, ProviderOperation>(5000);
internal readonly Dictionary<string, LoadBundleFileOperation> LoaderDic = new Dictionary<string, LoadBundleFileOperation>(5000); internal readonly Dictionary<string, LoadBundleOperation> LoaderDic = new Dictionary<string, LoadBundleOperation>(5000);
internal readonly List<SceneHandle> SceneHandles = new List<SceneHandle>(100); internal readonly List<SceneHandle> SceneHandles = new List<SceneHandle>(100);
private FileSystemHost _fileSystemHost;
private long _sceneCreateIndex = 0; private long _sceneCreateIndex = 0;
private IBundleQuery _bundleQuery;
private int _bundleLoadingMaxConcurrency; private int _bundleLoadingMaxConcurrency;
// 开发者配置选项 // 开发者配置选项
public bool AutoUnloadBundleWhenUnused { private set; get; } public bool AutoUnloadBundleWhenUnused { private set; get; }
public bool WebGLForceSyncLoadAsset { private set; get; } public bool WebGLForceSyncLoadAsset { private set; get; }
@@ -44,12 +44,12 @@ namespace YooAsset
/// <summary> /// <summary>
/// 初始化 /// 初始化
/// </summary> /// </summary>
public void Initialize(InitializePackageOptions options, IBundleQuery bundleServices) public void Initialize(InitializePackageOptions options, FileSystemHost host)
{ {
_fileSystemHost = host;
_bundleLoadingMaxConcurrency = options.BundleLoadingMaxConcurrency; _bundleLoadingMaxConcurrency = options.BundleLoadingMaxConcurrency;
AutoUnloadBundleWhenUnused = options.AutoUnloadBundleWhenUnused; AutoUnloadBundleWhenUnused = options.AutoUnloadBundleWhenUnused;
WebGLForceSyncLoadAsset = options.WebGLForceSyncLoadAsset; WebGLForceSyncLoadAsset = options.WebGLForceSyncLoadAsset;
_bundleQuery = bundleServices;
SceneManager.sceneUnloaded += OnSceneUnloaded; SceneManager.sceneUnloaded += OnSceneUnloaded;
} }
@@ -82,7 +82,7 @@ namespace YooAsset
loopCount--; loopCount--;
// 卸载主资源包加载器 // 卸载主资源包加载器
string mainBundleName = _bundleQuery.GetMainBundleName(assetInfo.Asset.BundleID); string mainBundleName = _fileSystemHost.GetMainBundleName(assetInfo.Asset.BundleID);
var mainLoader = TryGetBundleFileLoader(mainBundleName); var mainLoader = TryGetBundleFileLoader(mainBundleName);
if (mainLoader != null) if (mainLoader != null)
{ {
@@ -97,7 +97,7 @@ namespace YooAsset
// 卸载依赖资源包加载器 // 卸载依赖资源包加载器
foreach (var dependID in assetInfo.Asset.DependBundleIDs) foreach (var dependID in assetInfo.Asset.DependBundleIDs)
{ {
string dependBundleName = _bundleQuery.GetMainBundleName(dependID); string dependBundleName = _fileSystemHost.GetMainBundleName(dependID);
var dependLoader = TryGetBundleFileLoader(dependBundleName); var dependLoader = TryGetBundleFileLoader(dependBundleName);
if (dependLoader != null) if (dependLoader != null)
{ {
@@ -296,15 +296,15 @@ namespace YooAsset
return provider.CreateHandle<RawFileHandle>(); return provider.CreateHandle<RawFileHandle>();
} }
internal LoadBundleFileOperation CreateMainBundleFileLoader(AssetInfo assetInfo) internal LoadBundleOperation CreateMainBundleFileLoader(AssetInfo assetInfo)
{ {
BundleInfo bundleInfo = _bundleQuery.GetMainBundleInfo(assetInfo); BundleInfo bundleInfo = _fileSystemHost.GetMainBundleInfo(assetInfo);
return CreateBundleFileLoaderInternal(bundleInfo); return CreateBundleFileLoaderInternal(bundleInfo);
} }
internal List<LoadBundleFileOperation> CreateDependBundleFileLoaders(AssetInfo assetInfo) internal List<LoadBundleOperation> CreateDependBundleFileLoaders(AssetInfo assetInfo)
{ {
List<BundleInfo> bundleInfos = _bundleQuery.GetDependBundleInfos(assetInfo); List<BundleInfo> bundleInfos = _fileSystemHost.GetDependBundleInfos(assetInfo);
List<LoadBundleFileOperation> result = new List<LoadBundleFileOperation>(bundleInfos.Count); List<LoadBundleOperation> result = new List<LoadBundleOperation>(bundleInfos.Count);
foreach (var bundleInfo in bundleInfos) foreach (var bundleInfo in bundleInfos)
{ {
var bundleLoader = CreateBundleFileLoaderInternal(bundleInfo); var bundleLoader = CreateBundleFileLoaderInternal(bundleInfo);
@@ -321,7 +321,7 @@ namespace YooAsset
} }
internal bool CheckBundleDestroyed(int bundleID) internal bool CheckBundleDestroyed(int bundleID)
{ {
string bundleName = _bundleQuery.GetMainBundleName(bundleID); string bundleName = _fileSystemHost.GetMainBundleName(bundleID);
var bundleFileLoader = TryGetBundleFileLoader(bundleName); var bundleFileLoader = TryGetBundleFileLoader(bundleName);
if (bundleFileLoader == null) if (bundleFileLoader == null)
return true; return true;
@@ -329,7 +329,7 @@ namespace YooAsset
} }
internal bool CheckBundleReleasable(int bundleID) internal bool CheckBundleReleasable(int bundleID)
{ {
string bundleName = _bundleQuery.GetMainBundleName(bundleID); string bundleName = _fileSystemHost.GetMainBundleName(bundleID);
var bundleFileLoader = TryGetBundleFileLoader(bundleName); var bundleFileLoader = TryGetBundleFileLoader(bundleName);
if (bundleFileLoader == null) if (bundleFileLoader == null)
return true; return true;
@@ -344,22 +344,22 @@ namespace YooAsset
return BundleLoadingCounter >= _bundleLoadingMaxConcurrency; return BundleLoadingCounter >= _bundleLoadingMaxConcurrency;
} }
private LoadBundleFileOperation CreateBundleFileLoaderInternal(BundleInfo bundleInfo) private LoadBundleOperation CreateBundleFileLoaderInternal(BundleInfo bundleInfo)
{ {
// 如果加载器已经存在 // 如果加载器已经存在
string bundleName = bundleInfo.Bundle.BundleName; string bundleName = bundleInfo.Bundle.BundleName;
LoadBundleFileOperation loaderOperation = TryGetBundleFileLoader(bundleName); LoadBundleOperation loaderOperation = TryGetBundleFileLoader(bundleName);
if (loaderOperation != null) if (loaderOperation != null)
return loaderOperation; return loaderOperation;
// 新增下载需求 // 新增下载需求
loaderOperation = new LoadBundleFileOperation(this, bundleInfo); loaderOperation = new LoadBundleOperation(this, bundleInfo);
LoaderDic.Add(bundleName, loaderOperation); LoaderDic.Add(bundleName, loaderOperation);
return loaderOperation; return loaderOperation;
} }
private LoadBundleFileOperation TryGetBundleFileLoader(string bundleName) private LoadBundleOperation TryGetBundleFileLoader(string bundleName)
{ {
if (LoaderDic.TryGetValue(bundleName, out LoadBundleFileOperation value)) if (LoaderDic.TryGetValue(bundleName, out LoadBundleOperation value))
return value; return value;
else else
return null; return null;

View File

@@ -26,21 +26,22 @@ namespace YooAsset
} }
/// <summary> /// <summary>
/// 加载资源包 /// 创建加载器
/// </summary> /// </summary>
public FSLoadBundleOperation LoadBundleFile() public FSLoadBundleOperation CreateBundleLoader()
{ {
return _fileSystem.LoadBundleFile(Bundle); var options = new LoadBundleOptions(Bundle);
return _fileSystem.LoadBundleAsync(options);
} }
/// <summary> /// <summary>
/// 创建下载器 /// 创建下载器
/// </summary> /// </summary>
public FSDownloadFileOperation CreateDownloader(int failedTryAgain) public FSDownloadFileOperation CreateBundleDownloader(int failedTryAgain)
{ {
DownloadFileOptions options = new DownloadFileOptions(failedTryAgain); DownloadFileOptions options = new DownloadFileOptions(Bundle, failedTryAgain);
options.ImportFilePath = _importFilePath; options.ImportFilePath = _importFilePath;
return _fileSystem.DownloadFileAsync(Bundle, options); return _fileSystem.DownloadFileAsync(options);
} }
/// <summary> /// <summary>

View File

@@ -1,7 +1,7 @@
 
namespace YooAsset namespace YooAsset
{ {
public enum EBuildBundleType public enum EBundleType
{ {
/// <summary> /// <summary>
/// 未知类型 /// 未知类型

View File

@@ -4,12 +4,18 @@ using System.Collections.Generic;
namespace YooAsset namespace YooAsset
{ {
internal class PlayModeImpl : IPlayMode, IBundleQuery internal class FileSystemHost
{ {
public readonly string PackageName; public readonly string PackageName;
public readonly List<IFileSystem> FileSystems = new List<IFileSystem>(10); public readonly List<IFileSystem> FileSystems = new List<IFileSystem>(10);
public PlayModeImpl(string packageName) /// <summary>
/// 当前激活的清单
/// </summary>
public PackageManifest ActiveManifest { set; get; }
public FileSystemHost(string packageName)
{ {
PackageName = packageName; PackageName = packageName;
} }
@@ -47,16 +53,10 @@ namespace YooAsset
return operation; return operation;
} }
#region IPlayMode接口
/// <summary>
/// 当前激活的清单
/// </summary>
public PackageManifest ActiveManifest { set; get; }
/// <summary> /// <summary>
/// 销毁文件系统 /// 销毁文件系统
/// </summary> /// </summary>
void IPlayMode.DestroyFileSystem() public void Destroy()
{ {
foreach (var fileSystem in FileSystems) foreach (var fileSystem in FileSystems)
{ {
@@ -65,92 +65,7 @@ namespace YooAsset
FileSystems.Clear(); FileSystems.Clear();
} }
/// <summary> #region
/// 向网络端请求最新的资源版本
/// </summary>
RequestPackageVersionOperation IPlayMode.RequestPackageVersionAsync(RequestPackageVersionOptions options)
{
var operation = new RequestPackageVersionImplOperation(this, options);
return operation;
}
/// <summary>
/// 向网络端请求并更新清单
/// </summary>
LoadPackageManifestOperation IPlayMode.LoadPackageManifestAsync(LoadPackageManifestOptions options)
{
var operation = new LoadPackageManifestOperation(this, options);
return operation;
}
/// <summary>
/// 预下载指定版本的包裹内容
/// </summary>
PreDownloadContentOperation IPlayMode.PreDownloadContentAsync(PreDownloadContentOptions options)
{
var operation = new PreDownloadContentOperation(this, options);
return operation;
}
/// <summary>
/// 清理缓存文件
/// </summary>
ClearCacheFilesOperation IPlayMode.ClearCacheFilesAsync(ClearCacheFilesOptions options)
{
var operation = new ClearCacheFilesOperation(this, options);
return operation;
}
// 下载相关
ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByAll(int downloadingMaxNumber, int failedTryAgain)
{
List<BundleInfo> downloadList = GetDownloadListByAll(ActiveManifest);
var operation = new ResourceDownloaderOperation(PackageName, downloadList, downloadingMaxNumber, failedTryAgain);
return operation;
}
ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByTags(string[] tags, int downloadingMaxNumber, int failedTryAgain)
{
List<BundleInfo> downloadList = GetDownloadListByTags(ActiveManifest, tags);
var operation = new ResourceDownloaderOperation(PackageName, downloadList, downloadingMaxNumber, failedTryAgain);
return operation;
}
ResourceDownloaderOperation IPlayMode.CreateResourceDownloaderByPaths(AssetInfo[] assetInfos, bool recursiveDownload, int downloadingMaxNumber, int failedTryAgain)
{
List<BundleInfo> downloadList = GetDownloadListByPaths(ActiveManifest, assetInfos, recursiveDownload);
var operation = new ResourceDownloaderOperation(PackageName, downloadList, downloadingMaxNumber, failedTryAgain);
return operation;
}
// 解压相关
ResourceUnpackerOperation IPlayMode.CreateResourceUnpackerByAll(int upackingMaxNumber, int failedTryAgain)
{
List<BundleInfo> unpcakList = GetUnpackListByAll(ActiveManifest);
var operation = new ResourceUnpackerOperation(PackageName, unpcakList, upackingMaxNumber, failedTryAgain);
return operation;
}
ResourceUnpackerOperation IPlayMode.CreateResourceUnpackerByTags(string[] tags, int upackingMaxNumber, int failedTryAgain)
{
List<BundleInfo> unpcakList = GetUnpackListByTags(ActiveManifest, tags);
var operation = new ResourceUnpackerOperation(PackageName, unpcakList, upackingMaxNumber, failedTryAgain);
return operation;
}
// 导入相关
ResourceImporterOperation IPlayMode.CreateResourceImporterByFilePaths(string[] filePaths, int importingMaxNumber, int failedTryAgain)
{
List<BundleInfo> importerList = GetImporterListByFilePaths(ActiveManifest, filePaths);
var operation = new ResourceImporterOperation(PackageName, importerList, importingMaxNumber, failedTryAgain);
return operation;
}
ResourceImporterOperation IPlayMode.CreateResourceImporterByFileInfos(ImportFileInfo[] fileInfos, int importingMaxNumber, int failedTryAgain)
{
List<BundleInfo> importerList = GetImporterListByFileInfos(ActiveManifest, fileInfos);
var operation = new ResourceImporterOperation(PackageName, importerList, importingMaxNumber, failedTryAgain);
return operation;
}
#endregion
#region IBundleQuery接口
private BundleInfo CreateBundleInfo(PackageBundle packageBundle) private BundleInfo CreateBundleInfo(PackageBundle packageBundle)
{ {
if (packageBundle == null) if (packageBundle == null)
@@ -165,7 +80,11 @@ namespace YooAsset
throw new YooFileSystemException($"Can not found belong file system : {packageBundle.BundleName}"); throw new YooFileSystemException($"Can not found belong file system : {packageBundle.BundleName}");
} }
BundleInfo IBundleQuery.GetMainBundleInfo(AssetInfo assetInfo)
/// <summary>
/// 获取主资源包信息
/// </summary>
public BundleInfo GetMainBundleInfo(AssetInfo assetInfo)
{ {
if (assetInfo == null || assetInfo.IsInvalid) if (assetInfo == null || assetInfo.IsInvalid)
throw new YooInternalException(); throw new YooInternalException();
@@ -174,7 +93,21 @@ namespace YooAsset
var packageBundle = ActiveManifest.GetMainPackageBundle(assetInfo.Asset); var packageBundle = ActiveManifest.GetMainPackageBundle(assetInfo.Asset);
return CreateBundleInfo(packageBundle); return CreateBundleInfo(packageBundle);
} }
List<BundleInfo> IBundleQuery.GetDependBundleInfos(AssetInfo assetInfo)
/// <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) if (assetInfo == null || assetInfo.IsInvalid)
throw new YooInternalException(); throw new YooInternalException();
@@ -199,45 +132,50 @@ namespace YooAsset
} }
return result; return result;
} }
string IBundleQuery.GetMainBundleName(int bundleID)
{
// 注意:如果清单里未找到资源包会抛出异常!
var packageBundle = ActiveManifest.GetMainPackageBundle(bundleID);
return packageBundle.BundleName;
}
#endregion #endregion
/// <summary> #region
/// 获取主文件系统 public ResourceDownloaderOperation CreateResourceDownloader(ResourceDownloaderOptions options)
/// 说明:文件系统列表里,最后一个属于主文件系统
/// </summary>
public IFileSystem GetMainFileSystem()
{ {
int count = FileSystems.Count; List<BundleInfo> downloadList;
if (count == 0) if (options.Tags == null)
return null; downloadList = GetDownloadListByAll(ActiveManifest);
return FileSystems[count - 1]; else
downloadList = GetDownloadListByTags(ActiveManifest, options.Tags);
var operation = new ResourceDownloaderOperation(PackageName, downloadList, options.MaximumConcurrency, options.FailedTryAgain);
return operation;
}
public ResourceDownloaderOperation CreateResourceDownloader(BundleDownloaderOptions options)
{
List<BundleInfo> downloadList;
if (options.AssetInfos == null)
downloadList = GetDownloadListByAll(ActiveManifest);
else
downloadList = GetDownloadListByAssetInfos(ActiveManifest, options.AssetInfos, options.DownloadBundleDependencies);
var operation = new ResourceDownloaderOperation(PackageName, downloadList, options.MaximumConcurrency, options.FailedTryAgain);
return operation;
}
public ResourceUnpackerOperation CreateResourceUnpacker(ResourceUnpackerOptions options)
{
List<BundleInfo> unpcakList;
if (options.Tags == null)
unpcakList = GetUnpackListByAll(ActiveManifest);
else
unpcakList = GetUnpackListByTags(ActiveManifest, 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);
var operation = new ResourceImporterOperation(PackageName, importerList, options.MaximumConcurrency, options.FailedTryAgain);
return operation;
} }
/// <summary> internal List<BundleInfo> GetDownloadListByAll(PackageManifest manifest)
/// 获取资源包所属文件系统
/// </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;
}
public List<BundleInfo> GetDownloadListByAll(PackageManifest manifest)
{ {
if (manifest == null) if (manifest == null)
return new List<BundleInfo>(); return new List<BundleInfo>();
@@ -257,7 +195,7 @@ namespace YooAsset
} }
return result; return result;
} }
public List<BundleInfo> GetDownloadListByTags(PackageManifest manifest, string[] tags) internal List<BundleInfo> GetDownloadListByTags(PackageManifest manifest, string[] tags)
{ {
if (manifest == null) if (manifest == null)
return new List<BundleInfo>(); return new List<BundleInfo>();
@@ -290,7 +228,7 @@ namespace YooAsset
} }
return result; return result;
} }
public List<BundleInfo> GetDownloadListByPaths(PackageManifest manifest, AssetInfo[] assetInfos, bool recursiveDownload) internal List<BundleInfo> GetDownloadListByAssetInfos(PackageManifest manifest, AssetInfo[] assetInfos, bool recursiveDownload)
{ {
if (manifest == null) if (manifest == null)
return new List<BundleInfo>(); return new List<BundleInfo>();
@@ -365,7 +303,7 @@ namespace YooAsset
} }
return result; return result;
} }
public List<BundleInfo> GetUnpackListByAll(PackageManifest manifest) internal List<BundleInfo> GetUnpackListByAll(PackageManifest manifest)
{ {
if (manifest == null) if (manifest == null)
return new List<BundleInfo>(); return new List<BundleInfo>();
@@ -385,7 +323,7 @@ namespace YooAsset
} }
return result; return result;
} }
public List<BundleInfo> GetUnpackListByTags(PackageManifest manifest, string[] tags) internal List<BundleInfo> GetUnpackListByTags(PackageManifest manifest, string[] tags)
{ {
if (manifest == null) if (manifest == null)
return new List<BundleInfo>(); return new List<BundleInfo>();
@@ -408,22 +346,7 @@ namespace YooAsset
} }
return result; return result;
} }
public List<BundleInfo> GetImporterListByFilePaths(PackageManifest manifest, string[] filePaths) internal List<BundleInfo> GetImporterListByBundleInfos(PackageManifest manifest, ImportBundleInfo[] fileInfos)
{
if (manifest == null)
return new List<BundleInfo>();
ImportFileInfo[] fileInfos = new ImportFileInfo[filePaths.Length];
for (int i = 0; i < filePaths.Length; i++)
{
ImportFileInfo fileInfo = new ImportFileInfo();
fileInfo.FilePath = filePaths[i];
fileInfos[i] = fileInfo;
}
return GetImporterListByFileInfos(manifest, fileInfos);
}
public List<BundleInfo> GetImporterListByFileInfos(PackageManifest manifest, ImportFileInfo[] fileInfos)
{ {
if (manifest == null) if (manifest == null)
return new List<BundleInfo>(); return new List<BundleInfo>();
@@ -477,5 +400,36 @@ namespace YooAsset
} }
return result; 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;
}
} }
} }

View File

@@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: e7f5776546411834d9ed949d54a6f241
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -1,23 +0,0 @@
using System.Collections;
using System.Collections.Generic;
namespace YooAsset
{
internal interface IBundleQuery
{
/// <summary>
/// 获取主资源包信息
/// </summary>
BundleInfo GetMainBundleInfo(AssetInfo assetInfo);
/// <summary>
/// 获取依赖的资源包信息集合
/// </summary>
List<BundleInfo> GetDependBundleInfos(AssetInfo assetPath);
/// <summary>
/// 获取主资源包名称
/// </summary>
string GetMainBundleName(int bundleID);
}
}

View File

@@ -1,49 +0,0 @@

namespace YooAsset
{
internal interface IPlayMode
{
/// <summary>
/// 当前激活的清单
/// </summary>
PackageManifest ActiveManifest { set; get; }
/// <summary>
/// 销毁文件系统
/// </summary>
void DestroyFileSystem();
/// <summary>
/// 请求最新的资源版本
/// </summary>
RequestPackageVersionOperation RequestPackageVersionAsync(RequestPackageVersionOptions options);
/// <summary>
/// 请求并加载资源清单
/// </summary>
LoadPackageManifestOperation LoadPackageManifestAsync(LoadPackageManifestOptions options);
/// <summary>
/// 预下载指定版本的包裹内容
/// </summary>
PreDownloadContentOperation PreDownloadContentAsync(PreDownloadContentOptions options);
/// <summary>
/// 清理缓存文件
/// </summary>
ClearCacheFilesOperation ClearCacheFilesAsync(ClearCacheFilesOptions options);
// 下载相关
ResourceDownloaderOperation CreateResourceDownloaderByAll(int downloadingMaxNumber, int failedTryAgain);
ResourceDownloaderOperation CreateResourceDownloaderByTags(string[] tags, int downloadingMaxNumber, int failedTryAgain);
ResourceDownloaderOperation CreateResourceDownloaderByPaths(AssetInfo[] assetInfos, bool recursiveDownload, int downloadingMaxNumber, int failedTryAgain);
// 解压相关
ResourceUnpackerOperation CreateResourceUnpackerByAll(int upackingMaxNumber, int failedTryAgain);
ResourceUnpackerOperation CreateResourceUnpackerByTags(string[] tags, int upackingMaxNumber, int failedTryAgain);
// 导入相关
ResourceImporterOperation CreateResourceImporterByFilePaths(string[] filePaths, int importingMaxNumber, int failedTryAgain);
ResourceImporterOperation CreateResourceImporterByFileInfos(ImportFileInfo[] fileInfos, int importingMaxNumber, int failedTryAgain);
}
}

View File

@@ -14,15 +14,15 @@ namespace YooAsset
Done, Done,
} }
private readonly PlayModeImpl _impl; private readonly FileSystemHost _host;
private readonly ClearCacheFilesOptions _options; private readonly ClearCacheFilesOptions _options;
private List<IFileSystem> _cloneList; private List<IFileSystem> _cloneList;
private FSClearCacheFilesOperation _clearCacheFilesOp; private FSClearCacheFilesOperation _clearCacheFilesOp;
private ESteps _steps = ESteps.None; private ESteps _steps = ESteps.None;
internal ClearCacheFilesOperation(PlayModeImpl impl, ClearCacheFilesOptions options) internal ClearCacheFilesOperation(FileSystemHost host, ClearCacheFilesOptions options)
{ {
_impl = impl; _host = host;
_options = options; _options = options;
} }
internal override void InternalStart() internal override void InternalStart()
@@ -36,7 +36,7 @@ namespace YooAsset
if (_steps == ESteps.Prepare) if (_steps == ESteps.Prepare)
{ {
var fileSytems = _impl.FileSystems; var fileSytems = _host.FileSystems;
if (fileSytems == null || fileSytems.Count == 0) if (fileSytems == null || fileSytems.Count == 0)
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
@@ -72,7 +72,7 @@ namespace YooAsset
var fileSystem = _cloneList[0]; var fileSystem = _cloneList[0];
_cloneList.RemoveAt(0); _cloneList.RemoveAt(0);
_clearCacheFilesOp = fileSystem.ClearCacheFilesAsync(_impl.ActiveManifest, _options); _clearCacheFilesOp = fileSystem.ClearCacheFilesAsync(_options);
_clearCacheFilesOp.StartOperation(); _clearCacheFilesOp.StartOperation();
AddChildOperation(_clearCacheFilesOp); AddChildOperation(_clearCacheFilesOp);
_steps = ESteps.CheckClearResult; _steps = ESteps.CheckClearResult;

View File

@@ -13,20 +13,28 @@ namespace YooAsset
/// </summary> /// </summary>
public object ClearParam { private set; get; } public object ClearParam { private set; get; }
/// <summary>
/// 资源清单
/// </summary>
internal PackageManifest Manifest { set; get; }
public ClearCacheFilesOptions(EFileClearMode clearMode) public ClearCacheFilesOptions(EFileClearMode clearMode)
{ {
ClearMode = clearMode.ToString(); ClearMode = clearMode.ToString();
ClearParam = null; ClearParam = null;
Manifest = null;
} }
public ClearCacheFilesOptions(EFileClearMode clearMode, object clearParam) public ClearCacheFilesOptions(EFileClearMode clearMode, object clearParam)
{ {
ClearMode = clearMode.ToString(); ClearMode = clearMode.ToString();
ClearParam = clearParam; ClearParam = clearParam;
Manifest = null;
} }
public ClearCacheFilesOptions(string clearMode, object clearParam) public ClearCacheFilesOptions(string clearMode, object clearParam)
{ {
ClearMode = clearMode; ClearMode = clearMode;
ClearParam = clearParam; ClearParam = clearParam;
Manifest = null;
} }
} }
} }

View File

@@ -0,0 +1,102 @@

namespace YooAsset
{
/// <summary>
/// 下载器结束
/// </summary>
public struct DownloaderFinishData
{
/// <summary>
/// 所属包裹名称
/// </summary>
public string PackageName;
/// <summary>
/// 是否成功
/// </summary>
public bool Succeed;
}
/// <summary>
/// 下载器相关的更新数据
/// </summary>
public struct DownloadUpdateData
{
/// <summary>
/// 所属包裹名称
/// </summary>
public string PackageName;
/// <summary>
/// 下载进度 (0-1f)
/// </summary>
public float Progress;
/// <summary>
/// 下载文件总数
/// </summary>
public int TotalDownloadCount;
/// <summary>
/// 当前完成的下载文件数量
/// </summary>
public int CurrentDownloadCount;
/// <summary>
/// 下载数据总大小(单位:字节)
/// </summary>
public long TotalDownloadBytes;
/// <summary>
/// 当前完成的下载数据大小(单位:字节)
/// </summary>
public long CurrentDownloadBytes;
}
/// <summary>
/// 下载器相关的错误数据
/// </summary>
public struct DownloadErrorData
{
/// <summary>
/// 所属包裹名称
/// </summary>
public string PackageName;
/// <summary>
/// 下载失败的文件名称
/// </summary>
public string FileName;
/// <summary>
/// 错误信息
/// </summary>
public string ErrorInfo;
}
/// <summary>
/// 下载器相关的文件数据
/// </summary>
public struct DownloadFileData
{
/// <summary>
/// 所属包裹名称
/// </summary>
public string PackageName;
/// <summary>
/// 资源包名称
/// </summary>
public string BundleName;
/// <summary>
/// 文件名称
/// </summary>
public string FileName;
/// <summary>
/// 文件大小
/// </summary>
public long FileSize;
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 0a798eb87a00a284189bb69a767d2c02
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -3,107 +3,6 @@ using System.Collections.Generic;
namespace YooAsset namespace YooAsset
{ {
#region
/// <summary>
/// 下载器结束
/// </summary>
public struct DownloaderFinishData
{
/// <summary>
/// 所属包裹名称
/// </summary>
public string PackageName;
/// <summary>
/// 是否成功
/// </summary>
public bool Succeed;
}
/// <summary>
/// 下载器相关的更新数据
/// </summary>
public struct DownloadUpdateData
{
/// <summary>
/// 所属包裹名称
/// </summary>
public string PackageName;
/// <summary>
/// 下载进度 (0-1f)
/// </summary>
public float Progress;
/// <summary>
/// 下载文件总数
/// </summary>
public int TotalDownloadCount;
/// <summary>
/// 当前完成的下载文件数量
/// </summary>
public int CurrentDownloadCount;
/// <summary>
/// 下载数据总大小(单位:字节)
/// </summary>
public long TotalDownloadBytes;
/// <summary>
/// 当前完成的下载数据大小(单位:字节)
/// </summary>
public long CurrentDownloadBytes;
}
/// <summary>
/// 下载器相关的错误数据
/// </summary>
public struct DownloadErrorData
{
/// <summary>
/// 所属包裹名称
/// </summary>
public string PackageName;
/// <summary>
/// 下载失败的文件名称
/// </summary>
public string FileName;
/// <summary>
/// 错误信息
/// </summary>
public string ErrorInfo;
}
/// <summary>
/// 下载器相关的文件数据
/// </summary>
public struct DownloadFileData
{
/// <summary>
/// 所属包裹名称
/// </summary>
public string PackageName;
/// <summary>
/// 资源包名称
/// </summary>
public string BundleName;
/// <summary>
/// 文件名称
/// </summary>
public string FileName;
/// <summary>
/// 文件大小
/// </summary>
public long FileSize;
}
#endregion
public abstract class DownloaderOperation : AsyncOperationBase public abstract class DownloaderOperation : AsyncOperationBase
{ {
private enum ESteps private enum ESteps
@@ -140,7 +39,7 @@ namespace YooAsset
#endregion #endregion
private readonly string _packageName; private readonly string _packageName;
private readonly int _downloadingMaxNumber; private readonly int _maximumConcurrency;
private readonly int _failedTryAgain; private readonly int _failedTryAgain;
private readonly List<BundleInfo> _bundleInfoList; private readonly List<BundleInfo> _bundleInfoList;
private readonly List<FSDownloadFileOperation> _downloaders = new List<FSDownloadFileOperation>(MAX_LOADER_COUNT); private readonly List<FSDownloadFileOperation> _downloaders = new List<FSDownloadFileOperation>(MAX_LOADER_COUNT);
@@ -203,11 +102,11 @@ namespace YooAsset
public DownloadFileBegin DownloadFileBeginCallback { set; get; } public DownloadFileBegin DownloadFileBeginCallback { set; get; }
internal DownloaderOperation(string packageName, List<BundleInfo> downloadList, int downloadingMaxNumber, int failedTryAgain) internal DownloaderOperation(string packageName, List<BundleInfo> downloadList, int maximumConcurrency, int failedTryAgain)
{ {
_packageName = packageName; _packageName = packageName;
_bundleInfoList = downloadList; _bundleInfoList = downloadList;
_downloadingMaxNumber = UnityEngine.Mathf.Clamp(downloadingMaxNumber, 1, MAX_LOADER_COUNT); ; _maximumConcurrency = UnityEngine.Mathf.Clamp(maximumConcurrency, 1, MAX_LOADER_COUNT); ;
_failedTryAgain = failedTryAgain; _failedTryAgain = failedTryAgain;
// 统计下载信息 // 统计下载信息
@@ -321,11 +220,11 @@ namespace YooAsset
if (_isPause) if (_isPause)
return; return;
if (_downloaders.Count < _downloadingMaxNumber) if (_downloaders.Count < _maximumConcurrency)
{ {
int index = _bundleInfoList.Count - 1; int index = _bundleInfoList.Count - 1;
var bundleInfo = _bundleInfoList[index]; var bundleInfo = _bundleInfoList[index];
var downloader = bundleInfo.CreateDownloader(_failedTryAgain); var downloader = bundleInfo.CreateBundleDownloader(_failedTryAgain);
downloader.StartOperation(); downloader.StartOperation();
this.AddChildOperation(downloader); this.AddChildOperation(downloader);
@@ -502,25 +401,25 @@ namespace YooAsset
public sealed class ResourceDownloaderOperation : DownloaderOperation public sealed class ResourceDownloaderOperation : DownloaderOperation
{ {
internal ResourceDownloaderOperation(string packageName, List<BundleInfo> downloadList, int downloadingMaxNumber, int failedTryAgain) internal ResourceDownloaderOperation(string packageName, List<BundleInfo> downloadList, int maximumConcurrency, int failedTryAgain)
: base(packageName, downloadList, downloadingMaxNumber, failedTryAgain) : base(packageName, downloadList, maximumConcurrency, failedTryAgain)
{ {
} }
/// <summary> /// <summary>
/// 创建空的下载器 /// 创建空的下载器
/// </summary> /// </summary>
internal static ResourceDownloaderOperation CreateEmptyDownloader(string packageName, int downloadingMaxNumber, int failedTryAgain) internal static ResourceDownloaderOperation CreateEmptyDownloader(string packageName, int maximumConcurrency, int failedTryAgain)
{ {
List<BundleInfo> downloadList = new List<BundleInfo>(); List<BundleInfo> downloadList = new List<BundleInfo>();
var operation = new ResourceDownloaderOperation(packageName, downloadList, downloadingMaxNumber, failedTryAgain); var operation = new ResourceDownloaderOperation(packageName, downloadList, maximumConcurrency, failedTryAgain);
return operation; return operation;
} }
} }
public sealed class ResourceUnpackerOperation : DownloaderOperation public sealed class ResourceUnpackerOperation : DownloaderOperation
{ {
internal ResourceUnpackerOperation(string packageName, List<BundleInfo> downloadList, int downloadingMaxNumber, int failedTryAgain) internal ResourceUnpackerOperation(string packageName, List<BundleInfo> downloadList, int maximumConcurrency, int failedTryAgain)
: base(packageName, downloadList, downloadingMaxNumber, failedTryAgain) : base(packageName, downloadList, maximumConcurrency, failedTryAgain)
{ {
} }
@@ -536,8 +435,8 @@ namespace YooAsset
} }
public sealed class ResourceImporterOperation : DownloaderOperation public sealed class ResourceImporterOperation : DownloaderOperation
{ {
internal ResourceImporterOperation(string packageName, List<BundleInfo> downloadList, int downloadingMaxNumber, int failedTryAgain) internal ResourceImporterOperation(string packageName, List<BundleInfo> downloadList, int maximumConcurrency, int failedTryAgain)
: base(packageName, downloadList, downloadingMaxNumber, failedTryAgain) : base(packageName, downloadList, maximumConcurrency, failedTryAgain)
{ {
} }

View File

@@ -0,0 +1,155 @@

namespace YooAsset
{
/// <summary>
/// 资源下载选项
/// </summary>
public struct BundleDownloaderOptions
{
/// <summary>
/// 最大并发数量
/// </summary>
public int MaximumConcurrency { private set; get; }
/// <summary>
/// 失败后的重试次数
/// </summary>
public int FailedTryAgain { private set; get; }
/// <summary>
/// 下载资源对象所属资源包内所有资源对象依赖的资源包
/// </summary>
public bool DownloadBundleDependencies { private set; get; }
/// <summary>
/// 资源信息列表
/// 说明如果列表为NULL则下载所有资产
/// </summary>
public AssetInfo[] AssetInfos { private set; get; }
public BundleDownloaderOptions(AssetInfo assetInfo, bool downloadDependencies, int maximumConcurrency, int failedTryAgain)
{
AssetInfos = new AssetInfo[] { assetInfo };
DownloadBundleDependencies = downloadDependencies;
MaximumConcurrency = maximumConcurrency;
FailedTryAgain = failedTryAgain;
}
public BundleDownloaderOptions(AssetInfo[] assetInfos, bool downloadDependencies, int maximumConcurrency, int failedTryAgain)
{
AssetInfos = assetInfos;
DownloadBundleDependencies = downloadDependencies;
MaximumConcurrency = maximumConcurrency;
FailedTryAgain = failedTryAgain;
}
}
/// <summary>
/// 资源下载选项
/// </summary>
public struct ResourceDownloaderOptions
{
/// <summary>
/// 最大并发数量
/// </summary>
public int MaximumConcurrency { private set; get; }
/// <summary>
/// 失败后的重试次数
/// </summary>
public int FailedTryAgain { private set; get; }
/// <summary>
/// 资源标签列表
/// 说明如果列表为NULL则下载所有资产
/// </summary>
public string[] Tags { private set; get; }
public ResourceDownloaderOptions(int maximumConcurrency, int failedTryAgain)
{
Tags = null;
MaximumConcurrency = maximumConcurrency;
FailedTryAgain = failedTryAgain;
}
public ResourceDownloaderOptions(string tag, int maximumConcurrency, int failedTryAgain)
{
Tags = new string[] { tag };
MaximumConcurrency = maximumConcurrency;
FailedTryAgain = failedTryAgain;
}
public ResourceDownloaderOptions(string[] tags, int maximumConcurrency, int failedTryAgain)
{
Tags = tags;
MaximumConcurrency = maximumConcurrency;
FailedTryAgain = failedTryAgain;
}
}
/// <summary>
/// 资源解压选项
/// </summary>
public struct ResourceUnpackerOptions
{
/// <summary>
/// 最大并发数量
/// </summary>
public int MaximumConcurrency { private set; get; }
/// <summary>
/// 失败后的重试次数
/// </summary>
public int FailedTryAgain { private set; get; }
/// <summary>
/// 资源标签列表
/// 说明如果列表为NULL则解压所有资产
/// </summary>
public string[] Tags { private set; get; }
public ResourceUnpackerOptions(int maximumConcurrency, int failedTryAgain)
{
Tags = null;
MaximumConcurrency = maximumConcurrency;
FailedTryAgain = failedTryAgain;
}
public ResourceUnpackerOptions(string tag, int maximumConcurrency, int failedTryAgain)
{
Tags = new string[] { tag };
MaximumConcurrency = maximumConcurrency;
FailedTryAgain = failedTryAgain;
}
public ResourceUnpackerOptions(string[] tags, int maximumConcurrency, int failedTryAgain)
{
Tags = tags;
MaximumConcurrency = maximumConcurrency;
FailedTryAgain = failedTryAgain;
}
}
/// <summary>
/// 资源导入选项
/// </summary>
public struct BundleImporterOptions
{
/// <summary>
/// 最大并发数量
/// </summary>
public int MaximumConcurrency { private set; get; }
/// <summary>
/// 失败后的重试次数
/// </summary>
public int FailedTryAgain { private set; get; }
/// <summary>
/// 资源包信息列表
/// </summary>
public ImportBundleInfo[] BundleInfos { private set; get; }
public BundleImporterOptions(ImportBundleInfo[] bundleInfos, int maximumConcurrency, int failedTryAgain)
{
BundleInfos = bundleInfos;
MaximumConcurrency = maximumConcurrency;
FailedTryAgain = failedTryAgain;
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 2567b73a071bdc14884214cb5e3b5cc0
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -17,7 +17,7 @@ namespace YooAsset
private readonly ResourcePackage _package; private readonly ResourcePackage _package;
private readonly InitializePackageOptions _options; private readonly InitializePackageOptions _options;
private PlayModeImpl _playModeImpl; private FileSystemHost _fileSystemHost;
private InitializeFileSystemOperation _initializeFileSystemOp; private InitializeFileSystemOperation _initializeFileSystemOp;
private EPlayMode _playMode; private EPlayMode _playMode;
private ESteps _steps = ESteps.None; private ESteps _steps = ESteps.None;
@@ -118,12 +118,11 @@ namespace YooAsset
{ {
string packageName = _package.PackageName; string packageName = _package.PackageName;
var resourceManager = new ResourceManager(packageName); var resourceManager = new ResourceManager(packageName);
var playModeImpl = new PlayModeImpl(packageName); var fileSystemHost = new FileSystemHost(packageName);
resourceManager.Initialize(_options, playModeImpl); resourceManager.Initialize(_options, fileSystemHost);
_playModeImpl = playModeImpl; _fileSystemHost = fileSystemHost;
_package._bundleQuery = playModeImpl; _package._fileSystemHost = fileSystemHost;
_package._playModeImpl = playModeImpl;
_package._resourceManager = resourceManager; _package._resourceManager = resourceManager;
_steps = ESteps.InitFileSystem; _steps = ESteps.InitFileSystem;
} }
@@ -135,27 +134,27 @@ namespace YooAsset
if (_playMode == EPlayMode.EditorSimulateMode) if (_playMode == EPlayMode.EditorSimulateMode)
{ {
var initializeParameters = _options as EditorSimulateModeOptions; var initializeParameters = _options as EditorSimulateModeOptions;
_initializeFileSystemOp = _playModeImpl.InitializeAsync(initializeParameters.EditorFileSystemParameters); _initializeFileSystemOp = _fileSystemHost.InitializeAsync(initializeParameters.EditorFileSystemParameters);
} }
else if (_playMode == EPlayMode.OfflinePlayMode) else if (_playMode == EPlayMode.OfflinePlayMode)
{ {
var initializeParameters = _options as OfflinePlayModeOptions; var initializeParameters = _options as OfflinePlayModeOptions;
_initializeFileSystemOp = _playModeImpl.InitializeAsync(initializeParameters.BuildinFileSystemParameters); _initializeFileSystemOp = _fileSystemHost.InitializeAsync(initializeParameters.BuildinFileSystemParameters);
} }
else if (_playMode == EPlayMode.HostPlayMode) else if (_playMode == EPlayMode.HostPlayMode)
{ {
var initializeParameters = _options as HostPlayModeOptions; var initializeParameters = _options as HostPlayModeOptions;
_initializeFileSystemOp = _playModeImpl.InitializeAsync(initializeParameters.BuildinFileSystemParameters, initializeParameters.CacheFileSystemParameters); _initializeFileSystemOp = _fileSystemHost.InitializeAsync(initializeParameters.BuildinFileSystemParameters, initializeParameters.CacheFileSystemParameters);
} }
else if (_playMode == EPlayMode.WebPlayMode) else if (_playMode == EPlayMode.WebPlayMode)
{ {
var initializeParameters = _options as WebPlayModeOptions; var initializeParameters = _options as WebPlayModeOptions;
_initializeFileSystemOp = _playModeImpl.InitializeAsync(initializeParameters.WebServerFileSystemParameters, initializeParameters.WebRemoteFileSystemParameters); _initializeFileSystemOp = _fileSystemHost.InitializeAsync(initializeParameters.WebServerFileSystemParameters, initializeParameters.WebRemoteFileSystemParameters);
} }
else if (_playMode == EPlayMode.CustomPlayMode) else if (_playMode == EPlayMode.CustomPlayMode)
{ {
var initializeParameters = _options as CustomPlayModeOptions; var initializeParameters = _options as CustomPlayModeOptions;
_initializeFileSystemOp = _playModeImpl.InitializeAsync(initializeParameters.FileSystemParameterList); _initializeFileSystemOp = _fileSystemHost.InitializeAsync(initializeParameters.FileSystemParameterList);
} }
else else
{ {

View File

@@ -74,7 +74,7 @@ namespace YooAsset
// 读取文件标记 // 读取文件标记
uint fileSign = _buffer.ReadUInt32(); uint fileSign = _buffer.ReadUInt32();
if (fileSign != ManifestDefine.FileSign) if (fileSign != PackageManifestDefine.FileSign)
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Failed; Status = EOperationStatus.Failed;
@@ -85,8 +85,8 @@ namespace YooAsset
// 读取文件版本 // 读取文件版本
string fileVersion = _buffer.ReadUTF8(); string fileVersion = _buffer.ReadUTF8();
Version fileVer = new Version(fileVersion); Version fileVer = new Version(fileVersion);
Version ver2025_8_28 = new Version(ManifestDefine.VERSION_2025_8_28); Version ver2025_8_28 = new Version(PackageManifestDefine.VERSION_2025_8_28);
Version ver2025_9_30 = new Version(ManifestDefine.VERSION_2025_9_30); Version ver2025_9_30 = new Version(PackageManifestDefine.VERSION_2025_9_30);
if (fileVer < ver2025_8_28) if (fileVer < ver2025_8_28)
{ {
_steps = ESteps.Done; _steps = ESteps.Done;

View File

@@ -14,15 +14,15 @@ namespace YooAsset
Done, Done,
} }
private readonly PlayModeImpl _impl; private readonly FileSystemHost _host;
private readonly List<FileSystemParameters> _parametersList; private readonly List<FileSystemParameters> _parametersList;
private List<FileSystemParameters> _cloneList; private List<FileSystemParameters> _cloneList;
private FSInitializeFileSystemOperation _initFileSystemOp; private FSInitializeFileSystemOperation _initFileSystemOp;
private ESteps _steps = ESteps.None; private ESteps _steps = ESteps.None;
internal InitializeFileSystemOperation(PlayModeImpl impl, List<FileSystemParameters> parametersList) internal InitializeFileSystemOperation(FileSystemHost host, List<FileSystemParameters> parametersList)
{ {
_impl = impl; _host = host;
_parametersList = parametersList; _parametersList = parametersList;
} }
internal override void InternalStart() internal override void InternalStart()
@@ -71,7 +71,7 @@ namespace YooAsset
var fileSystemParams = _cloneList[0]; var fileSystemParams = _cloneList[0];
_cloneList.RemoveAt(0); _cloneList.RemoveAt(0);
IFileSystem fileSystemInstance = fileSystemParams.CreateFileSystem(_impl.PackageName); IFileSystem fileSystemInstance = fileSystemParams.CreateFileSystem(_host.PackageName);
if (fileSystemInstance == null) if (fileSystemInstance == null)
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
@@ -80,7 +80,7 @@ namespace YooAsset
return; return;
} }
_impl.FileSystems.Add(fileSystemInstance); _host.FileSystems.Add(fileSystemInstance);
_initFileSystemOp = fileSystemInstance.InitializeFileSystemAsync(); _initFileSystemOp = fileSystemInstance.InitializeFileSystemAsync();
_initFileSystemOp.StartOperation(); _initFileSystemOp.StartOperation();
AddChildOperation(_initFileSystemOp); AddChildOperation(_initFileSystemOp);

View File

@@ -12,14 +12,14 @@ namespace YooAsset
Done, Done,
} }
private readonly PlayModeImpl _impl; private readonly FileSystemHost _host;
private readonly LoadPackageManifestOptions _options; private readonly LoadPackageManifestOptions _options;
private FSLoadPackageManifestOperation _loadPackageManifestOp; private FSLoadPackageManifestOperation _loadPackageManifestOp;
private ESteps _steps = ESteps.None; private ESteps _steps = ESteps.None;
internal LoadPackageManifestOperation(PlayModeImpl impl, LoadPackageManifestOptions options) internal LoadPackageManifestOperation(FileSystemHost host, LoadPackageManifestOptions options)
{ {
_impl = impl; _host = host;
_options = options; _options = options;
} }
internal override void InternalStart() internal override void InternalStart()
@@ -48,7 +48,7 @@ namespace YooAsset
if (_steps == ESteps.CheckActiveManifest) if (_steps == ESteps.CheckActiveManifest)
{ {
// 检测当前激活的清单对象 // 检测当前激活的清单对象
if (_impl.ActiveManifest != null && _impl.ActiveManifest.PackageVersion == _options.PackageVersion) if (_host.ActiveManifest != null && _host.ActiveManifest.PackageVersion == _options.PackageVersion)
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Succeed; Status = EOperationStatus.Succeed;
@@ -63,7 +63,7 @@ namespace YooAsset
{ {
if (_loadPackageManifestOp == null) if (_loadPackageManifestOp == null)
{ {
var mainFileSystem = _impl.GetMainFileSystem(); var mainFileSystem = _host.GetMainFileSystem();
_loadPackageManifestOp = mainFileSystem.LoadPackageManifestAsync(_options); _loadPackageManifestOp = mainFileSystem.LoadPackageManifestAsync(_options);
_loadPackageManifestOp.StartOperation(); _loadPackageManifestOp.StartOperation();
AddChildOperation(_loadPackageManifestOp); AddChildOperation(_loadPackageManifestOp);
@@ -76,7 +76,7 @@ namespace YooAsset
if (_loadPackageManifestOp.Status == EOperationStatus.Succeed) if (_loadPackageManifestOp.Status == EOperationStatus.Succeed)
{ {
_steps = ESteps.Done; _steps = ESteps.Done;
_impl.ActiveManifest = _loadPackageManifestOp.Manifest; _host.ActiveManifest = _loadPackageManifestOp.Manifest;
Status = EOperationStatus.Succeed; Status = EOperationStatus.Succeed;
} }
else else

View File

@@ -15,7 +15,7 @@ namespace YooAsset
Done, Done,
} }
private readonly PlayModeImpl _impl; private readonly FileSystemHost _host;
private readonly PreDownloadContentOptions _options; private readonly PreDownloadContentOptions _options;
private readonly int _timeout; private readonly int _timeout;
private FSLoadPackageManifestOperation _loadPackageManifestOp; private FSLoadPackageManifestOperation _loadPackageManifestOp;
@@ -23,9 +23,9 @@ namespace YooAsset
private ESteps _steps = ESteps.None; private ESteps _steps = ESteps.None;
internal PreDownloadContentOperation(PlayModeImpl impl, PreDownloadContentOptions options) internal PreDownloadContentOperation(FileSystemHost host, PreDownloadContentOptions options)
{ {
_impl = impl; _host = host;
_options = options; _options = options;
} }
internal override void InternalStart() internal override void InternalStart()
@@ -53,11 +53,11 @@ namespace YooAsset
if (_steps == ESteps.CheckActiveManifest) if (_steps == ESteps.CheckActiveManifest)
{ {
// 检测当前激活的清单对象 // 检测当前激活的清单对象
if (_impl.ActiveManifest != null) if (_host.ActiveManifest != null)
{ {
if (_impl.ActiveManifest.PackageVersion == _options.PackageVersion) if (_host.ActiveManifest.PackageVersion == _options.PackageVersion)
{ {
_manifest = _impl.ActiveManifest; _manifest = _host.ActiveManifest;
_steps = ESteps.Done; _steps = ESteps.Done;
Status = EOperationStatus.Succeed; Status = EOperationStatus.Succeed;
return; return;
@@ -70,7 +70,7 @@ namespace YooAsset
{ {
if (_loadPackageManifestOp == null) if (_loadPackageManifestOp == null)
{ {
var mainFileSystem = _impl.GetMainFileSystem(); var mainFileSystem = _host.GetMainFileSystem();
var options = new LoadPackageManifestOptions(_options.PackageVersion, _options.Timeout); var options = new LoadPackageManifestOptions(_options.PackageVersion, _options.Timeout);
_loadPackageManifestOp = mainFileSystem.LoadPackageManifestAsync(options); _loadPackageManifestOp = mainFileSystem.LoadPackageManifestAsync(options);
_loadPackageManifestOp.StartOperation(); _loadPackageManifestOp.StartOperation();
@@ -106,11 +106,11 @@ namespace YooAsset
if (Status != EOperationStatus.Succeed) if (Status != EOperationStatus.Succeed)
{ {
YooLogger.Warning($"{nameof(PreDownloadContentOperation)} status is not succeed !"); YooLogger.Warning($"{nameof(PreDownloadContentOperation)} status is not succeed !");
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain); return ResourceDownloaderOperation.CreateEmptyDownloader(_host.PackageName, downloadingMaxNumber, failedTryAgain);
} }
List<BundleInfo> downloadList = _impl.GetDownloadListByAll(_manifest); List<BundleInfo> downloadList = _host.GetDownloadListByAll(_manifest);
var operation = new ResourceDownloaderOperation(_impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain); var operation = new ResourceDownloaderOperation(_host.PackageName, downloadList, downloadingMaxNumber, failedTryAgain);
return operation; return operation;
} }
@@ -125,11 +125,11 @@ namespace YooAsset
if (Status != EOperationStatus.Succeed) if (Status != EOperationStatus.Succeed)
{ {
YooLogger.Warning($"{nameof(PreDownloadContentOperation)} status is not succeed !"); YooLogger.Warning($"{nameof(PreDownloadContentOperation)} status is not succeed !");
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain); return ResourceDownloaderOperation.CreateEmptyDownloader(_host.PackageName, downloadingMaxNumber, failedTryAgain);
} }
List<BundleInfo> downloadList = _impl.GetDownloadListByTags(_manifest, new string[] { tag }); List<BundleInfo> downloadList = _host.GetDownloadListByTags(_manifest, new string[] { tag });
var operation = new ResourceDownloaderOperation(_impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain); var operation = new ResourceDownloaderOperation(_host.PackageName, downloadList, downloadingMaxNumber, failedTryAgain);
return operation; return operation;
} }
@@ -144,11 +144,11 @@ namespace YooAsset
if (Status != EOperationStatus.Succeed) if (Status != EOperationStatus.Succeed)
{ {
YooLogger.Warning($"{nameof(PreDownloadContentOperation)} status is not succeed !"); YooLogger.Warning($"{nameof(PreDownloadContentOperation)} status is not succeed !");
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain); return ResourceDownloaderOperation.CreateEmptyDownloader(_host.PackageName, downloadingMaxNumber, failedTryAgain);
} }
List<BundleInfo> downloadList = _impl.GetDownloadListByTags(_manifest, tags); List<BundleInfo> downloadList = _host.GetDownloadListByTags(_manifest, tags);
var operation = new ResourceDownloaderOperation(_impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain); var operation = new ResourceDownloaderOperation(_host.PackageName, downloadList, downloadingMaxNumber, failedTryAgain);
return operation; return operation;
} }
@@ -163,15 +163,15 @@ namespace YooAsset
if (Status != EOperationStatus.Succeed) if (Status != EOperationStatus.Succeed)
{ {
YooLogger.Warning($"{nameof(PreDownloadContentOperation)} status is not succeed !"); YooLogger.Warning($"{nameof(PreDownloadContentOperation)} status is not succeed !");
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain); return ResourceDownloaderOperation.CreateEmptyDownloader(_host.PackageName, downloadingMaxNumber, failedTryAgain);
} }
List<AssetInfo> assetInfos = new List<AssetInfo>(); List<AssetInfo> assetInfos = new List<AssetInfo>();
var assetInfo = _manifest.ConvertLocationToAssetInfo(location, null); var assetInfo = _manifest.ConvertLocationToAssetInfo(location, null);
assetInfos.Add(assetInfo); assetInfos.Add(assetInfo);
List<BundleInfo> downloadList = _impl.GetDownloadListByPaths(_manifest, assetInfos.ToArray(), recursiveDownload); List<BundleInfo> downloadList = _host.GetDownloadListByAssetInfos(_manifest, assetInfos.ToArray(), recursiveDownload);
var operation = new ResourceDownloaderOperation(_impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain); var operation = new ResourceDownloaderOperation(_host.PackageName, downloadList, downloadingMaxNumber, failedTryAgain);
return operation; return operation;
} }
@@ -186,7 +186,7 @@ namespace YooAsset
if (Status != EOperationStatus.Succeed) if (Status != EOperationStatus.Succeed)
{ {
YooLogger.Warning($"{nameof(PreDownloadContentOperation)} status is not succeed !"); YooLogger.Warning($"{nameof(PreDownloadContentOperation)} status is not succeed !");
return ResourceDownloaderOperation.CreateEmptyDownloader(_impl.PackageName, downloadingMaxNumber, failedTryAgain); return ResourceDownloaderOperation.CreateEmptyDownloader(_host.PackageName, downloadingMaxNumber, failedTryAgain);
} }
List<AssetInfo> assetInfos = new List<AssetInfo>(locations.Length); List<AssetInfo> assetInfos = new List<AssetInfo>(locations.Length);
@@ -196,8 +196,8 @@ namespace YooAsset
assetInfos.Add(assetInfo); assetInfos.Add(assetInfo);
} }
List<BundleInfo> downloadList = _impl.GetDownloadListByPaths(_manifest, assetInfos.ToArray(), recursiveDownload); List<BundleInfo> downloadList = _host.GetDownloadListByAssetInfos(_manifest, assetInfos.ToArray(), recursiveDownload);
var operation = new ResourceDownloaderOperation(_impl.PackageName, downloadList, downloadingMaxNumber, failedTryAgain); var operation = new ResourceDownloaderOperation(_host.PackageName, downloadList, downloadingMaxNumber, failedTryAgain);
return operation; return operation;
} }
} }

View File

@@ -1,14 +1,7 @@
 
namespace YooAsset namespace YooAsset
{ {
public abstract class RequestPackageVersionOperation : AsyncOperationBase public sealed class RequestPackageVersionOperation : AsyncOperationBase
{
/// <summary>
/// 当前最新的包裹版本
/// </summary>
public string PackageVersion { protected set; get; }
}
internal sealed class RequestPackageVersionImplOperation : RequestPackageVersionOperation
{ {
private enum ESteps private enum ESteps
{ {
@@ -17,14 +10,20 @@ namespace YooAsset
Done, Done,
} }
private readonly PlayModeImpl _impl; private readonly FileSystemHost _host;
private readonly RequestPackageVersionOptions _options; private readonly RequestPackageVersionOptions _options;
private FSRequestPackageVersionOperation _requestPackageVersionOp; private FSRequestPackageVersionOperation _requestPackageVersionOp;
private ESteps _steps = ESteps.None; private ESteps _steps = ESteps.None;
internal RequestPackageVersionImplOperation(PlayModeImpl impl, RequestPackageVersionOptions options) /// <summary>
/// 当前最新的包裹版本
/// </summary>
public string PackageVersion { private set; get; }
internal RequestPackageVersionOperation(FileSystemHost host, RequestPackageVersionOptions options)
{ {
_impl = impl; _host = host;
_options = options; _options = options;
} }
internal override void InternalStart() internal override void InternalStart()
@@ -40,7 +39,7 @@ namespace YooAsset
{ {
if (_requestPackageVersionOp == null) if (_requestPackageVersionOp == null)
{ {
var mainFileSystem = _impl.GetMainFileSystem(); var mainFileSystem = _host.GetMainFileSystem();
_requestPackageVersionOp = mainFileSystem.RequestPackageVersionAsync(_options); _requestPackageVersionOp = mainFileSystem.RequestPackageVersionAsync(_options);
_requestPackageVersionOp.StartOperation(); _requestPackageVersionOp.StartOperation();
AddChildOperation(_requestPackageVersionOp); AddChildOperation(_requestPackageVersionOp);

View File

@@ -122,8 +122,8 @@ namespace YooAsset
{ {
_mainfest = manifest; _mainfest = manifest;
_bundleType = manifest.BuildBundleType; _bundleType = manifest.BuildBundleType;
_fileExtension = ManifestTools.GetRemoteBundleFileExtension(BundleName); _fileExtension = PackageManifestTools.GetRemoteBundleFileExtension(BundleName);
_fileName = ManifestTools.GetRemoteBundleFileName(manifest.OutputNameStyle, BundleName, _fileExtension, FileHash); _fileName = PackageManifestTools.GetRemoteBundleFileName(manifest.OutputNameStyle, BundleName, _fileExtension, FileHash);
} }
/// <summary> /// <summary>

View File

@@ -1,7 +1,7 @@
 
namespace YooAsset namespace YooAsset
{ {
public class ManifestDefine internal class PackageManifestDefine
{ {
/// <summary> /// <summary>
/// 文件极限大小100MB /// 文件极限大小100MB

View File

@@ -6,7 +6,7 @@ using UnityEngine;
namespace YooAsset namespace YooAsset
{ {
internal static class ManifestTools internal static class PackageManifestTools
{ {
/// <summary> /// <summary>
/// 验证清单文件的二进制数据 /// 验证清单文件的二进制数据
@@ -49,10 +49,10 @@ namespace YooAsset
using (FileStream fs = new FileStream(savePath, FileMode.Create)) using (FileStream fs = new FileStream(savePath, FileMode.Create))
{ {
// 创建缓存器 // 创建缓存器
BufferWriter buffer = new BufferWriter(ManifestDefine.FileMaxSize); BufferWriter buffer = new BufferWriter(PackageManifestDefine.FileMaxSize);
// 写入文件标记 // 写入文件标记
buffer.WriteUInt32(ManifestDefine.FileSign); buffer.WriteUInt32(PackageManifestDefine.FileSign);
// 写入文件版本 // 写入文件版本
buffer.WriteUTF8(manifest.FileVersion); buffer.WriteUTF8(manifest.FileVersion);

View File

@@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: e9d6cb1ce5d510645866ad7c122abfab
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -10,8 +10,7 @@ namespace YooAsset
{ {
private InitializePackageOperation _initializeOp; private InitializePackageOperation _initializeOp;
internal ResourceManager _resourceManager; internal ResourceManager _resourceManager;
internal IBundleQuery _bundleQuery; internal FileSystemHost _fileSystemHost;
internal IPlayMode _playModeImpl;
internal EPlayMode _playMode; internal EPlayMode _playMode;
/// <summary> /// <summary>
@@ -39,9 +38,9 @@ namespace YooAsset
{ {
get get
{ {
if (_playModeImpl == null) if (_fileSystemHost == null)
return false; return false;
return _playModeImpl.ActiveManifest != null; return _fileSystemHost.ActiveManifest != null;
} }
} }
@@ -66,7 +65,6 @@ namespace YooAsset
internal void InternalDestroy() internal void InternalDestroy()
{ {
_initializeOp = null; _initializeOp = null;
_bundleQuery = null;
// 销毁资源管理器 // 销毁资源管理器
if (_resourceManager != null) if (_resourceManager != null)
@@ -75,11 +73,11 @@ namespace YooAsset
_resourceManager = null; _resourceManager = null;
} }
// 销毁文件系统 // 销毁文件系统中枢
if (_playModeImpl != null) if (_fileSystemHost != null)
{ {
_playModeImpl.DestroyFileSystem(); _fileSystemHost.Destroy();
_playModeImpl = null; _fileSystemHost = null;
} }
} }
@@ -135,7 +133,7 @@ namespace YooAsset
public RequestPackageVersionOperation RequestPackageVersionAsync(RequestPackageVersionOptions options) public RequestPackageVersionOperation RequestPackageVersionAsync(RequestPackageVersionOptions options)
{ {
DebugCheckInitialize(false); DebugCheckInitialize(false);
var operation = _playModeImpl.RequestPackageVersionAsync(options); var operation = new RequestPackageVersionOperation(_fileSystemHost, options);
OperationSystem.StartOperation(PackageName, operation); OperationSystem.StartOperation(PackageName, operation);
return operation; return operation;
} }
@@ -153,7 +151,7 @@ namespace YooAsset
YooLogger.Warning($"Found loaded bundle before update manifest ! Recommended to call the {nameof(UnloadAllAssetsAsync)} method to release loaded bundle !"); YooLogger.Warning($"Found loaded bundle before update manifest ! Recommended to call the {nameof(UnloadAllAssetsAsync)} method to release loaded bundle !");
} }
var operation = _playModeImpl.LoadPackageManifestAsync(options); var operation = new LoadPackageManifestOperation(_fileSystemHost, options);
OperationSystem.StartOperation(PackageName, operation); OperationSystem.StartOperation(PackageName, operation);
return operation; return operation;
} }
@@ -164,7 +162,7 @@ namespace YooAsset
public PreDownloadContentOperation PreDownloadContentAsync(PreDownloadContentOptions options) public PreDownloadContentOperation PreDownloadContentAsync(PreDownloadContentOptions options)
{ {
DebugCheckInitialize(false); DebugCheckInitialize(false);
var operation = _playModeImpl.PreDownloadContentAsync(options); var operation = new PreDownloadContentOperation(_fileSystemHost, options);
OperationSystem.StartOperation(PackageName, operation); OperationSystem.StartOperation(PackageName, operation);
return operation; return operation;
} }
@@ -175,7 +173,8 @@ namespace YooAsset
public ClearCacheFilesOperation ClearCacheFilesAsync(ClearCacheFilesOptions options) public ClearCacheFilesOperation ClearCacheFilesAsync(ClearCacheFilesOptions options)
{ {
DebugCheckInitialize(false); DebugCheckInitialize(false);
var operation = _playModeImpl.ClearCacheFilesAsync(options); options.Manifest = _fileSystemHost.ActiveManifest;
var operation = new ClearCacheFilesOperation(_fileSystemHost, options);
OperationSystem.StartOperation(PackageName, operation); OperationSystem.StartOperation(PackageName, operation);
return operation; return operation;
} }
@@ -188,7 +187,7 @@ namespace YooAsset
public string GetPackageVersion() public string GetPackageVersion()
{ {
DebugCheckInitialize(); DebugCheckInitialize();
return _playModeImpl.ActiveManifest.PackageVersion; return _fileSystemHost.ActiveManifest.PackageVersion;
} }
/// <summary> /// <summary>
@@ -197,7 +196,7 @@ namespace YooAsset
public string GetPackageNote() public string GetPackageNote()
{ {
DebugCheckInitialize(); DebugCheckInitialize();
return _playModeImpl.ActiveManifest.PackageNote; return _fileSystemHost.ActiveManifest.PackageNote;
} }
/// <summary> /// <summary>
@@ -206,7 +205,7 @@ namespace YooAsset
public PackageDetails GetPackageDetails() public PackageDetails GetPackageDetails()
{ {
DebugCheckInitialize(); DebugCheckInitialize();
return _playModeImpl.ActiveManifest.GetPackageDetails(); return _fileSystemHost.ActiveManifest.GetPackageDetails();
} }
#endregion #endregion
@@ -216,7 +215,7 @@ namespace YooAsset
/// </summary> /// </summary>
public UnloadAllAssetsOperation UnloadAllAssetsAsync() public UnloadAllAssetsOperation UnloadAllAssetsAsync()
{ {
var options = new UnloadAllAssetsOptions(); var options = new UnloadAllAssetsOptions(true, true);
return UnloadAllAssetsAsync(options); return UnloadAllAssetsAsync(options);
} }
@@ -235,12 +234,22 @@ namespace YooAsset
/// <summary> /// <summary>
/// 回收不再使用的资源 /// 回收不再使用的资源
/// 说明:卸载引用计数为零的资源 /// 说明:卸载引用计数为零的资源
/// 说明默认循环10次
/// </summary> /// </summary>
/// <param name="loopCount">循环迭代次数</param> public UnloadUnusedAssetsOperation UnloadUnusedAssetsAsync()
public UnloadUnusedAssetsOperation UnloadUnusedAssetsAsync(int loopCount = 10) {
var options = new UnloadUnusedAssetsOptions(10);
return UnloadUnusedAssetsAsync(options);
}
/// <summary>
/// 回收不再使用的资源
/// 说明:卸载引用计数为零的资源
/// </summary>
public UnloadUnusedAssetsOperation UnloadUnusedAssetsAsync(UnloadUnusedAssetsOptions options)
{ {
DebugCheckInitialize(); DebugCheckInitialize();
var operation = new UnloadUnusedAssetsOperation(_resourceManager, loopCount); var operation = new UnloadUnusedAssetsOperation(_resourceManager, options);
OperationSystem.StartOperation(PackageName, operation); OperationSystem.StartOperation(PackageName, operation);
return operation; return operation;
} }
@@ -295,7 +304,7 @@ namespace YooAsset
public AssetInfo[] GetAllAssetInfos() public AssetInfo[] GetAllAssetInfos()
{ {
DebugCheckInitialize(); DebugCheckInitialize();
return _playModeImpl.ActiveManifest.GetAllAssetInfos(); return _fileSystemHost.ActiveManifest.GetAllAssetInfos();
} }
/// <summary> /// <summary>
@@ -306,7 +315,7 @@ namespace YooAsset
{ {
DebugCheckInitialize(); DebugCheckInitialize();
string[] tags = new string[] { tag }; string[] tags = new string[] { tag };
return _playModeImpl.ActiveManifest.GetAssetInfosByTags(tags); return _fileSystemHost.ActiveManifest.GetAssetInfosByTags(tags);
} }
/// <summary> /// <summary>
@@ -316,7 +325,7 @@ namespace YooAsset
public AssetInfo[] GetAssetInfos(string[] tags) public AssetInfo[] GetAssetInfos(string[] tags)
{ {
DebugCheckInitialize(); DebugCheckInitialize();
return _playModeImpl.ActiveManifest.GetAssetInfosByTags(tags); return _fileSystemHost.ActiveManifest.GetAssetInfosByTags(tags);
} }
/// <summary> /// <summary>
@@ -368,7 +377,7 @@ namespace YooAsset
public bool CheckLocationValid(string location) public bool CheckLocationValid(string location)
{ {
DebugCheckInitialize(); DebugCheckInitialize();
string assetPath = _playModeImpl.ActiveManifest.TryMappingToAssetPath(location); string assetPath = _fileSystemHost.ActiveManifest.TryMappingToAssetPath(location);
return string.IsNullOrEmpty(assetPath) == false; return string.IsNullOrEmpty(assetPath) == false;
} }
@@ -380,11 +389,11 @@ namespace YooAsset
return false; return false;
} }
BundleInfo bundleInfo = _bundleQuery.GetMainBundleInfo(assetInfo); BundleInfo bundleInfo = _fileSystemHost.GetMainBundleInfo(assetInfo);
if (bundleInfo.IsNeedDownloadFromRemote()) if (bundleInfo.IsNeedDownloadFromRemote())
return true; return true;
List<BundleInfo> depends = _bundleQuery.GetDependBundleInfos(assetInfo); List<BundleInfo> depends = _fileSystemHost.GetDependBundleInfos(assetInfo);
foreach (var depend in depends) foreach (var depend in depends)
{ {
if (depend.IsNeedDownloadFromRemote()) if (depend.IsNeedDownloadFromRemote())
@@ -849,192 +858,55 @@ namespace YooAsset
#endregion #endregion
#region #region
/// <summary>
/// 创建资源下载器,用于下载当前资源版本所有的资源包文件
/// </summary>
/// <param name="downloadingMaxNumber">同时下载的最大文件数</param>
/// <param name="failedTryAgain">下载失败的重试次数</param>
public ResourceDownloaderOperation CreateResourceDownloader(int downloadingMaxNumber, int failedTryAgain)
{
DebugCheckInitialize();
return _playModeImpl.CreateResourceDownloaderByAll(downloadingMaxNumber, failedTryAgain);
}
/// <summary>
/// 创建资源下载器,用于下载指定的资源标签关联的资源包文件
/// </summary>
/// <param name="tag">资源标签</param>
/// <param name="downloadingMaxNumber">同时下载的最大文件数</param>
/// <param name="failedTryAgain">下载失败的重试次数</param>
public ResourceDownloaderOperation CreateResourceDownloader(string tag, int downloadingMaxNumber, int failedTryAgain)
{
DebugCheckInitialize();
return _playModeImpl.CreateResourceDownloaderByTags(new string[] { tag }, downloadingMaxNumber, failedTryAgain);
}
/// <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)
{ {
DebugCheckInitialize(); DebugCheckInitialize();
return _playModeImpl.CreateResourceDownloaderByTags(tags, downloadingMaxNumber, failedTryAgain); return _fileSystemHost.CreateResourceDownloader(options);
} }
/// <summary> /// <summary>
/// 创建资源下载器,用于下载指定的资源依赖的资源包文件 /// 创建资源下载器,用于下载指定的资源信息列表依赖的资源包文件
/// </summary> /// </summary>
/// <param name="location">资源的定位地址</param> public ResourceDownloaderOperation CreateBundleDownloader(BundleDownloaderOptions options)
/// <param name="recursiveDownload">下载资源对象所属资源包内所有资源对象依赖的资源包</param>
/// <param name="downloadingMaxNumber">同时下载的最大文件数</param>
/// <param name="failedTryAgain">下载失败的重试次数</param>
public ResourceDownloaderOperation CreateBundleDownloader(string location, bool recursiveDownload, int downloadingMaxNumber, int failedTryAgain)
{ {
DebugCheckInitialize(); DebugCheckInitialize();
var assetInfo = ConvertLocationToAssetInfo(location, null); return _fileSystemHost.CreateResourceDownloader(options);
AssetInfo[] assetInfos = new AssetInfo[] { assetInfo };
return _playModeImpl.CreateResourceDownloaderByPaths(assetInfos, recursiveDownload, downloadingMaxNumber, failedTryAgain);
}
public ResourceDownloaderOperation CreateBundleDownloader(string location, int downloadingMaxNumber, int failedTryAgain)
{
return CreateBundleDownloader(location, false, downloadingMaxNumber, failedTryAgain);
}
/// <summary>
/// 创建资源下载器,用于下载指定的资源列表依赖的资源包文件
/// </summary>
/// <param name="locations">资源的定位地址列表</param>
/// <param name="recursiveDownload">下载资源对象所属资源包内所有资源对象依赖的资源包</param>
/// <param name="downloadingMaxNumber">同时下载的最大文件数</param>
/// <param name="failedTryAgain">下载失败的重试次数</param>
public ResourceDownloaderOperation CreateBundleDownloader(string[] locations, bool recursiveDownload, int downloadingMaxNumber, int failedTryAgain)
{
DebugCheckInitialize();
List<AssetInfo> assetInfos = new List<AssetInfo>(locations.Length);
foreach (var location in locations)
{
var assetInfo = ConvertLocationToAssetInfo(location, null);
assetInfos.Add(assetInfo);
}
return _playModeImpl.CreateResourceDownloaderByPaths(assetInfos.ToArray(), recursiveDownload, downloadingMaxNumber, failedTryAgain);
}
public ResourceDownloaderOperation CreateBundleDownloader(string[] locations, int downloadingMaxNumber, int failedTryAgain)
{
return CreateBundleDownloader(locations, false, downloadingMaxNumber, failedTryAgain);
}
/// <summary>
/// 创建资源下载器,用于下载指定的资源依赖的资源包文件
/// </summary>
/// <param name="assetInfo">资源信息</param>
/// <param name="recursiveDownload">下载资源对象所属资源包内所有资源对象依赖的资源包</param>
/// <param name="downloadingMaxNumber">同时下载的最大文件数</param>
/// <param name="failedTryAgain">下载失败的重试次数</param>
public ResourceDownloaderOperation CreateBundleDownloader(AssetInfo assetInfo, bool recursiveDownload, int downloadingMaxNumber, int failedTryAgain)
{
DebugCheckInitialize();
AssetInfo[] assetInfos = new AssetInfo[] { assetInfo };
return _playModeImpl.CreateResourceDownloaderByPaths(assetInfos, recursiveDownload, downloadingMaxNumber, failedTryAgain);
}
public ResourceDownloaderOperation CreateBundleDownloader(AssetInfo assetInfo, int downloadingMaxNumber, int failedTryAgain)
{
return CreateBundleDownloader(assetInfo, false, downloadingMaxNumber, failedTryAgain);
}
/// <summary>
/// 创建资源下载器,用于下载指定的资源列表依赖的资源包文件
/// </summary>
/// <param name="assetInfos">资源信息列表</param>
/// <param name="recursiveDownload">下载资源对象所属资源包内所有资源对象依赖的资源包</param>
/// <param name="downloadingMaxNumber">同时下载的最大文件数</param>
/// <param name="failedTryAgain">下载失败的重试次数</param>
public ResourceDownloaderOperation CreateBundleDownloader(AssetInfo[] assetInfos, bool recursiveDownload, int downloadingMaxNumber, int failedTryAgain)
{
DebugCheckInitialize();
return _playModeImpl.CreateResourceDownloaderByPaths(assetInfos, recursiveDownload, downloadingMaxNumber, failedTryAgain);
}
public ResourceDownloaderOperation CreateBundleDownloader(AssetInfo[] assetInfos, int downloadingMaxNumber, int failedTryAgain)
{
return CreateBundleDownloader(assetInfos, false, downloadingMaxNumber, failedTryAgain);
} }
#endregion #endregion
#region #region
/// <summary>
/// 创建内置资源解压器,用于解压当前资源版本所有的资源包文件
/// </summary>
/// <param name="unpackingMaxNumber">同时解压的最大文件数</param>
/// <param name="failedTryAgain">解压失败的重试次数</param>
public ResourceUnpackerOperation CreateResourceUnpacker(int unpackingMaxNumber, int failedTryAgain)
{
DebugCheckInitialize();
return _playModeImpl.CreateResourceUnpackerByAll(unpackingMaxNumber, failedTryAgain);
}
/// <summary>
/// 创建内置资源解压器,用于解压指定的资源标签关联的资源包文件
/// </summary>
/// <param name="tag">资源标签</param>
/// <param name="unpackingMaxNumber">同时解压的最大文件数</param>
/// <param name="failedTryAgain">解压失败的重试次数</param>
public ResourceUnpackerOperation CreateResourceUnpacker(string tag, int unpackingMaxNumber, int failedTryAgain)
{
DebugCheckInitialize();
return _playModeImpl.CreateResourceUnpackerByTags(new string[] { tag }, unpackingMaxNumber, failedTryAgain);
}
/// <summary> /// <summary>
/// 创建内置资源解压器,用于解压指定的资源标签列表关联的资源包文件 /// 创建内置资源解压器,用于解压指定的资源标签列表关联的资源包文件
/// </summary> /// </summary>
/// <param name="tags">资源标签列表</param> public ResourceUnpackerOperation CreateResourceUnpacker(ResourceUnpackerOptions options)
/// <param name="unpackingMaxNumber">同时解压的最大文件数</param>
/// <param name="failedTryAgain">解压失败的重试次数</param>
public ResourceUnpackerOperation CreateResourceUnpacker(string[] tags, int unpackingMaxNumber, int failedTryAgain)
{ {
DebugCheckInitialize(); DebugCheckInitialize();
return _playModeImpl.CreateResourceUnpackerByTags(tags, unpackingMaxNumber, failedTryAgain); return _fileSystemHost.CreateResourceUnpacker(options);
} }
#endregion #endregion
#region #region
/// <summary> /// <summary>
/// 创建资源导入器 /// 创建资源导入器
/// 注意:资源文件名称必须和资源服务器部署的文件名称一致!
/// </summary> /// </summary>
/// <param name="filePaths">资源路径列表</param> public ResourceImporterOperation CreateResourceImporter(BundleImporterOptions options)
/// <param name="importerMaxNumber">同时导入的最大文件数</param>
/// <param name="failedTryAgain">导入失败的重试次数</param>
public ResourceImporterOperation CreateResourceImporter(string[] filePaths, int importerMaxNumber, int failedTryAgain)
{ {
DebugCheckInitialize(); DebugCheckInitialize();
return _playModeImpl.CreateResourceImporterByFilePaths(filePaths, importerMaxNumber, failedTryAgain); return _fileSystemHost.CreateResourceImporter(options);
}
/// <summary>
/// 创建资源导入器
/// 注意资源信息里需要指定BundleName或BundleGUID
/// </summary>
/// <param name="fileInfos">资源信息列表</param>
/// <param name="importerMaxNumber">同时导入的最大文件数</param>
/// <param name="failedTryAgain">导入失败的重试次数</param>
public ResourceImporterOperation CreateResourceImporter(ImportFileInfo[] fileInfos, int importerMaxNumber, int failedTryAgain)
{
DebugCheckInitialize();
return _playModeImpl.CreateResourceImporterByFileInfos(fileInfos, importerMaxNumber, failedTryAgain);
} }
#endregion #endregion
#region #region
private AssetInfo ConvertLocationToAssetInfo(string location, System.Type assetType) internal AssetInfo ConvertLocationToAssetInfo(string location, System.Type assetType)
{ {
return _playModeImpl.ActiveManifest.ConvertLocationToAssetInfo(location, assetType); return _fileSystemHost.ActiveManifest.ConvertLocationToAssetInfo(location, assetType);
} }
private AssetInfo ConvertAssetGUIDToAssetInfo(string assetGUID, System.Type assetType) internal AssetInfo ConvertAssetGUIDToAssetInfo(string assetGUID, System.Type assetType)
{ {
return _playModeImpl.ActiveManifest.ConvertAssetGUIDToAssetInfo(assetGUID, assetType); return _fileSystemHost.ActiveManifest.ConvertAssetGUIDToAssetInfo(assetGUID, assetType);
} }
#endregion #endregion
@@ -1060,7 +932,7 @@ namespace YooAsset
if (checkActiveManifest) if (checkActiveManifest)
{ {
if (_playModeImpl.ActiveManifest == null) if (_fileSystemHost.ActiveManifest == null)
throw new YooPackageException(PackageName, "Can not found active package manifest !"); throw new YooPackageException(PackageName, "Can not found active package manifest !");
} }
} }

View File

@@ -3,7 +3,7 @@ using UnityEngine;
namespace YooAsset namespace YooAsset
{ {
public struct DecryptFileInfo public struct DecryptBundleInfo
{ {
/// <summary> /// <summary>
/// 资源包名称 /// 资源包名称
@@ -20,13 +20,8 @@ namespace YooAsset
/// </summary> /// </summary>
public uint FileLoadCRC; public uint FileLoadCRC;
} }
public struct DecryptResult public struct DecryptAsyncResult
{ {
/// <summary>
/// 资源包对象
/// </summary>
public AssetBundle Result;
/// <summary> /// <summary>
/// 异步请求句柄 /// 异步请求句柄
/// </summary> /// </summary>
@@ -38,18 +33,30 @@ namespace YooAsset
/// </summary> /// </summary>
public Stream ManagedStream; public Stream ManagedStream;
} }
public struct DecryptSyncResult
{
/// <summary>
/// 资源包对象
/// </summary>
public AssetBundle Result;
public interface IDecryptionServices /// <summary>
/// 托管流对象
/// 注意:流对象在资源包对象释放的时候会自动释放
/// </summary>
public Stream ManagedStream;
}
public interface IBundleDecryptionServices
{ {
/// <summary> /// <summary>
/// 同步方式获取解密的资源包 /// 同步方式获取解密的资源包
/// </summary> /// </summary>
DecryptResult LoadAssetBundle(DecryptFileInfo fileInfo); DecryptSyncResult LoadAssetBundleSync(DecryptBundleInfo bundleInfo);
/// <summary> /// <summary>
/// 异步方式获取解密的资源包 /// 异步方式获取解密的资源包
/// </summary> /// </summary>
DecryptResult LoadAssetBundleAsync(DecryptFileInfo fileInfo); DecryptAsyncResult LoadAssetBundleAsync(DecryptBundleInfo bundleInfo);
/// <summary> /// <summary>
/// 后备方式获取解密的资源包 /// 后备方式获取解密的资源包
@@ -57,16 +64,45 @@ namespace YooAsset
/// 说明建议通过LoadFromMemory()方法加载资源包作为保底机制。 /// 说明建议通过LoadFromMemory()方法加载资源包作为保底机制。
/// issues : https://github.com/tuyoogame/YooAsset/issues/562 /// issues : https://github.com/tuyoogame/YooAsset/issues/562
/// </summary> /// </summary>
DecryptResult LoadAssetBundleFallback(DecryptFileInfo fileInfo); DecryptSyncResult LoadAssetBundleFallback(DecryptBundleInfo bundleInfo);
/// <summary> /// <summary>
/// 获取解密的字节数据 /// 获取解密的字节数据
/// </summary> /// </summary>
byte[] ReadFileData(DecryptFileInfo fileInfo); byte[] ReadFileData(DecryptBundleInfo bundleInfo);
/// <summary> /// <summary>
/// 获取解密的文本数据 /// 获取解密的文本数据
/// </summary> /// </summary>
string ReadFileText(DecryptFileInfo fileInfo); string ReadFileText(DecryptBundleInfo bundleInfo);
}
public struct WebDecryptBundleInfo
{
/// <summary>
/// 资源包名称
/// </summary>
public string BundleName;
/// <summary>
/// Unity引擎用于内容校验的CRC
/// </summary>
public uint FileLoadCRC;
/// <summary>
/// 文件字节数据
/// </summary>
public byte[] FileData;
}
public struct WebDecryptSyncResult
{
/// <summary>
/// 资源包对象
/// </summary>
public AssetBundle Result;
}
public interface IWebBundleDecryptionServices
{
WebDecryptSyncResult LoadAssetBundleSync(WebDecryptBundleInfo bundleInfo);
} }
} }

View File

@@ -1,7 +1,7 @@
 
namespace YooAsset namespace YooAsset
{ {
public struct EncryptFileInfo public struct EncryptBundleInfo
{ {
/// <summary> /// <summary>
/// 资源包名称 /// 资源包名称
@@ -25,9 +25,8 @@ namespace YooAsset
/// </summary> /// </summary>
public byte[] EncryptedData; public byte[] EncryptedData;
} }
public interface IBundleEncryptionServices
public interface IEncryptionServices
{ {
EncryptResult Encrypt(EncryptFileInfo fileInfo); EncryptResult Encrypt(EncryptBundleInfo bundleInfo);
} }
} }

View File

@@ -15,7 +15,6 @@ namespace YooAsset
{ {
_isInitialize = false; _isInitialize = false;
_packages.Clear(); _packages.Clear();
_defaultPackage = null;
} }
#endif #endif

View File

@@ -1,619 +0,0 @@
using System;
using System.Diagnostics;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.SceneManagement;
namespace YooAsset
{
public static partial class YooAssets
{
private static ResourcePackage _defaultPackage;
/// <summary>
/// 设置默认的资源包
/// </summary>
public static void SetDefaultPackage(ResourcePackage package)
{
_defaultPackage = package;
}
#region
/// <summary>
/// 是否需要从远端更新下载
/// </summary>
/// <param name="location">资源的定位地址</param>
public static bool IsNeedDownloadFromRemote(string location)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.IsNeedDownloadFromRemote(location);
}
/// <summary>
/// 是否需要从远端更新下载
/// </summary>
/// <param name="location">资源的定位地址</param>
public static bool IsNeedDownloadFromRemote(AssetInfo assetInfo)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.IsNeedDownloadFromRemote(assetInfo);
}
/// <summary>
/// 获取资源信息列表
/// </summary>
/// <param name="tag">资源标签</param>
public static AssetInfo[] GetAssetInfos(string tag)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.GetAssetInfos(tag);
}
/// <summary>
/// 获取资源信息列表
/// </summary>
/// <param name="tags">资源标签列表</param>
public static AssetInfo[] GetAssetInfos(string[] tags)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.GetAssetInfos(tags);
}
/// <summary>
/// 获取资源信息
/// </summary>
/// <param name="location">资源的定位地址</param>
public static AssetInfo GetAssetInfo(string location)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.GetAssetInfo(location);
}
/// <summary>
/// 获取资源信息
/// </summary>
/// <param name="location">资源的定位地址</param>
/// <param name="type">资源类型</param>
public static AssetInfo GetAssetInfo(string location, System.Type type)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.GetAssetInfo(location, type);
}
/// <summary>
/// 获取资源信息
/// </summary>
/// <param name="assetGUID">资源GUID</param>
public static AssetInfo GetAssetInfoByGUID(string assetGUID)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.GetAssetInfoByGUID(assetGUID);
}
/// <summary>
/// 获取资源信息
/// </summary>
/// <param name="assetGUID">资源GUID</param>
/// <param name="type">资源类型</param>
public static AssetInfo GetAssetInfoByGUID(string assetGUID, System.Type type)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.GetAssetInfoByGUID(assetGUID, type);
}
/// <summary>
/// 检查资源定位地址是否有效
/// </summary>
/// <param name="location">资源的定位地址</param>
public static bool CheckLocationValid(string location)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.CheckLocationValid(location);
}
#endregion
#region
/// <summary>
/// 同步加载原生文件
/// </summary>
/// <param name="assetInfo">资源信息</param>
public static RawFileHandle LoadRawFileSync(AssetInfo assetInfo)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadRawFileSync(assetInfo);
}
/// <summary>
/// 同步加载原生文件
/// </summary>
/// <param name="location">资源的定位地址</param>
public static RawFileHandle LoadRawFileSync(string location)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadRawFileSync(location);
}
/// <summary>
/// 异步加载原生文件
/// </summary>
/// <param name="assetInfo">资源信息</param>
public static RawFileHandle LoadRawFileAsync(AssetInfo assetInfo, uint priority = 0)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadRawFileAsync(assetInfo, priority);
}
/// <summary>
/// 异步加载原生文件
/// </summary>
/// <param name="location">资源的定位地址</param>
public static RawFileHandle LoadRawFileAsync(string location, uint priority = 0)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadRawFileAsync(location, priority);
}
#endregion
#region
/// <summary>
/// 同步加载场景
/// </summary>
/// <param name="location">场景的定位地址</param>
/// <param name="sceneMode">场景加载模式</param>
/// <param name="physicsMode">场景物理模式</param>
public static SceneHandle LoadSceneSync(string location, LoadSceneMode sceneMode = LoadSceneMode.Single, LocalPhysicsMode physicsMode = LocalPhysicsMode.None)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadSceneSync(location, sceneMode, physicsMode);
}
/// <summary>
/// 同步加载场景
/// </summary>
/// <param name="assetInfo">场景的资源信息</param>
/// <param name="sceneMode">场景加载模式</param>
/// <param name="physicsMode">场景物理模式</param>
public static SceneHandle LoadSceneSync(AssetInfo assetInfo, LoadSceneMode sceneMode = LoadSceneMode.Single, LocalPhysicsMode physicsMode = LocalPhysicsMode.None)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadSceneSync(assetInfo, sceneMode, physicsMode);
}
/// <summary>
/// 异步加载场景
/// </summary>
/// <param name="location">场景的定位地址</param>
/// <param name="sceneMode">场景加载模式</param>
/// <param name="physicsMode">场景物理模式</param>
/// <param name="suspendLoad">场景加载到90%自动挂起</param>
/// <param name="priority">优先级</param>
public static SceneHandle LoadSceneAsync(string location, LoadSceneMode sceneMode = LoadSceneMode.Single, LocalPhysicsMode physicsMode = LocalPhysicsMode.None, bool suspendLoad = false, uint priority = 100)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadSceneAsync(location, sceneMode, physicsMode, suspendLoad, priority);
}
/// <summary>
/// 异步加载场景
/// </summary>
/// <param name="assetInfo">场景的资源信息</param>
/// <param name="sceneMode">场景加载模式</param>
/// <param name="physicsMode">场景物理模式</param>
/// <param name="suspendLoad">场景加载到90%自动挂起</param>
/// <param name="priority">优先级</param>
public static SceneHandle LoadSceneAsync(AssetInfo assetInfo, LoadSceneMode sceneMode = LoadSceneMode.Single, LocalPhysicsMode physicsMode = LocalPhysicsMode.None, bool suspendLoad = false, uint priority = 100)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadSceneAsync(assetInfo, sceneMode, physicsMode, suspendLoad, priority);
}
#endregion
#region
/// <summary>
/// 同步加载资源对象
/// </summary>
/// <param name="assetInfo">资源信息</param>
public static AssetHandle LoadAssetSync(AssetInfo assetInfo)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadAssetSync(assetInfo);
}
/// <summary>
/// 同步加载资源对象
/// </summary>
/// <typeparam name="TObject">资源类型</typeparam>
/// <param name="location">资源的定位地址</param>
public static AssetHandle LoadAssetSync<TObject>(string location) where TObject : UnityEngine.Object
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadAssetSync<TObject>(location);
}
/// <summary>
/// 同步加载资源对象
/// </summary>
/// <param name="location">资源的定位地址</param>
/// <param name="type">资源类型</param>
public static AssetHandle LoadAssetSync(string location, System.Type type)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadAssetSync(location, type);
}
/// <summary>
/// 同步加载资源对象
/// </summary>
/// <param name="location">资源的定位地址</param>
public static AssetHandle LoadAssetSync(string location)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadAssetSync(location);
}
/// <summary>
/// 异步加载资源对象
/// </summary>
/// <param name="assetInfo">资源信息</param>
public static AssetHandle LoadAssetAsync(AssetInfo assetInfo, uint priority = 0)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadAssetAsync(assetInfo, priority);
}
/// <summary>
/// 异步加载资源对象
/// </summary>
/// <typeparam name="TObject">资源类型</typeparam>
/// <param name="location">资源的定位地址</param>
public static AssetHandle LoadAssetAsync<TObject>(string location, uint priority = 0) where TObject : UnityEngine.Object
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadAssetAsync<TObject>(location, priority);
}
/// <summary>
/// 异步加载资源对象
/// </summary>
/// <param name="location">资源的定位地址</param>
/// <param name="type">资源类型</param>
public static AssetHandle LoadAssetAsync(string location, System.Type type, uint priority = 0)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadAssetAsync(location, type, priority);
}
/// <summary>
/// 异步加载资源对象
/// </summary>
/// <param name="location">资源的定位地址</param>
public static AssetHandle LoadAssetAsync(string location, uint priority = 0)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadAssetAsync(location, priority);
}
#endregion
#region
/// <summary>
/// 同步加载子资源对象
/// </summary>
/// <param name="assetInfo">资源信息</param>
public static SubAssetsHandle LoadSubAssetsSync(AssetInfo assetInfo)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadSubAssetsSync(assetInfo);
}
/// <summary>
/// 同步加载子资源对象
/// </summary>
/// <typeparam name="TObject">资源类型</typeparam>
/// <param name="location">资源的定位地址</param>
public static SubAssetsHandle LoadSubAssetsSync<TObject>(string location) where TObject : UnityEngine.Object
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadSubAssetsSync<TObject>(location);
}
/// <summary>
/// 同步加载子资源对象
/// </summary>
/// <param name="location">资源的定位地址</param>
/// <param name="type">子对象类型</param>
public static SubAssetsHandle LoadSubAssetsSync(string location, System.Type type)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadSubAssetsSync(location, type);
}
/// <summary>
/// 同步加载子资源对象
/// </summary>
/// <param name="location">资源的定位地址</param>
public static SubAssetsHandle LoadSubAssetsSync(string location)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadSubAssetsSync(location);
}
/// <summary>
/// 异步加载子资源对象
/// </summary>
/// <param name="assetInfo">资源信息</param>
public static SubAssetsHandle LoadSubAssetsAsync(AssetInfo assetInfo, uint priority = 0)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadSubAssetsAsync(assetInfo, priority);
}
/// <summary>
/// 异步加载子资源对象
/// </summary>
/// <typeparam name="TObject">资源类型</typeparam>
/// <param name="location">资源的定位地址</param>
public static SubAssetsHandle LoadSubAssetsAsync<TObject>(string location, uint priority = 0) where TObject : UnityEngine.Object
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadSubAssetsAsync<TObject>(location, priority);
}
/// <summary>
/// 异步加载子资源对象
/// </summary>
/// <param name="location">资源的定位地址</param>
/// <param name="type">子对象类型</param>
public static SubAssetsHandle LoadSubAssetsAsync(string location, System.Type type, uint priority = 0)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadSubAssetsAsync(location, type, priority);
}
/// <summary>
/// 异步加载子资源对象
/// </summary>
/// <param name="location">资源的定位地址</param>
public static SubAssetsHandle LoadSubAssetsAsync(string location, uint priority = 0)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadSubAssetsAsync(location, priority);
}
#endregion
#region
/// <summary>
/// 同步加载资源包内所有资源对象
/// </summary>
/// <param name="assetInfo">资源信息</param>
public static AllAssetsHandle LoadAllAssetsSync(AssetInfo assetInfo)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadAllAssetsSync(assetInfo);
}
/// <summary>
/// 同步加载资源包内所有资源对象
/// </summary>
/// <typeparam name="TObject">资源类型</typeparam>
/// <param name="location">资源的定位地址</param>
public static AllAssetsHandle LoadAllAssetsSync<TObject>(string location) where TObject : UnityEngine.Object
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadAllAssetsSync<TObject>(location);
}
/// <summary>
/// 同步加载资源包内所有资源对象
/// </summary>
/// <param name="location">资源的定位地址</param>
/// <param name="type">子对象类型</param>
public static AllAssetsHandle LoadAllAssetsSync(string location, System.Type type)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadAllAssetsSync(location, type);
}
/// <summary>
/// 同步加载资源包内所有资源对象
/// </summary>
/// <param name="location">资源的定位地址</param>
public static AllAssetsHandle LoadAllAssetsSync(string location)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadAllAssetsSync(location);
}
/// <summary>
/// 异步加载资源包内所有资源对象
/// </summary>
/// <param name="assetInfo">资源信息</param>
public static AllAssetsHandle LoadAllAssetsAsync(AssetInfo assetInfo, uint priority = 0)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadAllAssetsAsync(assetInfo, priority);
}
/// <summary>
/// 异步加载资源包内所有资源对象
/// </summary>
/// <typeparam name="TObject">资源类型</typeparam>
/// <param name="location">资源的定位地址</param>
public static AllAssetsHandle LoadAllAssetsAsync<TObject>(string location, uint priority = 0) where TObject : UnityEngine.Object
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadAllAssetsAsync<TObject>(location, priority);
}
/// <summary>
/// 异步加载资源包内所有资源对象
/// </summary>
/// <param name="location">资源的定位地址</param>
/// <param name="type">子对象类型</param>
public static AllAssetsHandle LoadAllAssetsAsync(string location, System.Type type, uint priority = 0)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadAllAssetsAsync(location, type, priority);
}
/// <summary>
/// 异步加载资源包内所有资源对象
/// </summary>
/// <param name="location">资源的定位地址</param>
public static AllAssetsHandle LoadAllAssetsAsync(string location, uint priority = 0)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.LoadAllAssetsAsync(location, priority);
}
#endregion
#region
/// <summary>
/// 创建资源下载器,用于下载当前资源版本所有的资源包文件
/// </summary>
/// <param name="downloadingMaxNumber">同时下载的最大文件数</param>
/// <param name="failedTryAgain">下载失败的重试次数</param>
public static ResourceDownloaderOperation CreateResourceDownloader(int downloadingMaxNumber, int failedTryAgain)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.CreateResourceDownloader(downloadingMaxNumber, failedTryAgain);
}
/// <summary>
/// 创建资源下载器,用于下载指定的资源标签关联的资源包文件
/// </summary>
/// <param name="tag">资源标签</param>
/// <param name="downloadingMaxNumber">同时下载的最大文件数</param>
/// <param name="failedTryAgain">下载失败的重试次数</param>
public static ResourceDownloaderOperation CreateResourceDownloader(string tag, int downloadingMaxNumber, int failedTryAgain)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.CreateResourceDownloader(new string[] { tag }, downloadingMaxNumber, failedTryAgain);
}
/// <summary>
/// 创建资源下载器,用于下载指定的资源标签列表关联的资源包文件
/// </summary>
/// <param name="tags">资源标签列表</param>
/// <param name="downloadingMaxNumber">同时下载的最大文件数</param>
/// <param name="failedTryAgain">下载失败的重试次数</param>
public static ResourceDownloaderOperation CreateResourceDownloader(string[] tags, int downloadingMaxNumber, int failedTryAgain)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.CreateResourceDownloader(tags, downloadingMaxNumber, failedTryAgain);
}
/// <summary>
/// 创建资源下载器,用于下载指定的资源依赖的资源包文件
/// </summary>
/// <param name="location">资源定位地址</param>
/// <param name="downloadingMaxNumber">同时下载的最大文件数</param>
/// <param name="failedTryAgain">下载失败的重试次数</param>
public static ResourceDownloaderOperation CreateBundleDownloader(string location, int downloadingMaxNumber, int failedTryAgain)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.CreateBundleDownloader(location, downloadingMaxNumber, failedTryAgain);
}
/// <summary>
/// 创建资源下载器,用于下载指定的资源列表依赖的资源包文件
/// </summary>
/// <param name="locations">资源定位地址列表</param>
/// <param name="downloadingMaxNumber">同时下载的最大文件数</param>
/// <param name="failedTryAgain">下载失败的重试次数</param>
public static ResourceDownloaderOperation CreateBundleDownloader(string[] locations, int downloadingMaxNumber, int failedTryAgain)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.CreateBundleDownloader(locations, downloadingMaxNumber, failedTryAgain);
}
/// <summary>
/// 创建资源下载器,用于下载指定的资源依赖的资源包文件
/// </summary>
/// <param name="assetInfo">资源信息</param>
/// <param name="downloadingMaxNumber">同时下载的最大文件数</param>
/// <param name="failedTryAgain">下载失败的重试次数</param>
public static ResourceDownloaderOperation CreateBundleDownloader(AssetInfo assetInfo, int downloadingMaxNumber, int failedTryAgain)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.CreateBundleDownloader(assetInfo, downloadingMaxNumber, failedTryAgain);
}
/// <summary>
/// 创建资源下载器,用于下载指定的资源列表依赖的资源包文件
/// </summary>
/// <param name="assetInfos">资源信息列表</param>
/// <param name="downloadingMaxNumber">同时下载的最大文件数</param>
/// <param name="failedTryAgain">下载失败的重试次数</param>
public static ResourceDownloaderOperation CreateBundleDownloader(AssetInfo[] assetInfos, int downloadingMaxNumber, int failedTryAgain)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.CreateBundleDownloader(assetInfos, downloadingMaxNumber, failedTryAgain);
}
#endregion
#region
/// <summary>
/// 创建内置资源解压器,用于解压当前资源版本所有的资源包文件
/// </summary>
/// <param name="unpackingMaxNumber">同时解压的最大文件数</param>
/// <param name="failedTryAgain">解压失败的重试次数</param>
public static ResourceUnpackerOperation CreateResourceUnpacker(int unpackingMaxNumber, int failedTryAgain)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.CreateResourceUnpacker(unpackingMaxNumber, failedTryAgain);
}
/// <summary>
/// 创建内置资源解压器,用于解压指定的资源标签关联的资源包文件
/// </summary>
/// <param name="tag">资源标签</param>
/// <param name="unpackingMaxNumber">同时解压的最大文件数</param>
/// <param name="failedTryAgain">解压失败的重试次数</param>
public static ResourceUnpackerOperation CreateResourceUnpacker(string tag, int unpackingMaxNumber, int failedTryAgain)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.CreateResourceUnpacker(tag, unpackingMaxNumber, failedTryAgain);
}
/// <summary>
/// 创建内置资源解压器,用于解压指定的资源标签列表关联的资源包文件
/// </summary>
/// <param name="tags">资源标签列表</param>
/// <param name="unpackingMaxNumber">同时解压的最大文件数</param>
/// <param name="failedTryAgain">解压失败的重试次数</param>
public static ResourceUnpackerOperation CreateResourceUnpacker(string[] tags, int unpackingMaxNumber, int failedTryAgain)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.CreateResourceUnpacker(tags, unpackingMaxNumber, failedTryAgain);
}
#endregion
#region
/// <summary>
/// 创建资源导入器
/// 注意:资源文件名称必须和资源服务器部署的文件名称一致!
/// </summary>
/// <param name="filePaths">资源路径列表</param>
/// <param name="importerMaxNumber">同时导入的最大文件数</param>
/// <param name="failedTryAgain">导入失败的重试次数</param>
public static ResourceImporterOperation CreateResourceImporter(string[] filePaths, int importerMaxNumber, int failedTryAgain)
{
DebugCheckDefaultPackageValid();
return _defaultPackage.CreateResourceImporter(filePaths, importerMaxNumber, failedTryAgain);
}
#endregion
#region
[Conditional("DEBUG")]
private static void DebugCheckDefaultPackageValid()
{
if (_defaultPackage == null)
throw new YooInitializeException($"Default package is null. Please use {nameof(YooAssets.SetDefaultPackage)} !");
}
#endregion
}
}

View File

@@ -64,7 +64,7 @@ public class T2_TestBuldinFileSystem : IPrebuildSetup, IPostBuildCleanup
var manifestServices = new TestRestoreManifest(); var manifestServices = new TestRestoreManifest();
initParams.BuildinFileSystemParameters = FileSystemParameters.CreateDefaultBuildinFileSystemParameters(fileDecryption, packageRoot); initParams.BuildinFileSystemParameters = FileSystemParameters.CreateDefaultBuildinFileSystemParameters(fileDecryption, packageRoot);
initParams.BuildinFileSystemParameters.AddParameter(FileSystemParametersDefine.DISABLE_CATALOG_FILE, true); initParams.BuildinFileSystemParameters.AddParameter(FileSystemParametersDefine.DISABLE_CATALOG_FILE, true);
initParams.BuildinFileSystemParameters.AddParameter(FileSystemParametersDefine.MANIFEST_SERVICES, manifestServices); initParams.BuildinFileSystemParameters.AddParameter(FileSystemParametersDefine.MANIFEST_RESTORE_SERVICES, manifestServices);
var initializeOp = package.InitializePackageAsync(initParams); var initializeOp = package.InitializePackageAsync(initParams);
yield return initializeOp; yield return initializeOp;
if (initializeOp.Status != EOperationStatus.Succeed) if (initializeOp.Status != EOperationStatus.Succeed)

View File

@@ -52,7 +52,7 @@ public class T3_TestCacheFileSystem : IPrebuildSetup, IPostBuildCleanup
var remoteServices = new TestRemoteServices(hostServerIP); var remoteServices = new TestRemoteServices(hostServerIP);
initParams.BuildinFileSystemParameters = null; initParams.BuildinFileSystemParameters = null;
initParams.CacheFileSystemParameters = FileSystemParameters.CreateDefaultCacheFileSystemParameters(remoteServices, fileDecryption); initParams.CacheFileSystemParameters = FileSystemParameters.CreateDefaultCacheFileSystemParameters(remoteServices, fileDecryption);
initParams.CacheFileSystemParameters.AddParameter(FileSystemParametersDefine.MANIFEST_SERVICES, manifestServices); initParams.CacheFileSystemParameters.AddParameter(FileSystemParametersDefine.MANIFEST_RESTORE_SERVICES, manifestServices);
var initializeOp = package.InitializePackageAsync(initParams); var initializeOp = package.InitializePackageAsync(initParams);
yield return initializeOp; yield return initializeOp;
if (initializeOp.Status != EOperationStatus.Succeed) if (initializeOp.Status != EOperationStatus.Succeed)