diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultBuildinFileSystem/DefaultBuildinFileSystem.cs b/Assets/YooAsset/Runtime/FileSystem/DefaultBuildinFileSystem/DefaultBuildinFileSystem.cs
index b715faf..ac439b1 100644
--- a/Assets/YooAsset/Runtime/FileSystem/DefaultBuildinFileSystem/DefaultBuildinFileSystem.cs
+++ b/Assets/YooAsset/Runtime/FileSystem/DefaultBuildinFileSystem/DefaultBuildinFileSystem.cs
@@ -128,6 +128,44 @@ namespace YooAsset
string buidlinFilePath = GetBuildinFileLoadPath(bundle);
return UnpackFileSystem.DownloadFileAsync(bundle, buidlinFilePath, failedTryAgain, timeout);
}
+ public virtual FSLoadBundleOperation LoadBundleFile(PackageBundle bundle)
+ {
+ if (RawFileBuildPipeline)
+ {
+ var operation = new DBFSLoadRawBundleOperation(this, bundle);
+ OperationSystem.StartOperation(PackageName, operation);
+ return operation;
+ }
+ else
+ {
+ var operation = new DBFSLoadAssetBundleOperation(this, bundle);
+ OperationSystem.StartOperation(PackageName, operation);
+ return operation;
+ }
+ }
+ public virtual void UnloadBundleFile(PackageBundle bundle, object result)
+ {
+ AssetBundle assetBundle = result as AssetBundle;
+ if (assetBundle == null)
+ return;
+
+ if (UnpackFileSystem.Exists(bundle))
+ {
+ UnpackFileSystem.UnloadBundleFile(bundle, assetBundle);
+ }
+ else
+ {
+ if (assetBundle != null)
+ assetBundle.Unload(true);
+
+ if (_loadedStream.TryGetValue(bundle.BundleGUID, out Stream managedStream))
+ {
+ managedStream.Close();
+ managedStream.Dispose();
+ _loadedStream.Remove(bundle.BundleGUID);
+ }
+ }
+ }
public virtual void SetParameter(string name, object value)
{
@@ -170,26 +208,17 @@ namespace YooAsset
public virtual bool Belong(PackageBundle bundle)
{
- return Belong(bundle.BundleGUID);
- }
- public virtual bool Belong(string bundleGUID)
- {
- return _wrappers.ContainsKey(bundleGUID);
+ return _wrappers.ContainsKey(bundle.BundleGUID);
}
public virtual bool Exists(PackageBundle bundle)
{
- return Exists(bundle.BundleGUID);
+ return _wrappers.ContainsKey(bundle.BundleGUID);
}
- public virtual bool Exists(string bundleGUID)
- {
- return _wrappers.ContainsKey(bundleGUID);
- }
-
- public virtual bool CheckNeedDownload(PackageBundle bundle)
+ public virtual bool NeedDownload(PackageBundle bundle)
{
return false;
}
- public virtual bool CheckNeedUnpack(PackageBundle bundle)
+ public virtual bool NeedUnpack(PackageBundle bundle)
{
if (Belong(bundle) == false)
return false;
@@ -200,76 +229,11 @@ namespace YooAsset
return false;
#endif
}
- public virtual bool CheckNeedImport(PackageBundle bundle)
+ public virtual bool NeedImport(PackageBundle bundle)
{
return false;
}
- public virtual bool WriteFile(PackageBundle bundle, string copyPath)
- {
- return UnpackFileSystem.WriteFile(bundle, copyPath);
- }
- public virtual bool DeleteFile(PackageBundle bundle)
- {
- return UnpackFileSystem.DeleteFile(bundle);
- }
- public virtual bool DeleteFile(string bundleGUID)
- {
- return UnpackFileSystem.DeleteFile(bundleGUID);
- }
- public virtual EFileVerifyResult VerifyFile(PackageBundle bundle)
- {
- return UnpackFileSystem.VerifyFile(bundle);
- }
-
- public virtual byte[] ReadFileBytes(PackageBundle bundle)
- {
- throw new System.NotImplementedException();
- }
- public virtual string ReadFileText(PackageBundle bundle)
- {
- throw new System.NotImplementedException();
- }
-
- public virtual FSLoadBundleOperation LoadBundleFile(PackageBundle bundle)
- {
- if (RawFileBuildPipeline)
- {
- var operation = new DBFSLoadRawBundleOperation(this, bundle);
- OperationSystem.StartOperation(PackageName, operation);
- return operation;
- }
- else
- {
- var operation = new DBFSLoadAssetBundleOperation(this, bundle);
- OperationSystem.StartOperation(PackageName, operation);
- return operation;
- }
- }
- public virtual void UnloadBundleFile(PackageBundle bundle, object result)
- {
- AssetBundle assetBundle = result as AssetBundle;
- if (assetBundle == null)
- return;
-
- if (UnpackFileSystem.Exists(bundle))
- {
- UnpackFileSystem.UnloadBundleFile(bundle, assetBundle);
- }
- else
- {
- if (assetBundle != null)
- assetBundle.Unload(true);
-
- if (_loadedStream.TryGetValue(bundle.BundleGUID, out Stream managedStream))
- {
- managedStream.Close();
- managedStream.Dispose();
- _loadedStream.Remove(bundle.BundleGUID);
- }
- }
- }
-
#region 内部方法
protected string GetDefaultRoot()
{
@@ -311,9 +275,9 @@ namespace YooAsset
}
///
- /// 记录缓存信息
+ /// 记录文件信息
///
- public bool Record(string bundleGUID, FileWrapper wrapper)
+ public bool RecordFile(string bundleGUID, FileWrapper wrapper)
{
if (_wrappers.ContainsKey(bundleGUID))
{
diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultBuildinFileSystem/Operation/DBFSInitializeOperation.cs b/Assets/YooAsset/Runtime/FileSystem/DefaultBuildinFileSystem/Operation/DBFSInitializeOperation.cs
index 2e6f392..84d7f83 100644
--- a/Assets/YooAsset/Runtime/FileSystem/DefaultBuildinFileSystem/Operation/DBFSInitializeOperation.cs
+++ b/Assets/YooAsset/Runtime/FileSystem/DefaultBuildinFileSystem/Operation/DBFSInitializeOperation.cs
@@ -170,7 +170,7 @@ namespace YooAsset
if (manifest.TryGetPackageBundleByFileName(fileName, out PackageBundle value))
{
var fileWrapper = new DefaultBuildinFileSystem.FileWrapper(fileName);
- _fileSystem.Record(value.BundleGUID, fileWrapper);
+ _fileSystem.RecordFile(value.BundleGUID, fileWrapper);
}
else
{
diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultBuildinFileSystem/Operation/DBFSLoadBundleOperation.cs b/Assets/YooAsset/Runtime/FileSystem/DefaultBuildinFileSystem/Operation/DBFSLoadBundleOperation.cs
index 75e5042..5ec3b40 100644
--- a/Assets/YooAsset/Runtime/FileSystem/DefaultBuildinFileSystem/Operation/DBFSLoadBundleOperation.cs
+++ b/Assets/YooAsset/Runtime/FileSystem/DefaultBuildinFileSystem/Operation/DBFSLoadBundleOperation.cs
@@ -34,7 +34,7 @@ namespace YooAsset
DownloadProgress = 1f;
DownloadedBytes = _bundle.FileSize;
- if (_fileSystem.CheckNeedUnpack(_bundle))
+ if (_fileSystem.NeedUnpack(_bundle))
{
_steps = ESteps.UnpackAssetBundleFile;
}
@@ -205,7 +205,7 @@ namespace YooAsset
DownloadProgress = 1f;
DownloadedBytes = _bundle.FileSize;
- if (_fileSystem.CheckNeedUnpack(_bundle))
+ if (_fileSystem.NeedUnpack(_bundle))
{
_steps = ESteps.UnpackRawBundleFile;
}
diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultBuildinFileSystem/Operation/internal/LoadBuildinCatalogFileOperation.cs b/Assets/YooAsset/Runtime/FileSystem/DefaultBuildinFileSystem/Operation/internal/LoadBuildinCatalogFileOperation.cs
index 92247a3..58e7870 100644
--- a/Assets/YooAsset/Runtime/FileSystem/DefaultBuildinFileSystem/Operation/internal/LoadBuildinCatalogFileOperation.cs
+++ b/Assets/YooAsset/Runtime/FileSystem/DefaultBuildinFileSystem/Operation/internal/LoadBuildinCatalogFileOperation.cs
@@ -51,7 +51,7 @@ namespace YooAsset
foreach (var wrapper in catalog.Wrappers)
{
var fileWrapper = new DefaultBuildinFileSystem.FileWrapper(wrapper.FileName);
- _fileSystem.Record(wrapper.BundleGUID, fileWrapper);
+ _fileSystem.RecordFile(wrapper.BundleGUID, fileWrapper);
}
YooLogger.Log($"Package '{_fileSystem.PackageName}' catalog files count : {catalog.Wrappers.Count}");
diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultCacheFileSystem/DefaultCacheFileSystem.cs b/Assets/YooAsset/Runtime/FileSystem/DefaultCacheFileSystem/DefaultCacheFileSystem.cs
index 085b9c3..aa737e8 100644
--- a/Assets/YooAsset/Runtime/FileSystem/DefaultCacheFileSystem/DefaultCacheFileSystem.cs
+++ b/Assets/YooAsset/Runtime/FileSystem/DefaultCacheFileSystem/DefaultCacheFileSystem.cs
@@ -197,6 +197,37 @@ namespace YooAsset
}
}
}
+ public virtual FSLoadBundleOperation LoadBundleFile(PackageBundle bundle)
+ {
+ if (RawFileBuildPipeline)
+ {
+ var operation = new DCFSLoadRawBundleOperation(this, bundle);
+ OperationSystem.StartOperation(PackageName, operation);
+ return operation;
+ }
+ else
+ {
+ var operation = new DCFSLoadAssetBundleOperation(this, bundle);
+ 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))
+ {
+ managedStream.Close();
+ managedStream.Dispose();
+ _loadedStream.Remove(bundle.BundleGUID);
+ }
+ }
public virtual void SetParameter(string name, object value)
{
@@ -268,35 +299,26 @@ namespace YooAsset
}
public virtual bool Belong(PackageBundle bundle)
- {
- return Belong(bundle.BundleGUID);
- }
- public virtual bool Belong(string bundleGUID)
{
// 注意:缓存文件系统保底加载!
return true;
}
public virtual bool Exists(PackageBundle bundle)
{
- return Exists(bundle.BundleGUID);
+ return _wrappers.ContainsKey(bundle.BundleGUID);
}
- public virtual bool Exists(string bundleGUID)
- {
- return _wrappers.ContainsKey(bundleGUID);
- }
-
- public virtual bool CheckNeedDownload(PackageBundle bundle)
+ public virtual bool NeedDownload(PackageBundle bundle)
{
if (Belong(bundle) == false)
return false;
return Exists(bundle) == false;
}
- public virtual bool CheckNeedUnpack(PackageBundle bundle)
+ public virtual bool NeedUnpack(PackageBundle bundle)
{
return false;
}
- public virtual bool CheckNeedImport(PackageBundle bundle)
+ public virtual bool NeedImport(PackageBundle bundle)
{
if (Belong(bundle) == false)
return false;
@@ -304,119 +326,6 @@ namespace YooAsset
return Exists(bundle) == false;
}
- public virtual bool WriteFile(PackageBundle bundle, string copyPath)
- {
- if (_wrappers.ContainsKey(bundle.BundleGUID))
- {
- throw new Exception("Should never get here !");
- }
-
- string infoFilePath = GetInfoFilePath(bundle);
- string dataFilePath = GetDataFilePath(bundle);
-
- try
- {
- if (File.Exists(infoFilePath))
- File.Delete(infoFilePath);
- if (File.Exists(dataFilePath))
- File.Delete(dataFilePath);
-
- FileUtility.CreateFileDirectory(dataFilePath);
-
- // 拷贝数据文件
- FileInfo fileInfo = new FileInfo(copyPath);
- fileInfo.CopyTo(dataFilePath);
-
- // 写入文件信息
- WriteInfoFile(infoFilePath, bundle.FileCRC, bundle.FileSize);
- }
- catch (Exception e)
- {
- YooLogger.Error($"Failed to write cache file ! {e.Message}");
- return false;
- }
-
- FileWrapper wrapper = new FileWrapper(infoFilePath, dataFilePath, bundle.FileCRC, bundle.FileSize);
- return Record(bundle.BundleGUID, wrapper);
- }
- public virtual bool DeleteFile(PackageBundle bundle)
- {
- return DeleteFile(bundle.BundleGUID);
- }
- public virtual bool DeleteFile(string bundleGUID)
- {
- if (_wrappers.TryGetValue(bundleGUID, out FileWrapper wrapper))
- {
- try
- {
- string dataFilePath = wrapper.DataFilePath;
- FileInfo fileInfo = new FileInfo(dataFilePath);
- if (fileInfo.Exists)
- fileInfo.Directory.Delete(true);
- _wrappers.Remove(bundleGUID);
- return true;
- }
- catch (Exception e)
- {
- YooLogger.Error($"Failed to delete cache file ! {e.Message}");
- return false;
- }
- }
- else
- {
- return false;
- }
- }
- public virtual EFileVerifyResult VerifyFile(PackageBundle bundle)
- {
- if (_wrappers.TryGetValue(bundle.BundleGUID, out FileWrapper wrapper) == false)
- return EFileVerifyResult.CacheNotFound;
-
- EFileVerifyResult result = FileSystemHelper.FileVerify(wrapper.DataFilePath, wrapper.DataFileSize, wrapper.DataFileCRC, EFileVerifyLevel.High);
- return result;
- }
-
- public virtual byte[] ReadFileBytes(PackageBundle bundle)
- {
- throw new System.NotImplementedException();
- }
- public virtual string ReadFileText(PackageBundle bundle)
- {
- throw new System.NotImplementedException();
- }
-
- public virtual FSLoadBundleOperation LoadBundleFile(PackageBundle bundle)
- {
- if (RawFileBuildPipeline)
- {
- var operation = new DCFSLoadRawBundleOperation(this, bundle);
- OperationSystem.StartOperation(PackageName, operation);
- return operation;
- }
- else
- {
- var operation = new DCFSLoadAssetBundleOperation(this, bundle);
- 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))
- {
- managedStream.Close();
- managedStream.Dispose();
- _loadedStream.Remove(bundle.BundleGUID);
- }
- }
-
#region 内部方法
private readonly BufferWriter _sharedBuffer = new BufferWriter(1024);
public void WriteInfoFile(string filePath, string dataFileCRC, long dataFileSize)
@@ -504,24 +413,21 @@ namespace YooAsset
{
return PathUtility.Combine(_manifestFileRoot, DefaultCacheFileSystemDefine.AppFootPrintFileName);
}
- public void DeleteAllManifestFiles()
+
+ ///
+ /// 是否已经记录了文件
+ ///
+ public bool IsRecordFile(string bundleGUID)
{
- if (Directory.Exists(_manifestFileRoot))
- {
- Directory.Delete(_manifestFileRoot, true);
- }
- }
- public List GetAllCachedBundleGUIDs()
- {
- return _wrappers.Keys.ToList();
+ return _wrappers.ContainsKey(bundleGUID);
}
///
- /// 记录缓存信息
+ /// 记录文件信息
///
- public bool Record(string bundleGUID, FileWrapper wrapper)
+ public bool RecordFile(string bundleGUID, FileWrapper wrapper)
{
- if (Exists(bundleGUID))
+ if (_wrappers.ContainsKey(bundleGUID))
{
YooLogger.Error($"{nameof(DefaultCacheFileSystem)} has element : {bundleGUID}");
return false;
@@ -530,6 +436,104 @@ namespace YooAsset
_wrappers.Add(bundleGUID, wrapper);
return true;
}
+
+ ///
+ /// 验证缓存文件
+ ///
+ public EFileVerifyResult VerifyCacheFile(PackageBundle bundle)
+ {
+ if (_wrappers.TryGetValue(bundle.BundleGUID, out FileWrapper wrapper) == false)
+ return EFileVerifyResult.CacheNotFound;
+
+ EFileVerifyResult result = FileSystemHelper.FileVerify(wrapper.DataFilePath, wrapper.DataFileSize, wrapper.DataFileCRC, EFileVerifyLevel.High);
+ return result;
+ }
+
+ ///
+ /// 写入缓存文件
+ ///
+ public bool WriteCacheFile(PackageBundle bundle, string copyPath)
+ {
+ if (_wrappers.ContainsKey(bundle.BundleGUID))
+ {
+ throw new Exception("Should never get here !");
+ }
+
+ string infoFilePath = GetInfoFilePath(bundle);
+ string dataFilePath = GetDataFilePath(bundle);
+
+ try
+ {
+ if (File.Exists(infoFilePath))
+ File.Delete(infoFilePath);
+ if (File.Exists(dataFilePath))
+ File.Delete(dataFilePath);
+
+ FileUtility.CreateFileDirectory(dataFilePath);
+
+ // 拷贝数据文件
+ FileInfo fileInfo = new FileInfo(copyPath);
+ fileInfo.CopyTo(dataFilePath);
+
+ // 写入文件信息
+ WriteInfoFile(infoFilePath, bundle.FileCRC, bundle.FileSize);
+ }
+ catch (Exception e)
+ {
+ YooLogger.Error($"Failed to write cache file ! {e.Message}");
+ return false;
+ }
+
+ FileWrapper wrapper = new FileWrapper(infoFilePath, dataFilePath, bundle.FileCRC, bundle.FileSize);
+ return RecordFile(bundle.BundleGUID, wrapper);
+ }
+
+ ///
+ /// 删除缓存文件
+ ///
+ public bool DeleteCacheFile(string bundleGUID)
+ {
+ if (_wrappers.TryGetValue(bundleGUID, out FileWrapper wrapper))
+ {
+ try
+ {
+ string dataFilePath = wrapper.DataFilePath;
+ FileInfo fileInfo = new FileInfo(dataFilePath);
+ if (fileInfo.Exists)
+ fileInfo.Directory.Delete(true);
+ _wrappers.Remove(bundleGUID);
+ return true;
+ }
+ catch (Exception e)
+ {
+ YooLogger.Error($"Failed to delete cache file ! {e.Message}");
+ return false;
+ }
+ }
+ else
+ {
+ return false;
+ }
+ }
+
+ ///
+ /// 删除所有清单文件
+ ///
+ public void DeleteAllManifestFiles()
+ {
+ if (Directory.Exists(_manifestFileRoot))
+ {
+ Directory.Delete(_manifestFileRoot, true);
+ }
+ }
+
+ ///
+ /// 获取所有缓存文件GUID
+ ///
+ public List GetAllCachedBundleGUIDs()
+ {
+ return _wrappers.Keys.ToList();
+ }
#endregion
}
}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultCacheFileSystem/Operation/DCFSClearAllBundleFilesOperation.cs b/Assets/YooAsset/Runtime/FileSystem/DefaultCacheFileSystem/Operation/DCFSClearAllBundleFilesOperation.cs
index 351524f..8c0d8bd 100644
--- a/Assets/YooAsset/Runtime/FileSystem/DefaultCacheFileSystem/Operation/DCFSClearAllBundleFilesOperation.cs
+++ b/Assets/YooAsset/Runtime/FileSystem/DefaultCacheFileSystem/Operation/DCFSClearAllBundleFilesOperation.cs
@@ -45,7 +45,7 @@ namespace YooAsset
for (int i = _allBundleGUIDs.Count - 1; i >= 0; i--)
{
string bundleGUID = _allBundleGUIDs[i];
- _fileSystem.DeleteFile(bundleGUID);
+ _fileSystem.DeleteCacheFile(bundleGUID);
_allBundleGUIDs.RemoveAt(i);
if (OperationSystem.IsBusy)
break;
diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultCacheFileSystem/Operation/DCFSClearUnusedBundleFilesOperation.cs b/Assets/YooAsset/Runtime/FileSystem/DefaultCacheFileSystem/Operation/DCFSClearUnusedBundleFilesOperation.cs
index 1dcb721..5036f4f 100644
--- a/Assets/YooAsset/Runtime/FileSystem/DefaultCacheFileSystem/Operation/DCFSClearUnusedBundleFilesOperation.cs
+++ b/Assets/YooAsset/Runtime/FileSystem/DefaultCacheFileSystem/Operation/DCFSClearUnusedBundleFilesOperation.cs
@@ -47,7 +47,7 @@ namespace YooAsset
for (int i = _unusedBundleGUIDs.Count - 1; i >= 0; i--)
{
string bundleGUID = _unusedBundleGUIDs[i];
- _fileSystem.DeleteFile(bundleGUID);
+ _fileSystem.DeleteCacheFile(bundleGUID);
_unusedBundleGUIDs.RemoveAt(i);
if (OperationSystem.IsBusy)
break;
diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultCacheFileSystem/Operation/DCFSDownloadFileOperation.cs b/Assets/YooAsset/Runtime/FileSystem/DefaultCacheFileSystem/Operation/DCFSDownloadFileOperation.cs
index c27d334..7f6cf81 100644
--- a/Assets/YooAsset/Runtime/FileSystem/DefaultCacheFileSystem/Operation/DCFSDownloadFileOperation.cs
+++ b/Assets/YooAsset/Runtime/FileSystem/DefaultCacheFileSystem/Operation/DCFSDownloadFileOperation.cs
@@ -8,17 +8,18 @@ namespace YooAsset
{
private readonly DefaultCacheFileSystem _fileSystem;
private VerifyTempFileOperation _verifyOperation;
- private string _fileSavePath;
+ private string _tempFilePath;
private ESteps _steps = ESteps.None;
- internal DCFSDownloadNormalFileOperation(DefaultCacheFileSystem fileSystem, PackageBundle bundle, string mainURL, string fallbackURL, int failedTryAgain, int timeout)
+ internal DCFSDownloadNormalFileOperation(DefaultCacheFileSystem fileSystem, PackageBundle bundle,
+ string mainURL, string fallbackURL, int failedTryAgain, int timeout)
: base(bundle, mainURL, fallbackURL, failedTryAgain, timeout)
{
_fileSystem = fileSystem;
}
internal override void InternalOnStart()
{
- _fileSavePath = _fileSystem.GetTempFilePath(Bundle);
+ _tempFilePath = _fileSystem.GetTempFilePath(Bundle);
_steps = ESteps.CheckExists;
}
internal override void InternalOnUpdate()
@@ -43,26 +44,17 @@ namespace YooAsset
// 创建下载器
if (_steps == ESteps.CreateRequest)
{
- FileUtility.CreateFileDirectory(_fileSavePath);
+ FileUtility.CreateFileDirectory(_tempFilePath);
+
+ // 删除临时文件
+ if (File.Exists(_tempFilePath))
+ File.Delete(_tempFilePath);
// 获取请求地址
_requestURL = GetRequestURL();
- // 重置变量
- _isAbort = false;
- _latestDownloadBytes = 0;
- _latestDownloadRealtime = Time.realtimeSinceStartup;
- DownloadProgress = 0f;
- DownloadedBytes = 0;
-
- // 重置计时器
- if (_tryAgainTimer > 0f)
- YooLogger.Warning($"Try again download : {_requestURL}");
- _tryAgainTimer = 0f;
-
- // 删除临时文件
- if (File.Exists(_fileSavePath))
- File.Delete(_fileSavePath);
+ // 重置请求
+ ResetRequestFiled();
// 创建下载器
CreateWebRequest();
@@ -95,7 +87,7 @@ namespace YooAsset
// 验证下载文件
if (_steps == ESteps.VerifyTempFile)
{
- var element = new TempFileElement(_fileSavePath, Bundle.FileCRC, Bundle.FileSize);
+ var element = new TempFileElement(_tempFilePath, Bundle.FileCRC, Bundle.FileSize);
_verifyOperation = new VerifyTempFileOperation(element);
OperationSystem.StartOperation(_fileSystem.PackageName, _verifyOperation);
_steps = ESteps.CheckVerifyTempFile;
@@ -111,7 +103,7 @@ namespace YooAsset
if (_verifyOperation.Status == EOperationStatus.Succeed)
{
- if (_fileSystem.WriteFile(Bundle, _fileSavePath))
+ if (_fileSystem.WriteCacheFile(Bundle, _tempFilePath))
{
Status = EOperationStatus.Succeed;
_steps = ESteps.Done;
@@ -131,8 +123,8 @@ namespace YooAsset
}
// 注意:验证完成后直接删除文件
- if (File.Exists(_fileSavePath))
- File.Delete(_fileSavePath);
+ if (File.Exists(_tempFilePath))
+ File.Delete(_tempFilePath);
}
// 重新尝试下载
@@ -183,7 +175,7 @@ namespace YooAsset
private void CreateWebRequest()
{
_webRequest = DownloadSystemHelper.NewUnityWebRequestGet(_requestURL);
- DownloadHandlerFile handler = new DownloadHandlerFile(_fileSavePath);
+ DownloadHandlerFile handler = new DownloadHandlerFile(_tempFilePath);
handler.removeFileOnAbort = true;
_webRequest.downloadHandler = handler;
_webRequest.disposeDownloadHandlerOnDispose = true;
@@ -210,7 +202,8 @@ namespace YooAsset
private ESteps _steps = ESteps.None;
- internal DCFSDownloadResumeFileOperation(DefaultCacheFileSystem fileSystem, PackageBundle bundle, string mainURL, string fallbackURL, int failedTryAgain, int timeout)
+ internal DCFSDownloadResumeFileOperation(DefaultCacheFileSystem fileSystem, PackageBundle bundle,
+ string mainURL, string fallbackURL, int failedTryAgain, int timeout)
: base(bundle, mainURL, fallbackURL, failedTryAgain, timeout)
{
_fileSystem = fileSystem;
@@ -248,19 +241,10 @@ namespace YooAsset
_requestURL = GetRequestURL();
// 重置变量
- _isAbort = false;
- _latestDownloadBytes = 0;
- _latestDownloadRealtime = Time.realtimeSinceStartup;
- _fileOriginLength = 0;
- DownloadProgress = 0f;
- DownloadedBytes = 0;
-
- // 重置计时器
- if (_tryAgainTimer > 0f)
- YooLogger.Warning($"Try again download : {_requestURL}");
- _tryAgainTimer = 0f;
+ ResetRequestFiled();
// 获取下载起始位置
+ _fileOriginLength = 0;
long fileBeginLength = -1;
if (File.Exists(_fileSavePath))
{
@@ -325,7 +309,7 @@ namespace YooAsset
if (_verifyOperation.Status == EOperationStatus.Succeed)
{
- if (_fileSystem.WriteFile(Bundle, _fileSavePath))
+ if (_fileSystem.WriteCacheFile(Bundle, _fileSavePath))
{
Status = EOperationStatus.Succeed;
_steps = ESteps.Done;
diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultCacheFileSystem/Operation/DCFSLoadBundleOperation.cs b/Assets/YooAsset/Runtime/FileSystem/DefaultCacheFileSystem/Operation/DCFSLoadBundleOperation.cs
index 4942313..237400a 100644
--- a/Assets/YooAsset/Runtime/FileSystem/DefaultCacheFileSystem/Operation/DCFSLoadBundleOperation.cs
+++ b/Assets/YooAsset/Runtime/FileSystem/DefaultCacheFileSystem/Operation/DCFSLoadBundleOperation.cs
@@ -29,7 +29,7 @@ namespace YooAsset
}
internal override void InternalOnStart()
{
- if (_fileSystem.CheckNeedDownload(_bundle))
+ if (_fileSystem.NeedDownload(_bundle))
{
_steps = ESteps.DownloadFile;
}
@@ -112,7 +112,7 @@ namespace YooAsset
{
// 注意:当缓存文件的校验等级为Low的时候,并不能保证缓存文件的完整性。
// 说明:在AssetBundle文件加载失败的情况下,我们需要重新验证文件的完整性!
- EFileVerifyResult result = _fileSystem.VerifyFile(_bundle);
+ EFileVerifyResult result = _fileSystem.VerifyCacheFile(_bundle);
if (result == EFileVerifyResult.Succeed)
{
// 注意:在安卓移动平台,华为和三星真机上有极小概率加载资源包失败。
@@ -146,7 +146,7 @@ namespace YooAsset
else
{
_steps = ESteps.Done;
- _fileSystem.DeleteFile(_bundle);
+ _fileSystem.DeleteCacheFile(_bundle.BundleGUID);
Status = EOperationStatus.Failed;
Error = $"Find corrupted file and delete the file : {_bundle.BundleName}";
YooLogger.Error(Error);
@@ -215,7 +215,7 @@ namespace YooAsset
}
internal override void InternalOnStart()
{
- if (_fileSystem.CheckNeedDownload(_bundle))
+ if (_fileSystem.NeedDownload(_bundle))
{
_steps = ESteps.DownloadFile;
}
diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultCacheFileSystem/Operation/internal/SearchCacheFilesOperation.cs b/Assets/YooAsset/Runtime/FileSystem/DefaultCacheFileSystem/Operation/internal/SearchCacheFilesOperation.cs
index f17fa16..5844862 100644
--- a/Assets/YooAsset/Runtime/FileSystem/DefaultCacheFileSystem/Operation/internal/SearchCacheFilesOperation.cs
+++ b/Assets/YooAsset/Runtime/FileSystem/DefaultCacheFileSystem/Operation/internal/SearchCacheFilesOperation.cs
@@ -81,7 +81,7 @@ namespace YooAsset
foreach (var chidDirectory in childDirectories)
{
string bundleGUID = chidDirectory.Name;
- if (_fileSystem.Exists(bundleGUID))
+ if (_fileSystem.IsRecordFile(bundleGUID))
continue;
// 创建验证元素类
diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultCacheFileSystem/Operation/internal/VerifyCacheFilesOperation.cs b/Assets/YooAsset/Runtime/FileSystem/DefaultCacheFileSystem/Operation/internal/VerifyCacheFilesOperation.cs
index 8459ebf..2ad7a4a 100644
--- a/Assets/YooAsset/Runtime/FileSystem/DefaultCacheFileSystem/Operation/internal/VerifyCacheFilesOperation.cs
+++ b/Assets/YooAsset/Runtime/FileSystem/DefaultCacheFileSystem/Operation/internal/VerifyCacheFilesOperation.cs
@@ -159,7 +159,7 @@ namespace YooAsset
{
_succeedCount++;
var fileWrapper = new DefaultCacheFileSystem.FileWrapper(element.InfoFilePath, element.DataFilePath, element.DataFileCRC, element.DataFileSize);
- _fileSystem.Record(element.BundleGUID, fileWrapper);
+ _fileSystem.RecordFile(element.BundleGUID, fileWrapper);
}
else
{
diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultEditorFileSystem/DefaultEditorFileSystem.cs b/Assets/YooAsset/Runtime/FileSystem/DefaultEditorFileSystem/DefaultEditorFileSystem.cs
index 06db9e6..77ea595 100644
--- a/Assets/YooAsset/Runtime/FileSystem/DefaultEditorFileSystem/DefaultEditorFileSystem.cs
+++ b/Assets/YooAsset/Runtime/FileSystem/DefaultEditorFileSystem/DefaultEditorFileSystem.cs
@@ -1,12 +1,8 @@
-using System;
-using System.IO;
-using System.Collections.Generic;
-using UnityEngine;
-
+
namespace YooAsset
{
///
- /// 内置文件系统
+ /// 模拟文件系统
///
internal class DefaultEditorFileSystem : IFileSystem
{
@@ -95,6 +91,15 @@ namespace YooAsset
{
throw new System.NotImplementedException();
}
+ public virtual FSLoadBundleOperation LoadBundleFile(PackageBundle bundle)
+ {
+ var operation = new DEFSLoadBundleOperation(this, bundle);
+ OperationSystem.StartOperation(PackageName, operation);
+ return operation;
+ }
+ public virtual void UnloadBundleFile(PackageBundle bundle, object result)
+ {
+ }
public virtual void SetParameter(string name, object value)
{
@@ -124,81 +129,28 @@ namespace YooAsset
{
return true;
}
- public virtual bool Belong(string bundleGUID)
- {
- return true;
- }
public virtual bool Exists(PackageBundle bundle)
{
return true;
}
- public virtual bool Exists(string bundleGUID)
- {
- return true;
- }
-
- public virtual bool CheckNeedDownload(PackageBundle bundle)
+ public virtual bool NeedDownload(PackageBundle bundle)
{
return false;
}
- public virtual bool CheckNeedUnpack(PackageBundle bundle)
+ public virtual bool NeedUnpack(PackageBundle bundle)
{
return false;
}
- public virtual bool CheckNeedImport(PackageBundle bundle)
+ public virtual bool NeedImport(PackageBundle bundle)
{
return false;
}
- public virtual bool WriteFile(PackageBundle bundle, string copyPath)
- {
- return true;
- }
- public virtual bool DeleteFile(PackageBundle bundle)
- {
- return true;
- }
- public virtual bool DeleteFile(string bundleGUID)
- {
- return true;
- }
- public virtual EFileVerifyResult VerifyFile(PackageBundle bundle)
- {
- return EFileVerifyResult.Succeed;
- }
-
- public virtual byte[] ReadFileBytes(PackageBundle bundle)
- {
- throw new System.NotImplementedException();
- }
- public virtual string ReadFileText(PackageBundle bundle)
- {
- throw new System.NotImplementedException();
- }
-
- public virtual FSLoadBundleOperation LoadBundleFile(PackageBundle bundle)
- {
- var operation = new DEFSLoadBundleOperation(this, bundle);
- OperationSystem.StartOperation(PackageName, operation);
- return operation;
- }
- public virtual void UnloadBundleFile(PackageBundle bundle, object result)
- {
- }
-
#region 内部方法
protected string GetDefaultRoot()
{
return "Assets/";
}
-
- ///
- /// 记录缓存信息
- ///
- public bool Record(string bundleGUID, object value)
- {
- return true;
- }
#endregion
}
}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/DefaultWebFileSystem.cs b/Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/DefaultWebFileSystem.cs
index 3a0dd3a..a784a82 100644
--- a/Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/DefaultWebFileSystem.cs
+++ b/Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/DefaultWebFileSystem.cs
@@ -5,6 +5,9 @@ using UnityEngine;
namespace YooAsset
{
+ ///
+ /// Web文件系统
+ ///
internal class DefaultWebFileSystem : IFileSystem
{
public class FileWrapper
@@ -128,6 +131,21 @@ namespace YooAsset
{
throw new System.NotImplementedException();
}
+ public virtual FSLoadBundleOperation LoadBundleFile(PackageBundle bundle)
+ {
+ var operation = new DWFSLoadAssetBundleOperation(this, bundle);
+ 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);
+ }
public virtual void SetParameter(string name, object value)
{
@@ -165,74 +183,26 @@ namespace YooAsset
{
return true;
}
- public virtual bool Belong(string bundleGUID)
+ public virtual bool Exists(PackageBundle bundle)
{
return true;
}
- public virtual bool Exists(PackageBundle bundle)
+ public virtual bool NeedDownload(PackageBundle bundle)
+ {
+ if (Belong(bundle) == false)
+ return false;
+
+ return Exists(bundle) == false;
+ }
+ public virtual bool NeedUnpack(PackageBundle bundle)
{
return false;
}
- public virtual bool Exists(string bundleGUID)
+ public virtual bool NeedImport(PackageBundle bundle)
{
return false;
}
- public virtual bool CheckNeedDownload(PackageBundle bundle)
- {
- return false;
- }
- public virtual bool CheckNeedUnpack(PackageBundle bundle)
- {
- return false;
- }
- public virtual bool CheckNeedImport(PackageBundle bundle)
- {
- return false;
- }
-
- public virtual bool WriteFile(PackageBundle bundle, string copyPath)
- {
- throw new System.NotImplementedException();
- }
- public virtual bool DeleteFile(PackageBundle bundle)
- {
- throw new System.NotImplementedException();
- }
- public virtual bool DeleteFile(string bundleGUID)
- {
- throw new System.NotImplementedException();
- }
- public virtual EFileVerifyResult VerifyFile(PackageBundle bundle)
- {
- return EFileVerifyResult.Succeed;
- }
-
- public virtual byte[] ReadFileBytes(PackageBundle bundle)
- {
- throw new System.NotImplementedException();
- }
- public virtual string ReadFileText(PackageBundle bundle)
- {
- throw new System.NotImplementedException();
- }
-
- public virtual FSLoadBundleOperation LoadBundleFile(PackageBundle bundle)
- {
- var operation = new DWFSLoadAssetBundleOperation(this, bundle);
- 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);
- }
-
#region 内部方法
protected string GetDefaultWebRoot()
{
@@ -270,9 +240,9 @@ namespace YooAsset
}
///
- /// 记录缓存信息
+ /// 记录文件信息
///
- public bool Record(string bundleGUID, FileWrapper wrapper)
+ public bool RecordFile(string bundleGUID, FileWrapper wrapper)
{
if (_wrappers.ContainsKey(bundleGUID))
{
diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/Operation/DWFSLoadBundleOperation.cs b/Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/Operation/DWFSLoadBundleOperation.cs
index 2ee6c2b..d4a2205 100644
--- a/Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/Operation/DWFSLoadBundleOperation.cs
+++ b/Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/Operation/DWFSLoadBundleOperation.cs
@@ -7,13 +7,12 @@ namespace YooAsset
{
None,
DownloadFile,
- CheckResult,
Done,
}
private readonly DefaultWebFileSystem _fileSystem;
private readonly PackageBundle _bundle;
- private DWFSDownloadWebFileOperation _downloadWebFileOp;
+ private DownloadHandlerAssetBundleOperation _downloadhanlderAssetBundleOp;
private ESteps _steps = ESteps.None;
@@ -33,32 +32,32 @@ namespace YooAsset
if (_steps == ESteps.DownloadFile)
{
- if (_downloadWebFileOp == null)
+ if (_downloadhanlderAssetBundleOp == null)
{
int failedTryAgain = int.MaxValue;
int timeout = 60;
string mainURL = _fileSystem.RemoteServices.GetRemoteMainURL(_bundle.FileName);
string fallbackURL = _fileSystem.RemoteServices.GetRemoteFallbackURL(_bundle.FileName);
- _downloadWebFileOp = new DWFSDownloadWebFileOperation(_fileSystem, _bundle, mainURL, fallbackURL, failedTryAgain, timeout);
+ _downloadhanlderAssetBundleOp = new DownloadHandlerAssetBundleOperation(_fileSystem, _bundle, mainURL, fallbackURL, failedTryAgain, timeout);
}
- DownloadProgress = _downloadWebFileOp.DownloadProgress;
- DownloadedBytes = _downloadWebFileOp.DownloadedBytes;
- Progress = _downloadWebFileOp.Progress;
- if (_downloadWebFileOp.IsDone == false)
+ DownloadProgress = _downloadhanlderAssetBundleOp.DownloadProgress;
+ DownloadedBytes = _downloadhanlderAssetBundleOp.DownloadedBytes;
+ Progress = _downloadhanlderAssetBundleOp.Progress;
+ if (_downloadhanlderAssetBundleOp.IsDone == false)
return;
- if (_downloadWebFileOp.Status == EOperationStatus.Succeed)
+ if (_downloadhanlderAssetBundleOp.Status == EOperationStatus.Succeed)
{
_steps = ESteps.Done;
- Result = _downloadWebFileOp.Result;
+ Result = _downloadhanlderAssetBundleOp.Result;
Status = EOperationStatus.Succeed;
}
else
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
- Error = _downloadWebFileOp.Error;
+ Error = _downloadhanlderAssetBundleOp.Error;
}
}
}
@@ -77,8 +76,8 @@ namespace YooAsset
{
if (_steps == ESteps.DownloadFile)
{
- if (_downloadWebFileOp != null)
- _downloadWebFileOp.SetAbort();
+ if (_downloadhanlderAssetBundleOp != null)
+ _downloadhanlderAssetBundleOp.SetAbort();
}
}
}
diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/Operation/DWFSDownloadFileOperation.cs b/Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/Operation/internal/DownloadHandlerAssetBundleOperation.cs
similarity index 83%
rename from Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/Operation/DWFSDownloadFileOperation.cs
rename to Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/Operation/internal/DownloadHandlerAssetBundleOperation.cs
index 9318fc0..0d0eefe 100644
--- a/Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/Operation/DWFSDownloadFileOperation.cs
+++ b/Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/Operation/internal/DownloadHandlerAssetBundleOperation.cs
@@ -1,22 +1,19 @@
-using System.IO;
-using UnityEngine;
+using UnityEngine;
using UnityEngine.Networking;
namespace YooAsset
{
- internal class DWFSDownloadWebFileOperation : DefaultDownloadFileOperation
+ internal class DownloadHandlerAssetBundleOperation : DefaultDownloadFileOperation
{
private readonly DefaultWebFileSystem _fileSystem;
private DownloadHandlerAssetBundle _downloadhandler;
private ESteps _steps = ESteps.None;
- ///
- /// 下载结果
- ///
public AssetBundle Result { private set; get; }
- internal DWFSDownloadWebFileOperation(DefaultWebFileSystem fileSystem, PackageBundle bundle, string mainURL, string fallbackURL, int failedTryAgain, int timeout)
+ internal DownloadHandlerAssetBundleOperation(DefaultWebFileSystem fileSystem, PackageBundle bundle,
+ string mainURL, string fallbackURL, int failedTryAgain, int timeout)
: base(bundle, mainURL, fallbackURL, failedTryAgain, timeout)
{
_fileSystem = fileSystem;
@@ -37,16 +34,7 @@ namespace YooAsset
_requestURL = GetRequestURL();
// 重置变量
- _isAbort = false;
- _latestDownloadBytes = 0;
- _latestDownloadRealtime = Time.realtimeSinceStartup;
- DownloadProgress = 0f;
- DownloadedBytes = 0;
-
- // 重置计时器
- if (_tryAgainTimer > 0f)
- YooLogger.Warning($"Try again download : {_requestURL}");
- _tryAgainTimer = 0f;
+ ResetRequestFiled();
// 创建下载器
CreateWebRequest();
@@ -110,11 +98,21 @@ namespace YooAsset
private void CreateWebRequest()
{
+ _downloadhandler = CreateDownloadHandler();
_webRequest = DownloadSystemHelper.NewUnityWebRequestGet(_requestURL);
- _webRequest.downloadHandler = CreateDownloadHandler();
+ _webRequest.downloadHandler = _downloadhandler;
_webRequest.disposeDownloadHandlerOnDispose = true;
_webRequest.SendWebRequest();
}
+ private void DisposeWebRequest()
+ {
+ if (_webRequest != null)
+ {
+ //注意:引擎底层会自动调用Abort方法
+ _webRequest.Dispose();
+ _webRequest = null;
+ }
+ }
private DownloadHandlerAssetBundle CreateDownloadHandler()
{
if (_fileSystem.DisableUnityWebCache)
@@ -138,14 +136,5 @@ namespace YooAsset
return downloadhandler;
}
}
- private void DisposeWebRequest()
- {
- if (_webRequest != null)
- {
- //注意:引擎底层会自动调用Abort方法
- _webRequest.Dispose();
- _webRequest = null;
- }
- }
}
}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/Operation/DWFSDownloadFileOperation.cs.meta b/Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/Operation/internal/DownloadHandlerAssetBundleOperation.cs.meta
similarity index 100%
rename from Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/Operation/DWFSDownloadFileOperation.cs.meta
rename to Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/Operation/internal/DownloadHandlerAssetBundleOperation.cs.meta
diff --git a/Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/Operation/internal/LoadWebCatalogFileOperation.cs b/Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/Operation/internal/LoadWebCatalogFileOperation.cs
index a6fa1ca..531d52f 100644
--- a/Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/Operation/internal/LoadWebCatalogFileOperation.cs
+++ b/Assets/YooAsset/Runtime/FileSystem/DefaultWebFileSystem/Operation/internal/LoadWebCatalogFileOperation.cs
@@ -60,7 +60,7 @@ namespace YooAsset
foreach (var wrapper in catalog.Wrappers)
{
var fileWrapper = new DefaultWebFileSystem.FileWrapper(wrapper.FileName);
- _fileSystem.Record(wrapper.BundleGUID, fileWrapper);
+ _fileSystem.RecordFile(wrapper.BundleGUID, fileWrapper);
}
YooLogger.Log($"Package '{_fileSystem.PackageName}' catalog files count : {catalog.Wrappers.Count}");
diff --git a/Assets/YooAsset/Runtime/FileSystem/Interface/IFileSystem.cs b/Assets/YooAsset/Runtime/FileSystem/Interface/IFileSystem.cs
index a3d5d95..4e87927 100644
--- a/Assets/YooAsset/Runtime/FileSystem/Interface/IFileSystem.cs
+++ b/Assets/YooAsset/Runtime/FileSystem/Interface/IFileSystem.cs
@@ -53,7 +53,17 @@ namespace YooAsset
/// 下载远端文件
///
FSDownloadFileOperation DownloadFileAsync(params object[] args);
-
+
+ ///
+ /// 加载Bundle文件
+ ///
+ FSLoadBundleOperation LoadBundleFile(PackageBundle bundle);
+
+ ///
+ /// 卸载Bundle文件
+ ///
+ void UnloadBundleFile(PackageBundle bundle, object result);
+
///
/// 设置自定义参数
@@ -76,78 +86,24 @@ namespace YooAsset
///
bool Belong(PackageBundle bundle);
- ///
- /// 查询文件归属
- ///
- bool Belong(string bundleGUID);
-
///
/// 查询文件是否存在
///
bool Exists(PackageBundle bundle);
///
- /// 查询文件是否存在
+ /// 是否需要下载
///
- bool Exists(string bundleGUID);
-
+ bool NeedDownload(PackageBundle bundle);
///
- /// 检测是否需要下载
+ /// 是否需要解压
///
- bool CheckNeedDownload(PackageBundle bundle);
-
+ bool NeedUnpack(PackageBundle bundle);
+
///
- /// 检测是否需要解压
+ /// 是否需要导入
///
- bool CheckNeedUnpack(PackageBundle bundle);
-
- ///
- /// 检测是否需要导入
- ///
- bool CheckNeedImport(PackageBundle bundle);
-
-
- ///
- /// 写入文件
- ///
- bool WriteFile(PackageBundle bundle, string copyPath);
-
- ///
- /// 删除文件
- ///
- bool DeleteFile(PackageBundle bundle);
-
- ///
- /// 删除文件
- ///
- bool DeleteFile(string bundleGUID);
-
- ///
- /// 校验文件
- ///
- EFileVerifyResult VerifyFile(PackageBundle bundle);
-
-
- ///
- /// 读取文件的二进制数据
- ///
- byte[] ReadFileBytes(PackageBundle bundle);
-
- ///
- /// 读取文件的文本数据
- ///
- string ReadFileText(PackageBundle bundle);
-
-
- ///
- /// 加载Bundle文件
- ///
- FSLoadBundleOperation LoadBundleFile(PackageBundle bundle);
-
- ///
- /// 卸载Bundle文件
- ///
- void UnloadBundleFile(PackageBundle bundle, object result);
+ bool NeedImport(PackageBundle bundle);
}
}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/FileSystem/Operation/Internal/DefaultDownloadFileOperation.cs b/Assets/YooAsset/Runtime/FileSystem/Operation/Internal/DefaultDownloadFileOperation.cs
index 88c93f8..f26a336 100644
--- a/Assets/YooAsset/Runtime/FileSystem/Operation/Internal/DefaultDownloadFileOperation.cs
+++ b/Assets/YooAsset/Runtime/FileSystem/Operation/Internal/DefaultDownloadFileOperation.cs
@@ -1,4 +1,5 @@
-using UnityEngine.Networking;
+using UnityEngine;
+using UnityEngine.Networking;
namespace YooAsset
{
@@ -61,6 +62,24 @@ namespace YooAsset
return _mainURL;
}
+ ///
+ /// 重置请求字段
+ ///
+ protected void ResetRequestFiled()
+ {
+ // 重置变量
+ _isAbort = false;
+ _latestDownloadBytes = 0;
+ _latestDownloadRealtime = Time.realtimeSinceStartup;
+ DownloadProgress = 0f;
+ DownloadedBytes = 0;
+
+ // 重置计时器
+ if (_tryAgainTimer > 0f)
+ YooLogger.Warning($"Try again download : {_requestURL}");
+ _tryAgainTimer = 0f;
+ }
+
///
/// 检测请求超时
///
diff --git a/Assets/YooAsset/Runtime/ResourcePackage/BundleInfo.cs b/Assets/YooAsset/Runtime/ResourcePackage/BundleInfo.cs
index a87d2f4..fb2adf3 100644
--- a/Assets/YooAsset/Runtime/ResourcePackage/BundleInfo.cs
+++ b/Assets/YooAsset/Runtime/ResourcePackage/BundleInfo.cs
@@ -62,7 +62,7 @@ namespace YooAsset
///
public bool IsNeedDownloadFromRemote()
{
- return _fileSystem.CheckNeedDownload(Bundle);
+ return _fileSystem.NeedDownload(Bundle);
}
///
diff --git a/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/PlayModeHelper.cs b/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/PlayModeHelper.cs
index 985b302..ad1e541 100644
--- a/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/PlayModeHelper.cs
+++ b/Assets/YooAsset/Runtime/ResourcePackage/PlayMode/PlayModeHelper.cs
@@ -37,17 +37,17 @@ namespace YooAsset
IFileSystem fileSystem = null;
if (fileSystemA != null && fileSystemA.Belong(packageBundle))
{
- if (fileSystemA.CheckNeedDownload(packageBundle))
+ if (fileSystemA.NeedDownload(packageBundle))
fileSystem = fileSystemA;
}
else if (fileSystemB != null && fileSystemB.Belong(packageBundle))
{
- if (fileSystemB.CheckNeedDownload(packageBundle))
+ if (fileSystemB.NeedDownload(packageBundle))
fileSystem = fileSystemB;
}
else if (fileSystemC != null && fileSystemC.Belong(packageBundle))
{
- if (fileSystemC.CheckNeedDownload(packageBundle))
+ if (fileSystemC.NeedDownload(packageBundle))
fileSystem = fileSystemC;
}
else
@@ -70,17 +70,17 @@ namespace YooAsset
IFileSystem fileSystem = null;
if (fileSystemA != null && fileSystemA.Belong(packageBundle))
{
- if (fileSystemA.CheckNeedDownload(packageBundle))
+ if (fileSystemA.NeedDownload(packageBundle))
fileSystem = fileSystemA;
}
else if (fileSystemB != null && fileSystemB.Belong(packageBundle))
{
- if (fileSystemB.CheckNeedDownload(packageBundle))
+ if (fileSystemB.NeedDownload(packageBundle))
fileSystem = fileSystemB;
}
else if (fileSystemC != null && fileSystemC.Belong(packageBundle))
{
- if (fileSystemC.CheckNeedDownload(packageBundle))
+ if (fileSystemC.NeedDownload(packageBundle))
fileSystem = fileSystemC;
}
else
@@ -140,17 +140,17 @@ namespace YooAsset
IFileSystem fileSystem = null;
if (fileSystemA != null && fileSystemA.Belong(packageBundle))
{
- if (fileSystemA.CheckNeedDownload(packageBundle))
+ if (fileSystemA.NeedDownload(packageBundle))
fileSystem = fileSystemA;
}
else if (fileSystemB != null && fileSystemB.Belong(packageBundle))
{
- if (fileSystemB.CheckNeedDownload(packageBundle))
+ if (fileSystemB.NeedDownload(packageBundle))
fileSystem = fileSystemB;
}
else if (fileSystemC != null && fileSystemC.Belong(packageBundle))
{
- if (fileSystemC.CheckNeedDownload(packageBundle))
+ if (fileSystemC.NeedDownload(packageBundle))
fileSystem = fileSystemC;
}
else
@@ -173,17 +173,17 @@ namespace YooAsset
IFileSystem fileSystem = null;
if (fileSystemA != null && fileSystemA.Belong(packageBundle))
{
- if (fileSystemA.CheckNeedUnpack(packageBundle))
+ if (fileSystemA.NeedUnpack(packageBundle))
fileSystem = fileSystemA;
}
else if (fileSystemB != null && fileSystemB.Belong(packageBundle))
{
- if (fileSystemB.CheckNeedUnpack(packageBundle))
+ if (fileSystemB.NeedUnpack(packageBundle))
fileSystem = fileSystemB;
}
else if (fileSystemC != null && fileSystemC.Belong(packageBundle))
{
- if (fileSystemC.CheckNeedUnpack(packageBundle))
+ if (fileSystemC.NeedUnpack(packageBundle))
fileSystem = fileSystemC;
}
else
@@ -207,17 +207,17 @@ namespace YooAsset
IFileSystem fileSystem = null;
if (fileSystemA != null && fileSystemA.Belong(packageBundle))
{
- if (fileSystemA.CheckNeedUnpack(packageBundle))
+ if (fileSystemA.NeedUnpack(packageBundle))
fileSystem = fileSystemA;
}
else if (fileSystemB != null && fileSystemB.Belong(packageBundle))
{
- if (fileSystemB.CheckNeedUnpack(packageBundle))
+ if (fileSystemB.NeedUnpack(packageBundle))
fileSystem = fileSystemB;
}
else if (fileSystemC != null && fileSystemC.Belong(packageBundle))
{
- if (fileSystemC.CheckNeedUnpack(packageBundle))
+ if (fileSystemC.NeedUnpack(packageBundle))
fileSystem = fileSystemC;
}
else
@@ -248,17 +248,17 @@ namespace YooAsset
IFileSystem fileSystem = null;
if (fileSystemA != null && fileSystemA.Belong(packageBundle))
{
- if (fileSystemA.CheckNeedImport(packageBundle))
+ if (fileSystemA.NeedImport(packageBundle))
fileSystem = fileSystemA;
}
else if (fileSystemB != null && fileSystemB.Belong(packageBundle))
{
- if (fileSystemB.CheckNeedImport(packageBundle))
+ if (fileSystemB.NeedImport(packageBundle))
fileSystem = fileSystemB;
}
else if (fileSystemC != null && fileSystemC.Belong(packageBundle))
{
- if (fileSystemC.CheckNeedImport(packageBundle))
+ if (fileSystemC.NeedImport(packageBundle))
fileSystem = fileSystemC;
}
else