update file system

重构运行时核心代码
This commit is contained in:
何冠峰
2024-12-24 18:23:19 +08:00
parent 6d6fd3af2c
commit 6254d00bb5
67 changed files with 1811 additions and 204 deletions

View File

@@ -13,7 +13,6 @@ namespace YooAsset
internal class DefaultCacheFileSystem : IFileSystem, ICacheSystem
{
protected readonly Dictionary<string, CacheWrapper> _wrappers = new Dictionary<string, CacheWrapper>(10000);
protected readonly Dictionary<string, Stream> _loadedStream = new Dictionary<string, Stream>(10000);
protected readonly Dictionary<string, string> _dataFilePaths = new Dictionary<string, string>(10000);
protected readonly Dictionary<string, string> _infoFilePaths = new Dictionary<string, string>(10000);
protected readonly Dictionary<string, string> _tempFilePaths = new Dictionary<string, string>(10000);
@@ -67,11 +66,6 @@ namespace YooAsset
/// </summary>
public bool AppendFileExtension { private set; get; } = false;
/// <summary>
/// 自定义参数:原生文件构建管线
/// </summary>
public bool RawFileBuildPipeline { private set; get; } = false;
/// <summary>
/// 自定义参数:最大并发连接数
/// </summary>
@@ -154,7 +148,13 @@ namespace YooAsset
}
public virtual FSLoadBundleOperation LoadBundleFile(PackageBundle bundle)
{
if (RawFileBuildPipeline)
if (bundle.BundleType == (int)EBuildBundleType.AssetBundle)
{
var operation = new DCFSLoadAssetBundleOperation(this, bundle);
OperationSystem.StartOperation(PackageName, operation);
return operation;
}
else if (bundle.BundleType == (int)EBuildBundleType.RawBundle)
{
var operation = new DCFSLoadRawBundleOperation(this, bundle);
OperationSystem.StartOperation(PackageName, operation);
@@ -162,30 +162,12 @@ namespace YooAsset
}
else
{
var operation = new DCFSLoadAssetBundleOperation(this, bundle);
string error = $"{nameof(DefaultCacheFileSystem)} not support load bundle type : {bundle.BundleType}";
var operation = new FSLoadBundleCompleteOperation(error);
OperationSystem.StartOperation(PackageName, operation);
return operation;
}
}
public virtual void UnloadBundleFile(PackageBundle bundle, object result)
{
AssetBundle assetBundle = result as AssetBundle;
if (assetBundle == null)
return;
if (assetBundle != null)
assetBundle.Unload(true);
if (_loadedStream.TryGetValue(bundle.BundleGUID, out Stream managedStream))
{
if (managedStream != null)
{
managedStream.Close();
managedStream.Dispose();
}
_loadedStream.Remove(bundle.BundleGUID);
}
}
public virtual void SetParameter(string name, object value)
{
@@ -201,10 +183,6 @@ namespace YooAsset
{
AppendFileExtension = (bool)value;
}
else if (name == FileSystemParametersDefine.RAW_FILE_BUILD_PIPELINE)
{
RawFileBuildPipeline = (bool)value;
}
else if (name == FileSystemParametersDefine.DOWNLOAD_MAX_CONCURRENCY)
{
DownloadMaxConcurrency = (int)value;
@@ -276,7 +254,11 @@ namespace YooAsset
return Exists(bundle) == false;
}
public virtual byte[] ReadFileData(PackageBundle bundle)
public virtual string GetBundleFilePath(PackageBundle bundle)
{
return GetCacheFileLoadPath(bundle);
}
public virtual byte[] ReadBundleFileData(PackageBundle bundle)
{
if (Exists(bundle) == false)
return null;
@@ -304,7 +286,7 @@ namespace YooAsset
return FileUtility.ReadAllBytes(filePath);
}
}
public virtual string ReadFileText(PackageBundle bundle)
public virtual string ReadBundleFileText(PackageBundle bundle)
{
if (Exists(bundle) == false)
return null;
@@ -523,7 +505,7 @@ namespace YooAsset
/// <summary>
/// 加载加密资源文件
/// </summary>
public AssetBundle LoadEncryptedAssetBundle(PackageBundle bundle)
public DecryptResult LoadEncryptedAssetBundle(PackageBundle bundle)
{
string filePath = GetCacheFileLoadPath(bundle);
var fileInfo = new DecryptFileInfo()
@@ -532,16 +514,13 @@ namespace YooAsset
FileLoadCRC = bundle.UnityCRC,
FileLoadPath = filePath,
};
var assetBundle = DecryptionServices.LoadAssetBundle(fileInfo, out var managedStream);
_loadedStream.Add(bundle.BundleGUID, managedStream);
return assetBundle;
return DecryptionServices.LoadAssetBundle(fileInfo);
}
/// <summary>
/// 加载加密资源文件
/// </summary>
public AssetBundleCreateRequest LoadEncryptedAssetBundleAsync(PackageBundle bundle)
public DecryptResult LoadEncryptedAssetBundleAsync(PackageBundle bundle)
{
string filePath = GetCacheFileLoadPath(bundle);
var fileInfo = new DecryptFileInfo()
@@ -550,10 +529,7 @@ namespace YooAsset
FileLoadCRC = bundle.UnityCRC,
FileLoadPath = filePath,
};
var createRequest = DecryptionServices.LoadAssetBundleAsync(fileInfo, out var managedStream);
_loadedStream.Add(bundle.BundleGUID, managedStream);
return createRequest;
return DecryptionServices.LoadAssetBundleAsync(fileInfo);
}
#endregion
}