diff --git a/Assets/YooAsset/Runtime/CacheSystem/CacheFileInfo.cs b/Assets/YooAsset/Runtime/CacheSystem/CacheFileInfo.cs
index 9017fd8..bdf1383 100644
--- a/Assets/YooAsset/Runtime/CacheSystem/CacheFileInfo.cs
+++ b/Assets/YooAsset/Runtime/CacheSystem/CacheFileInfo.cs
@@ -3,34 +3,34 @@ using System.IO;
namespace YooAsset
{
- internal class CacheFileInfo
- {
- private static readonly BufferWriter SharedBuffer = new BufferWriter(1024);
+ internal class CacheFileInfo
+ {
+ private static readonly BufferWriter SharedBuffer = new BufferWriter(1024);
- ///
- /// 写入资源包信息
- ///
- public static void WriteInfoToFile(string filePath, string dataFileCRC, long dataFileSize)
- {
- using (FileStream fs = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.Read))
- {
- SharedBuffer.Clear();
- SharedBuffer.WriteUTF8(dataFileCRC);
- SharedBuffer.WriteInt64(dataFileSize);
- SharedBuffer.WriteToStream(fs);
- fs.Flush();
- }
- }
+ ///
+ /// 写入资源包信息
+ ///
+ public static void WriteInfoToFile(string filePath, string dataFileCRC, long dataFileSize)
+ {
+ using (FileStream fs = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.Read))
+ {
+ SharedBuffer.Clear();
+ SharedBuffer.WriteUTF8(dataFileCRC);
+ SharedBuffer.WriteInt64(dataFileSize);
+ SharedBuffer.WriteToStream(fs);
+ fs.Flush();
+ }
+ }
- ///
- /// 读取资源包信息
- ///
- public static void ReadInfoFromFile(string filePath, out string dataFileCRC, out long dataFileSize)
- {
- byte[] binaryData = FileUtility.ReadAllBytes(filePath);
- BufferReader buffer = new BufferReader(binaryData);
- dataFileCRC = buffer.ReadUTF8();
- dataFileSize = buffer.ReadInt64();
- }
- }
+ ///
+ /// 读取资源包信息
+ ///
+ public static void ReadInfoFromFile(string filePath, out string dataFileCRC, out long dataFileSize)
+ {
+ byte[] binaryData = FileUtility.ReadAllBytes(filePath);
+ BufferReader buffer = new BufferReader(binaryData);
+ dataFileCRC = buffer.ReadUTF8();
+ dataFileSize = buffer.ReadInt64();
+ }
+ }
}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/CacheSystem/CacheHelper.cs b/Assets/YooAsset/Runtime/CacheSystem/CacheHelper.cs
index 23894c5..3242708 100644
--- a/Assets/YooAsset/Runtime/CacheSystem/CacheHelper.cs
+++ b/Assets/YooAsset/Runtime/CacheSystem/CacheHelper.cs
@@ -6,98 +6,98 @@ using System.Diagnostics;
namespace YooAsset
{
- internal static class CacheHelper
- {
- ///
- /// 禁用Unity缓存系统在WebGL平台
- ///
- public static bool DisableUnityCacheOnWebGL = false;
+ internal static class CacheHelper
+ {
+ ///
+ /// 禁用Unity缓存系统在WebGL平台
+ ///
+ public static bool DisableUnityCacheOnWebGL = false;
- ///
- /// 验证缓存文件(子线程内操作)
- ///
- public static EVerifyResult VerifyingCacheFile(VerifyCacheFileElement element, EVerifyLevel verifyLevel)
- {
- try
- {
- if (verifyLevel == EVerifyLevel.Low)
- {
- if (File.Exists(element.InfoFilePath) == false)
- return EVerifyResult.InfoFileNotExisted;
- if (File.Exists(element.DataFilePath) == false)
- return EVerifyResult.DataFileNotExisted;
- return EVerifyResult.Succeed;
- }
- else
- {
- if (File.Exists(element.InfoFilePath) == false)
- return EVerifyResult.InfoFileNotExisted;
+ ///
+ /// 验证缓存文件(子线程内操作)
+ ///
+ public static EVerifyResult VerifyingCacheFile(VerifyCacheFileElement element, EVerifyLevel verifyLevel)
+ {
+ try
+ {
+ if (verifyLevel == EVerifyLevel.Low)
+ {
+ if (File.Exists(element.InfoFilePath) == false)
+ return EVerifyResult.InfoFileNotExisted;
+ if (File.Exists(element.DataFilePath) == false)
+ return EVerifyResult.DataFileNotExisted;
+ return EVerifyResult.Succeed;
+ }
+ else
+ {
+ if (File.Exists(element.InfoFilePath) == false)
+ return EVerifyResult.InfoFileNotExisted;
- // 解析信息文件获取验证数据
- CacheFileInfo.ReadInfoFromFile(element.InfoFilePath, out element.DataFileCRC, out element.DataFileSize);
- }
- }
- catch (Exception)
- {
- return EVerifyResult.Exception;
- }
+ // 解析信息文件获取验证数据
+ CacheFileInfo.ReadInfoFromFile(element.InfoFilePath, out element.DataFileCRC, out element.DataFileSize);
+ }
+ }
+ catch (Exception)
+ {
+ return EVerifyResult.Exception;
+ }
- return VerifyingInternal(element.DataFilePath, element.DataFileSize, element.DataFileCRC, verifyLevel);
- }
+ return VerifyingInternal(element.DataFilePath, element.DataFileSize, element.DataFileCRC, verifyLevel);
+ }
- ///
- /// 验证下载文件(子线程内操作)
- ///
- public static EVerifyResult VerifyingTempFile(VerifyTempFileElement element)
- {
- return VerifyingInternal(element.TempDataFilePath, element.FileSize, element.FileCRC, EVerifyLevel.High);
- }
+ ///
+ /// 验证下载文件(子线程内操作)
+ ///
+ public static EVerifyResult VerifyingTempFile(VerifyTempFileElement element)
+ {
+ return VerifyingInternal(element.TempDataFilePath, element.FileSize, element.FileCRC, EVerifyLevel.High);
+ }
- ///
- /// 验证记录文件(主线程内操作)
- ///
- public static EVerifyResult VerifyingRecordFile(CacheManager cache, string cacheGUID)
- {
- var wrapper = cache.TryGetWrapper(cacheGUID);
- if (wrapper == null)
- return EVerifyResult.CacheNotFound;
+ ///
+ /// 验证记录文件(主线程内操作)
+ ///
+ public static EVerifyResult VerifyingRecordFile(CacheManager cache, string cacheGUID)
+ {
+ var wrapper = cache.TryGetWrapper(cacheGUID);
+ if (wrapper == null)
+ return EVerifyResult.CacheNotFound;
- EVerifyResult result = VerifyingInternal(wrapper.DataFilePath, wrapper.DataFileSize, wrapper.DataFileCRC, EVerifyLevel.High);
- return result;
- }
+ EVerifyResult result = VerifyingInternal(wrapper.DataFilePath, wrapper.DataFileSize, wrapper.DataFileCRC, EVerifyLevel.High);
+ return result;
+ }
- private static EVerifyResult VerifyingInternal(string filePath, long fileSize, string fileCRC, EVerifyLevel verifyLevel)
- {
- try
- {
- if (File.Exists(filePath) == false)
- return EVerifyResult.DataFileNotExisted;
+ private static EVerifyResult VerifyingInternal(string filePath, long fileSize, string fileCRC, EVerifyLevel verifyLevel)
+ {
+ try
+ {
+ if (File.Exists(filePath) == false)
+ return EVerifyResult.DataFileNotExisted;
- // 先验证文件大小
- long size = FileUtility.GetFileSize(filePath);
- if (size < fileSize)
- return EVerifyResult.FileNotComplete;
- else if (size > fileSize)
- return EVerifyResult.FileOverflow;
+ // 先验证文件大小
+ long size = FileUtility.GetFileSize(filePath);
+ if (size < fileSize)
+ return EVerifyResult.FileNotComplete;
+ else if (size > fileSize)
+ return EVerifyResult.FileOverflow;
- // 再验证文件CRC
- if (verifyLevel == EVerifyLevel.High)
- {
- string crc = HashUtility.FileCRC32(filePath);
- if (crc == fileCRC)
- return EVerifyResult.Succeed;
- else
- return EVerifyResult.FileCrcError;
- }
- else
- {
- return EVerifyResult.Succeed;
- }
- }
- catch (Exception)
- {
- return EVerifyResult.Exception;
- }
- }
- }
+ // 再验证文件CRC
+ if (verifyLevel == EVerifyLevel.High)
+ {
+ string crc = HashUtility.FileCRC32(filePath);
+ if (crc == fileCRC)
+ return EVerifyResult.Succeed;
+ else
+ return EVerifyResult.FileCrcError;
+ }
+ else
+ {
+ return EVerifyResult.Succeed;
+ }
+ }
+ catch (Exception)
+ {
+ return EVerifyResult.Exception;
+ }
+ }
+ }
}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/CacheSystem/CacheManager.cs b/Assets/YooAsset/Runtime/CacheSystem/CacheManager.cs
index 71ef9ac..9b94fc2 100644
--- a/Assets/YooAsset/Runtime/CacheSystem/CacheManager.cs
+++ b/Assets/YooAsset/Runtime/CacheSystem/CacheManager.cs
@@ -5,132 +5,132 @@ using System.Collections.Generic;
namespace YooAsset
{
- internal class CacheManager
- {
- internal class RecordWrapper
- {
- public string InfoFilePath { private set; get; }
- public string DataFilePath { private set; get; }
- public string DataFileCRC { private set; get; }
- public long DataFileSize { private set; get; }
+ internal class CacheManager
+ {
+ internal class RecordWrapper
+ {
+ public string InfoFilePath { private set; get; }
+ public string DataFilePath { private set; get; }
+ public string DataFileCRC { private set; get; }
+ public long DataFileSize { private set; get; }
- public RecordWrapper(string infoFilePath, string dataFilePath, string dataFileCRC, long dataFileSize)
- {
- InfoFilePath = infoFilePath;
- DataFilePath = dataFilePath;
- DataFileCRC = dataFileCRC;
- DataFileSize = dataFileSize;
- }
- }
+ public RecordWrapper(string infoFilePath, string dataFilePath, string dataFileCRC, long dataFileSize)
+ {
+ InfoFilePath = infoFilePath;
+ DataFilePath = dataFilePath;
+ DataFileCRC = dataFileCRC;
+ DataFileSize = dataFileSize;
+ }
+ }
- private readonly Dictionary _wrappers = new Dictionary();
+ private readonly Dictionary _wrappers = new Dictionary();
- ///
- /// 所属包裹
- ///
- public readonly string PackageName;
+ ///
+ /// 所属包裹
+ ///
+ public readonly string PackageName;
- ///
- /// 验证级别
- ///
- public readonly EVerifyLevel BootVerifyLevel;
+ ///
+ /// 验证级别
+ ///
+ public readonly EVerifyLevel BootVerifyLevel;
- public CacheManager(string packageName, EVerifyLevel bootVerifyLevel)
- {
- PackageName = packageName;
- BootVerifyLevel = bootVerifyLevel;
- }
+ public CacheManager(string packageName, EVerifyLevel bootVerifyLevel)
+ {
+ PackageName = packageName;
+ BootVerifyLevel = bootVerifyLevel;
+ }
- ///
- /// 清空所有数据
- ///
- public void ClearAll()
- {
- _wrappers.Clear();
- }
+ ///
+ /// 清空所有数据
+ ///
+ public void ClearAll()
+ {
+ _wrappers.Clear();
+ }
- ///
- /// 查询缓存记录
- ///
- public bool IsCached(string cacheGUID)
- {
- return _wrappers.ContainsKey(cacheGUID);
- }
+ ///
+ /// 查询缓存记录
+ ///
+ public bool IsCached(string cacheGUID)
+ {
+ return _wrappers.ContainsKey(cacheGUID);
+ }
- ///
- /// 记录验证结果
- ///
- public void Record(string cacheGUID, RecordWrapper wrapper)
- {
- if (_wrappers.ContainsKey(cacheGUID) == false)
- {
- _wrappers.Add(cacheGUID, wrapper);
- }
- else
- {
- throw new Exception("Should never get here !");
- }
- }
+ ///
+ /// 记录验证结果
+ ///
+ public void Record(string cacheGUID, RecordWrapper wrapper)
+ {
+ if (_wrappers.ContainsKey(cacheGUID) == false)
+ {
+ _wrappers.Add(cacheGUID, wrapper);
+ }
+ else
+ {
+ throw new Exception("Should never get here !");
+ }
+ }
- ///
- /// 丢弃验证结果并删除缓存文件
- ///
- public void Discard(string cacheGUID)
- {
- var wrapper = TryGetWrapper(cacheGUID);
- if (wrapper != null)
- {
- try
- {
- string dataFilePath = wrapper.DataFilePath;
- FileInfo fileInfo = new FileInfo(dataFilePath);
- if (fileInfo.Exists)
- fileInfo.Directory.Delete(true);
- }
- catch (Exception e)
- {
- YooLogger.Error($"Failed to delete cache file ! {e.Message}");
- }
- }
+ ///
+ /// 丢弃验证结果并删除缓存文件
+ ///
+ public void Discard(string cacheGUID)
+ {
+ var wrapper = TryGetWrapper(cacheGUID);
+ if (wrapper != null)
+ {
+ try
+ {
+ string dataFilePath = wrapper.DataFilePath;
+ FileInfo fileInfo = new FileInfo(dataFilePath);
+ if (fileInfo.Exists)
+ fileInfo.Directory.Delete(true);
+ }
+ catch (Exception e)
+ {
+ YooLogger.Error($"Failed to delete cache file ! {e.Message}");
+ }
+ }
- if (_wrappers.ContainsKey(cacheGUID))
- {
- _wrappers.Remove(cacheGUID);
- }
- }
+ if (_wrappers.ContainsKey(cacheGUID))
+ {
+ _wrappers.Remove(cacheGUID);
+ }
+ }
- ///
- /// 获取记录对象
- ///
- public RecordWrapper TryGetWrapper(string cacheGUID)
- {
- if (_wrappers.TryGetValue(cacheGUID, out RecordWrapper value))
- return value;
- else
- return null;
- }
+ ///
+ /// 获取记录对象
+ ///
+ public RecordWrapper TryGetWrapper(string cacheGUID)
+ {
+ if (_wrappers.TryGetValue(cacheGUID, out RecordWrapper value))
+ return value;
+ else
+ return null;
+ }
- ///
- /// 获取缓存文件总数
- ///
- public int GetAllCachedFilesCount()
- {
- return _wrappers.Count;
- }
+ ///
+ /// 获取缓存文件总数
+ ///
+ public int GetAllCachedFilesCount()
+ {
+ return _wrappers.Count;
+ }
- ///
- /// 获取缓存GUID集合
- ///
- public List GetAllCachedGUIDs()
- {
- List keys = new List(_wrappers.Keys.Count);
- var keyCollection = _wrappers.Keys;
- foreach (var key in keyCollection)
- {
- keys.Add(key);
- }
- return keys;
- }
- }
+ ///
+ /// 获取缓存GUID集合
+ ///
+ public List GetAllCachedGUIDs()
+ {
+ List keys = new List(_wrappers.Keys.Count);
+ var keyCollection = _wrappers.Keys;
+ foreach (var key in keyCollection)
+ {
+ keys.Add(key);
+ }
+ return keys;
+ }
+ }
}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/CacheSystem/EVerifyLevel.cs b/Assets/YooAsset/Runtime/CacheSystem/EVerifyLevel.cs
index ac60421..966a922 100644
--- a/Assets/YooAsset/Runtime/CacheSystem/EVerifyLevel.cs
+++ b/Assets/YooAsset/Runtime/CacheSystem/EVerifyLevel.cs
@@ -1,24 +1,24 @@
namespace YooAsset
{
- ///
- /// 下载文件校验等级
- ///
- public enum EVerifyLevel
- {
- ///
- /// 验证文件存在
- ///
- Low,
+ ///
+ /// 下载文件校验等级
+ ///
+ public enum EVerifyLevel
+ {
+ ///
+ /// 验证文件存在
+ ///
+ Low,
- ///
- /// 验证文件大小
- ///
- Middle,
+ ///
+ /// 验证文件大小
+ ///
+ Middle,
- ///
- /// 验证文件大小和CRC
- ///
- High,
- }
+ ///
+ /// 验证文件大小和CRC
+ ///
+ High,
+ }
}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/CacheSystem/Operation/ClearAllCacheFilesOperation.cs b/Assets/YooAsset/Runtime/CacheSystem/Operation/ClearAllCacheFilesOperation.cs
index 9f3068a..deb1ac8 100644
--- a/Assets/YooAsset/Runtime/CacheSystem/Operation/ClearAllCacheFilesOperation.cs
+++ b/Assets/YooAsset/Runtime/CacheSystem/Operation/ClearAllCacheFilesOperation.cs
@@ -4,68 +4,68 @@ using System.IO;
namespace YooAsset
{
- ///
- /// 清理本地包裹所有的缓存文件
- ///
- public sealed class ClearAllCacheFilesOperation : AsyncOperationBase
- {
- private enum ESteps
- {
- None,
- GetAllCacheFiles,
- ClearAllCacheFiles,
- Done,
- }
+ ///
+ /// 清理本地包裹所有的缓存文件
+ ///
+ public sealed class ClearAllCacheFilesOperation : AsyncOperationBase
+ {
+ private enum ESteps
+ {
+ None,
+ GetAllCacheFiles,
+ ClearAllCacheFiles,
+ Done,
+ }
- private readonly CacheManager _cache;
- private List _allCacheGUIDs;
- private int _fileTotalCount = 0;
- private ESteps _steps = ESteps.None;
-
- internal ClearAllCacheFilesOperation(CacheManager cache)
- {
- _cache = cache;
- }
- internal override void InternalOnStart()
- {
- _steps = ESteps.GetAllCacheFiles;
- }
- internal override void InternalOnUpdate()
- {
- if (_steps == ESteps.None || _steps == ESteps.Done)
- return;
+ private readonly CacheManager _cache;
+ private List _allCacheGUIDs;
+ private int _fileTotalCount = 0;
+ private ESteps _steps = ESteps.None;
- if (_steps == ESteps.GetAllCacheFiles)
- {
- _allCacheGUIDs = _cache.GetAllCachedGUIDs();
- _fileTotalCount = _allCacheGUIDs.Count;
- YooLogger.Log($"Found all cache file count : {_fileTotalCount}");
- _steps = ESteps.ClearAllCacheFiles;
- }
+ internal ClearAllCacheFilesOperation(CacheManager cache)
+ {
+ _cache = cache;
+ }
+ internal override void InternalOnStart()
+ {
+ _steps = ESteps.GetAllCacheFiles;
+ }
+ internal override void InternalOnUpdate()
+ {
+ if (_steps == ESteps.None || _steps == ESteps.Done)
+ return;
- if (_steps == ESteps.ClearAllCacheFiles)
- {
- for (int i = _allCacheGUIDs.Count - 1; i >= 0; i--)
- {
- string cacheGUID = _allCacheGUIDs[i];
- _cache.Discard(cacheGUID);
- _allCacheGUIDs.RemoveAt(i);
+ if (_steps == ESteps.GetAllCacheFiles)
+ {
+ _allCacheGUIDs = _cache.GetAllCachedGUIDs();
+ _fileTotalCount = _allCacheGUIDs.Count;
+ YooLogger.Log($"Found all cache file count : {_fileTotalCount}");
+ _steps = ESteps.ClearAllCacheFiles;
+ }
- if (OperationSystem.IsBusy)
- break;
- }
+ if (_steps == ESteps.ClearAllCacheFiles)
+ {
+ for (int i = _allCacheGUIDs.Count - 1; i >= 0; i--)
+ {
+ string cacheGUID = _allCacheGUIDs[i];
+ _cache.Discard(cacheGUID);
+ _allCacheGUIDs.RemoveAt(i);
- if (_fileTotalCount == 0)
- Progress = 1.0f;
- else
- Progress = 1.0f - (_allCacheGUIDs.Count / _fileTotalCount);
+ if (OperationSystem.IsBusy)
+ break;
+ }
- if (_allCacheGUIDs.Count == 0)
- {
- _steps = ESteps.Done;
- Status = EOperationStatus.Succeed;
- }
- }
- }
- }
+ if (_fileTotalCount == 0)
+ Progress = 1.0f;
+ else
+ Progress = 1.0f - (_allCacheGUIDs.Count / _fileTotalCount);
+
+ if (_allCacheGUIDs.Count == 0)
+ {
+ _steps = ESteps.Done;
+ Status = EOperationStatus.Succeed;
+ }
+ }
+ }
+ }
}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/CacheSystem/Operation/ClearUnusedCacheFilesOperation.cs b/Assets/YooAsset/Runtime/CacheSystem/Operation/ClearUnusedCacheFilesOperation.cs
index 1df9d20..2db369f 100644
--- a/Assets/YooAsset/Runtime/CacheSystem/Operation/ClearUnusedCacheFilesOperation.cs
+++ b/Assets/YooAsset/Runtime/CacheSystem/Operation/ClearUnusedCacheFilesOperation.cs
@@ -4,84 +4,84 @@ using System.IO;
namespace YooAsset
{
- ///
- /// 清理本地包裹未使用的缓存文件
- ///
- public sealed class ClearUnusedCacheFilesOperation : AsyncOperationBase
- {
- private enum ESteps
- {
- None,
- GetUnusedCacheFiles,
- ClearUnusedCacheFiles,
- Done,
- }
+ ///
+ /// 清理本地包裹未使用的缓存文件
+ ///
+ public sealed class ClearUnusedCacheFilesOperation : AsyncOperationBase
+ {
+ private enum ESteps
+ {
+ None,
+ GetUnusedCacheFiles,
+ ClearUnusedCacheFiles,
+ Done,
+ }
- private readonly ResourcePackage _package;
- private readonly CacheManager _cache;
- private List _unusedCacheGUIDs;
- private int _unusedFileTotalCount = 0;
- private ESteps _steps = ESteps.None;
+ private readonly ResourcePackage _package;
+ private readonly CacheManager _cache;
+ private List _unusedCacheGUIDs;
+ private int _unusedFileTotalCount = 0;
+ private ESteps _steps = ESteps.None;
- internal ClearUnusedCacheFilesOperation(ResourcePackage package, CacheManager cache)
- {
- _package = package;
- _cache = cache;
- }
- internal override void InternalOnStart()
- {
- _steps = ESteps.GetUnusedCacheFiles;
- }
- internal override void InternalOnUpdate()
- {
- if (_steps == ESteps.None || _steps == ESteps.Done)
- return;
+ internal ClearUnusedCacheFilesOperation(ResourcePackage package, CacheManager cache)
+ {
+ _package = package;
+ _cache = cache;
+ }
+ internal override void InternalOnStart()
+ {
+ _steps = ESteps.GetUnusedCacheFiles;
+ }
+ internal override void InternalOnUpdate()
+ {
+ if (_steps == ESteps.None || _steps == ESteps.Done)
+ return;
- if (_steps == ESteps.GetUnusedCacheFiles)
- {
- _unusedCacheGUIDs = GetUnusedCacheGUIDs();
- _unusedFileTotalCount = _unusedCacheGUIDs.Count;
- YooLogger.Log($"Found unused cache file count : {_unusedFileTotalCount}");
- _steps = ESteps.ClearUnusedCacheFiles;
- }
+ if (_steps == ESteps.GetUnusedCacheFiles)
+ {
+ _unusedCacheGUIDs = GetUnusedCacheGUIDs();
+ _unusedFileTotalCount = _unusedCacheGUIDs.Count;
+ YooLogger.Log($"Found unused cache file count : {_unusedFileTotalCount}");
+ _steps = ESteps.ClearUnusedCacheFiles;
+ }
- if (_steps == ESteps.ClearUnusedCacheFiles)
- {
- for (int i = _unusedCacheGUIDs.Count - 1; i >= 0; i--)
- {
- string cacheGUID = _unusedCacheGUIDs[i];
- _cache.Discard(cacheGUID);
- _unusedCacheGUIDs.RemoveAt(i);
+ if (_steps == ESteps.ClearUnusedCacheFiles)
+ {
+ for (int i = _unusedCacheGUIDs.Count - 1; i >= 0; i--)
+ {
+ string cacheGUID = _unusedCacheGUIDs[i];
+ _cache.Discard(cacheGUID);
+ _unusedCacheGUIDs.RemoveAt(i);
- if (OperationSystem.IsBusy)
- break;
- }
+ if (OperationSystem.IsBusy)
+ break;
+ }
- if (_unusedFileTotalCount == 0)
- Progress = 1.0f;
- else
- Progress = 1.0f - (_unusedCacheGUIDs.Count / _unusedFileTotalCount);
+ if (_unusedFileTotalCount == 0)
+ Progress = 1.0f;
+ else
+ Progress = 1.0f - (_unusedCacheGUIDs.Count / _unusedFileTotalCount);
- if (_unusedCacheGUIDs.Count == 0)
- {
- _steps = ESteps.Done;
- Status = EOperationStatus.Succeed;
- }
- }
- }
+ if (_unusedCacheGUIDs.Count == 0)
+ {
+ _steps = ESteps.Done;
+ Status = EOperationStatus.Succeed;
+ }
+ }
+ }
- private List GetUnusedCacheGUIDs()
- {
- var allCacheGUIDs = _cache.GetAllCachedGUIDs();
- List result = new List(allCacheGUIDs.Count);
- foreach (var cacheGUID in allCacheGUIDs)
- {
- if (_package.IsIncludeBundleFile(cacheGUID) == false)
- {
- result.Add(cacheGUID);
- }
- }
- return result;
- }
- }
+ private List GetUnusedCacheGUIDs()
+ {
+ var allCacheGUIDs = _cache.GetAllCachedGUIDs();
+ List result = new List(allCacheGUIDs.Count);
+ foreach (var cacheGUID in allCacheGUIDs)
+ {
+ if (_package.IsIncludeBundleFile(cacheGUID) == false)
+ {
+ result.Add(cacheGUID);
+ }
+ }
+ return result;
+ }
+ }
}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/CacheSystem/Operation/Internal/FindCacheFilesOperation.cs b/Assets/YooAsset/Runtime/CacheSystem/Operation/Internal/FindCacheFilesOperation.cs
index 7158e9b..da6d2f8 100644
--- a/Assets/YooAsset/Runtime/CacheSystem/Operation/Internal/FindCacheFilesOperation.cs
+++ b/Assets/YooAsset/Runtime/CacheSystem/Operation/Internal/FindCacheFilesOperation.cs
@@ -5,127 +5,127 @@ using System.Collections.Generic;
namespace YooAsset
{
- internal sealed class FindCacheFilesOperation : AsyncOperationBase
- {
- private enum ESteps
- {
- None,
- Prepare,
- UpdateCacheFiles,
- Done,
- }
+ internal sealed class FindCacheFilesOperation : AsyncOperationBase
+ {
+ private enum ESteps
+ {
+ None,
+ Prepare,
+ UpdateCacheFiles,
+ Done,
+ }
- private readonly PersistentManager _persistent;
- private readonly CacheManager _cache;
- private IEnumerator _filesEnumerator = null;
- private float _verifyStartTime;
- private ESteps _steps = ESteps.None;
+ private readonly PersistentManager _persistent;
+ private readonly CacheManager _cache;
+ private IEnumerator _filesEnumerator = null;
+ private float _verifyStartTime;
+ private ESteps _steps = ESteps.None;
- ///
- /// 需要验证的元素
- ///
- public readonly List VerifyElements = new List(5000);
+ ///
+ /// 需要验证的元素
+ ///
+ public readonly List VerifyElements = new List(5000);
- public FindCacheFilesOperation(PersistentManager persistent, CacheManager cache)
- {
- _persistent = persistent;
- _cache = cache;
- }
- internal override void InternalOnStart()
- {
- _steps = ESteps.Prepare;
- _verifyStartTime = UnityEngine.Time.realtimeSinceStartup;
- }
- internal override void InternalOnUpdate()
- {
- if (_steps == ESteps.None || _steps == ESteps.Done)
- return;
+ public FindCacheFilesOperation(PersistentManager persistent, CacheManager cache)
+ {
+ _persistent = persistent;
+ _cache = cache;
+ }
+ internal override void InternalOnStart()
+ {
+ _steps = ESteps.Prepare;
+ _verifyStartTime = UnityEngine.Time.realtimeSinceStartup;
+ }
+ internal override void InternalOnUpdate()
+ {
+ if (_steps == ESteps.None || _steps == ESteps.Done)
+ return;
- if (_steps == ESteps.Prepare)
- {
- string rootPath = _persistent.SandboxCacheFilesRoot;
- DirectoryInfo rootDirectory = new DirectoryInfo(rootPath);
- if (rootDirectory.Exists)
- {
- var directorieInfos = rootDirectory.EnumerateDirectories();
- _filesEnumerator = directorieInfos.GetEnumerator();
- }
- _steps = ESteps.UpdateCacheFiles;
- }
+ if (_steps == ESteps.Prepare)
+ {
+ string rootPath = _persistent.SandboxCacheFilesRoot;
+ DirectoryInfo rootDirectory = new DirectoryInfo(rootPath);
+ if (rootDirectory.Exists)
+ {
+ var directorieInfos = rootDirectory.EnumerateDirectories();
+ _filesEnumerator = directorieInfos.GetEnumerator();
+ }
+ _steps = ESteps.UpdateCacheFiles;
+ }
- if (_steps == ESteps.UpdateCacheFiles)
- {
- if (UpdateCacheFiles())
- return;
+ if (_steps == ESteps.UpdateCacheFiles)
+ {
+ if (UpdateCacheFiles())
+ return;
- // 注意:总是返回成功
- _steps = ESteps.Done;
- Status = EOperationStatus.Succeed;
- float costTime = UnityEngine.Time.realtimeSinceStartup - _verifyStartTime;
- YooLogger.Log($"Find cache files elapsed time {costTime:f1} seconds");
- }
- }
+ // 注意:总是返回成功
+ _steps = ESteps.Done;
+ Status = EOperationStatus.Succeed;
+ float costTime = UnityEngine.Time.realtimeSinceStartup - _verifyStartTime;
+ YooLogger.Log($"Find cache files elapsed time {costTime:f1} seconds");
+ }
+ }
- private bool UpdateCacheFiles()
- {
- if (_filesEnumerator == null)
- return false;
+ private bool UpdateCacheFiles()
+ {
+ if (_filesEnumerator == null)
+ return false;
- bool isFindItem;
- while (true)
- {
- isFindItem = _filesEnumerator.MoveNext();
- if (isFindItem == false)
- break;
+ bool isFindItem;
+ while (true)
+ {
+ isFindItem = _filesEnumerator.MoveNext();
+ if (isFindItem == false)
+ break;
- var rootFoder = _filesEnumerator.Current;
- var childDirectories = rootFoder.GetDirectories();
- foreach (var chidDirectory in childDirectories)
- {
- string cacheGUID = chidDirectory.Name;
- if (_cache.IsCached(cacheGUID))
- continue;
+ var rootFoder = _filesEnumerator.Current;
+ var childDirectories = rootFoder.GetDirectories();
+ foreach (var chidDirectory in childDirectories)
+ {
+ string cacheGUID = chidDirectory.Name;
+ if (_cache.IsCached(cacheGUID))
+ continue;
- // 创建验证元素类
- string fileRootPath = chidDirectory.FullName;
- string dataFilePath = $"{fileRootPath}/{ YooAssetSettings.CacheBundleDataFileName}";
- string infoFilePath = $"{fileRootPath}/{ YooAssetSettings.CacheBundleInfoFileName}";
- string dataFileExtension = FindDataFileExtension(chidDirectory);
+ // 创建验证元素类
+ string fileRootPath = chidDirectory.FullName;
+ string dataFilePath = $"{fileRootPath}/{ YooAssetSettings.CacheBundleDataFileName}";
+ string infoFilePath = $"{fileRootPath}/{ YooAssetSettings.CacheBundleInfoFileName}";
+ string dataFileExtension = FindDataFileExtension(chidDirectory);
- // 跳过断点续传的临时文件
- if (dataFileExtension == ".temp")
- continue;
+ // 跳过断点续传的临时文件
+ if (dataFileExtension == ".temp")
+ continue;
- // 注意:根据配置需求数据文件会带文件格式
- if (_persistent.AppendFileExtension)
- {
- if (string.IsNullOrEmpty(dataFileExtension) == false)
- dataFilePath += dataFileExtension;
- }
+ // 注意:根据配置需求数据文件会带文件格式
+ if (_persistent.AppendFileExtension)
+ {
+ if (string.IsNullOrEmpty(dataFileExtension) == false)
+ dataFilePath += dataFileExtension;
+ }
- VerifyCacheFileElement element = new VerifyCacheFileElement(_cache.PackageName, cacheGUID, fileRootPath, dataFilePath, infoFilePath);
- VerifyElements.Add(element);
- }
+ VerifyCacheFileElement element = new VerifyCacheFileElement(_cache.PackageName, cacheGUID, fileRootPath, dataFilePath, infoFilePath);
+ VerifyElements.Add(element);
+ }
- if (OperationSystem.IsBusy)
- break;
- }
+ if (OperationSystem.IsBusy)
+ break;
+ }
- return isFindItem;
- }
- private string FindDataFileExtension(DirectoryInfo directoryInfo)
- {
- string dataFileExtension = string.Empty;
- var fileInfos = directoryInfo.GetFiles();
- foreach (var fileInfo in fileInfos)
- {
- if (fileInfo.Name.StartsWith(YooAssetSettings.CacheBundleDataFileName))
- {
- dataFileExtension = fileInfo.Extension;
- break;
- }
- }
- return dataFileExtension;
- }
- }
+ return isFindItem;
+ }
+ private string FindDataFileExtension(DirectoryInfo directoryInfo)
+ {
+ string dataFileExtension = string.Empty;
+ var fileInfos = directoryInfo.GetFiles();
+ foreach (var fileInfo in fileInfos)
+ {
+ if (fileInfo.Name.StartsWith(YooAssetSettings.CacheBundleDataFileName))
+ {
+ dataFileExtension = fileInfo.Extension;
+ break;
+ }
+ }
+ return dataFileExtension;
+ }
+ }
}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/CacheSystem/Operation/Internal/VerifyCacheFilesOperation.cs b/Assets/YooAsset/Runtime/CacheSystem/Operation/Internal/VerifyCacheFilesOperation.cs
index 56e9289..45f6d7e 100644
--- a/Assets/YooAsset/Runtime/CacheSystem/Operation/Internal/VerifyCacheFilesOperation.cs
+++ b/Assets/YooAsset/Runtime/CacheSystem/Operation/Internal/VerifyCacheFilesOperation.cs
@@ -6,249 +6,249 @@ using System.Threading;
namespace YooAsset
{
- internal abstract class VerifyCacheFilesOperation : AsyncOperationBase
- {
- public static VerifyCacheFilesOperation CreateOperation(CacheManager cache, List elements)
- {
+ internal abstract class VerifyCacheFilesOperation : AsyncOperationBase
+ {
+ public static VerifyCacheFilesOperation CreateOperation(CacheManager cache, List elements)
+ {
#if UNITY_WEBGL
var operation = new VerifyCacheFilesWithoutThreadOperation(cache, elements);
#else
- var operation = new VerifyCacheFilesWithThreadOperation(cache, elements);
+ var operation = new VerifyCacheFilesWithThreadOperation(cache, elements);
#endif
- return operation;
- }
- }
+ return operation;
+ }
+ }
- ///
- /// 本地缓存文件验证(线程版)
- ///
- internal class VerifyCacheFilesWithThreadOperation : VerifyCacheFilesOperation
- {
- private enum ESteps
- {
- None,
- InitVerify,
- UpdateVerify,
- Done,
- }
+ ///
+ /// 本地缓存文件验证(线程版)
+ ///
+ internal class VerifyCacheFilesWithThreadOperation : VerifyCacheFilesOperation
+ {
+ private enum ESteps
+ {
+ None,
+ InitVerify,
+ UpdateVerify,
+ Done,
+ }
- private readonly ThreadSyncContext _syncContext = new ThreadSyncContext();
- private readonly CacheManager _cache;
- private List _waitingList;
- private List _verifyingList;
- private int _verifyMaxNum;
- private int _verifyTotalCount;
- private float _verifyStartTime;
- private int _succeedCount;
- private int _failedCount;
- private ESteps _steps = ESteps.None;
+ private readonly ThreadSyncContext _syncContext = new ThreadSyncContext();
+ private readonly CacheManager _cache;
+ private List _waitingList;
+ private List _verifyingList;
+ private int _verifyMaxNum;
+ private int _verifyTotalCount;
+ private float _verifyStartTime;
+ private int _succeedCount;
+ private int _failedCount;
+ private ESteps _steps = ESteps.None;
- public VerifyCacheFilesWithThreadOperation(CacheManager cache, List elements)
- {
- _cache = cache;
- _waitingList = elements;
- }
- internal override void InternalOnStart()
- {
- _steps = ESteps.InitVerify;
- _verifyStartTime = UnityEngine.Time.realtimeSinceStartup;
- }
- internal override void InternalOnUpdate()
- {
- if (_steps == ESteps.None || _steps == ESteps.Done)
- return;
+ public VerifyCacheFilesWithThreadOperation(CacheManager cache, List elements)
+ {
+ _cache = cache;
+ _waitingList = elements;
+ }
+ internal override void InternalOnStart()
+ {
+ _steps = ESteps.InitVerify;
+ _verifyStartTime = UnityEngine.Time.realtimeSinceStartup;
+ }
+ internal override void InternalOnUpdate()
+ {
+ if (_steps == ESteps.None || _steps == ESteps.Done)
+ return;
- if (_steps == ESteps.InitVerify)
- {
- int fileCount = _waitingList.Count;
+ if (_steps == ESteps.InitVerify)
+ {
+ int fileCount = _waitingList.Count;
- // 设置同时验证的最大数
- ThreadPool.GetMaxThreads(out int workerThreads, out int ioThreads);
- YooLogger.Log($"Work threads : {workerThreads}, IO threads : {ioThreads}");
- _verifyMaxNum = Math.Min(workerThreads, ioThreads);
- _verifyTotalCount = fileCount;
- if (_verifyMaxNum < 1)
- _verifyMaxNum = 1;
+ // 设置同时验证的最大数
+ ThreadPool.GetMaxThreads(out int workerThreads, out int ioThreads);
+ YooLogger.Log($"Work threads : {workerThreads}, IO threads : {ioThreads}");
+ _verifyMaxNum = Math.Min(workerThreads, ioThreads);
+ _verifyTotalCount = fileCount;
+ if (_verifyMaxNum < 1)
+ _verifyMaxNum = 1;
- _verifyingList = new List(_verifyMaxNum);
- _steps = ESteps.UpdateVerify;
- }
+ _verifyingList = new List(_verifyMaxNum);
+ _steps = ESteps.UpdateVerify;
+ }
- if (_steps == ESteps.UpdateVerify)
- {
- _syncContext.Update();
+ if (_steps == ESteps.UpdateVerify)
+ {
+ _syncContext.Update();
- Progress = GetProgress();
- if (_waitingList.Count == 0 && _verifyingList.Count == 0)
- {
- _steps = ESteps.Done;
- Status = EOperationStatus.Succeed;
- float costTime = UnityEngine.Time.realtimeSinceStartup - _verifyStartTime;
- YooLogger.Log($"Verify cache files elapsed time {costTime:f1} seconds");
- }
+ Progress = GetProgress();
+ if (_waitingList.Count == 0 && _verifyingList.Count == 0)
+ {
+ _steps = ESteps.Done;
+ Status = EOperationStatus.Succeed;
+ float costTime = UnityEngine.Time.realtimeSinceStartup - _verifyStartTime;
+ YooLogger.Log($"Verify cache files elapsed time {costTime:f1} seconds");
+ }
- for (int i = _waitingList.Count - 1; i >= 0; i--)
- {
- if (OperationSystem.IsBusy)
- break;
+ for (int i = _waitingList.Count - 1; i >= 0; i--)
+ {
+ if (OperationSystem.IsBusy)
+ break;
- if (_verifyingList.Count >= _verifyMaxNum)
- break;
+ if (_verifyingList.Count >= _verifyMaxNum)
+ break;
- var element = _waitingList[i];
- if (BeginVerifyFileWithThread(element))
- {
- _waitingList.RemoveAt(i);
- _verifyingList.Add(element);
- }
- else
- {
- YooLogger.Warning("The thread pool is failed queued.");
- break;
- }
- }
- }
- }
+ var element = _waitingList[i];
+ if (BeginVerifyFileWithThread(element))
+ {
+ _waitingList.RemoveAt(i);
+ _verifyingList.Add(element);
+ }
+ else
+ {
+ YooLogger.Warning("The thread pool is failed queued.");
+ break;
+ }
+ }
+ }
+ }
- private float GetProgress()
- {
- if (_verifyTotalCount == 0)
- return 1f;
- return (float)(_succeedCount + _failedCount) / _verifyTotalCount;
- }
- private bool BeginVerifyFileWithThread(VerifyCacheFileElement element)
- {
- return ThreadPool.QueueUserWorkItem(new WaitCallback(VerifyInThread), element);
- }
- private void VerifyInThread(object obj)
- {
- VerifyCacheFileElement element = (VerifyCacheFileElement)obj;
- element.Result = CacheHelper.VerifyingCacheFile(element, _cache.BootVerifyLevel);
- _syncContext.Post(VerifyCallback, element);
- }
- private void VerifyCallback(object obj)
- {
- VerifyCacheFileElement element = (VerifyCacheFileElement)obj;
- _verifyingList.Remove(element);
+ private float GetProgress()
+ {
+ if (_verifyTotalCount == 0)
+ return 1f;
+ return (float)(_succeedCount + _failedCount) / _verifyTotalCount;
+ }
+ private bool BeginVerifyFileWithThread(VerifyCacheFileElement element)
+ {
+ return ThreadPool.QueueUserWorkItem(new WaitCallback(VerifyInThread), element);
+ }
+ private void VerifyInThread(object obj)
+ {
+ VerifyCacheFileElement element = (VerifyCacheFileElement)obj;
+ element.Result = CacheHelper.VerifyingCacheFile(element, _cache.BootVerifyLevel);
+ _syncContext.Post(VerifyCallback, element);
+ }
+ private void VerifyCallback(object obj)
+ {
+ VerifyCacheFileElement element = (VerifyCacheFileElement)obj;
+ _verifyingList.Remove(element);
- if (element.Result == EVerifyResult.Succeed)
- {
- _succeedCount++;
- var wrapper = new CacheManager.RecordWrapper(element.InfoFilePath, element.DataFilePath, element.DataFileCRC, element.DataFileSize);
- _cache.Record(element.CacheGUID, wrapper);
- }
- else
- {
- _failedCount++;
+ if (element.Result == EVerifyResult.Succeed)
+ {
+ _succeedCount++;
+ var wrapper = new CacheManager.RecordWrapper(element.InfoFilePath, element.DataFilePath, element.DataFileCRC, element.DataFileSize);
+ _cache.Record(element.CacheGUID, wrapper);
+ }
+ else
+ {
+ _failedCount++;
- YooLogger.Warning($"Failed verify file and delete files : {element.FileRootPath}");
- element.DeleteFiles();
- }
- }
- }
+ YooLogger.Warning($"Failed verify file and delete files : {element.FileRootPath}");
+ element.DeleteFiles();
+ }
+ }
+ }
- ///
- /// 本地缓存文件验证(非线程版)
- ///
- internal class VerifyCacheFilesWithoutThreadOperation : VerifyCacheFilesOperation
- {
- private enum ESteps
- {
- None,
- InitVerify,
- UpdateVerify,
- Done,
- }
+ ///
+ /// 本地缓存文件验证(非线程版)
+ ///
+ internal class VerifyCacheFilesWithoutThreadOperation : VerifyCacheFilesOperation
+ {
+ private enum ESteps
+ {
+ None,
+ InitVerify,
+ UpdateVerify,
+ Done,
+ }
- private readonly CacheManager _cache;
- private List _waitingList;
- private List _verifyingList;
- private int _verifyMaxNum;
- private int _verifyTotalCount;
- private float _verifyStartTime;
- private int _succeedCount;
- private int _failedCount;
- private ESteps _steps = ESteps.None;
-
- public VerifyCacheFilesWithoutThreadOperation(CacheManager cache, List elements)
- {
- _cache = cache;
- _waitingList = elements;
- }
- internal override void InternalOnStart()
- {
- _steps = ESteps.InitVerify;
- _verifyStartTime = UnityEngine.Time.realtimeSinceStartup;
- }
- internal override void InternalOnUpdate()
- {
- if (_steps == ESteps.None || _steps == ESteps.Done)
- return;
+ private readonly CacheManager _cache;
+ private List _waitingList;
+ private List _verifyingList;
+ private int _verifyMaxNum;
+ private int _verifyTotalCount;
+ private float _verifyStartTime;
+ private int _succeedCount;
+ private int _failedCount;
+ private ESteps _steps = ESteps.None;
- if (_steps == ESteps.InitVerify)
- {
- int fileCount = _waitingList.Count;
+ public VerifyCacheFilesWithoutThreadOperation(CacheManager cache, List elements)
+ {
+ _cache = cache;
+ _waitingList = elements;
+ }
+ internal override void InternalOnStart()
+ {
+ _steps = ESteps.InitVerify;
+ _verifyStartTime = UnityEngine.Time.realtimeSinceStartup;
+ }
+ internal override void InternalOnUpdate()
+ {
+ if (_steps == ESteps.None || _steps == ESteps.Done)
+ return;
- // 设置同时验证的最大数
- _verifyMaxNum = fileCount;
- _verifyTotalCount = fileCount;
+ if (_steps == ESteps.InitVerify)
+ {
+ int fileCount = _waitingList.Count;
- _verifyingList = new List(_verifyMaxNum);
- _steps = ESteps.UpdateVerify;
- }
+ // 设置同时验证的最大数
+ _verifyMaxNum = fileCount;
+ _verifyTotalCount = fileCount;
- if (_steps == ESteps.UpdateVerify)
- {
- Progress = GetProgress();
- if (_waitingList.Count == 0 && _verifyingList.Count == 0)
- {
- _steps = ESteps.Done;
- Status = EOperationStatus.Succeed;
- float costTime = UnityEngine.Time.realtimeSinceStartup - _verifyStartTime;
- YooLogger.Log($"Package verify elapsed time {costTime:f1} seconds");
- }
+ _verifyingList = new List(_verifyMaxNum);
+ _steps = ESteps.UpdateVerify;
+ }
- for (int i = _waitingList.Count - 1; i >= 0; i--)
- {
- if (OperationSystem.IsBusy)
- break;
+ if (_steps == ESteps.UpdateVerify)
+ {
+ Progress = GetProgress();
+ if (_waitingList.Count == 0 && _verifyingList.Count == 0)
+ {
+ _steps = ESteps.Done;
+ Status = EOperationStatus.Succeed;
+ float costTime = UnityEngine.Time.realtimeSinceStartup - _verifyStartTime;
+ YooLogger.Log($"Package verify elapsed time {costTime:f1} seconds");
+ }
- if (_verifyingList.Count >= _verifyMaxNum)
- break;
+ for (int i = _waitingList.Count - 1; i >= 0; i--)
+ {
+ if (OperationSystem.IsBusy)
+ break;
- var element = _waitingList[i];
- BeginVerifyFileWithoutThread(element);
- _waitingList.RemoveAt(i);
- _verifyingList.Add(element);
- }
+ if (_verifyingList.Count >= _verifyMaxNum)
+ break;
- // 主线程内验证,可以清空列表
- _verifyingList.Clear();
- }
- }
+ var element = _waitingList[i];
+ BeginVerifyFileWithoutThread(element);
+ _waitingList.RemoveAt(i);
+ _verifyingList.Add(element);
+ }
- private float GetProgress()
- {
- if (_verifyTotalCount == 0)
- return 1f;
- return (float)(_succeedCount + _failedCount) / _verifyTotalCount;
- }
- private void BeginVerifyFileWithoutThread(VerifyCacheFileElement element)
- {
- element.Result = CacheHelper.VerifyingCacheFile(element, _cache.BootVerifyLevel);
- if (element.Result == EVerifyResult.Succeed)
- {
- _succeedCount++;
- var wrapper = new CacheManager.RecordWrapper(element.InfoFilePath, element.DataFilePath, element.DataFileCRC, element.DataFileSize);
- _cache.Record(element.CacheGUID, wrapper);
- }
- else
- {
- _failedCount++;
+ // 主线程内验证,可以清空列表
+ _verifyingList.Clear();
+ }
+ }
- YooLogger.Warning($"Failed verify file and delete files : {element.FileRootPath}");
- element.DeleteFiles();
- }
- }
- }
+ private float GetProgress()
+ {
+ if (_verifyTotalCount == 0)
+ return 1f;
+ return (float)(_succeedCount + _failedCount) / _verifyTotalCount;
+ }
+ private void BeginVerifyFileWithoutThread(VerifyCacheFileElement element)
+ {
+ element.Result = CacheHelper.VerifyingCacheFile(element, _cache.BootVerifyLevel);
+ if (element.Result == EVerifyResult.Succeed)
+ {
+ _succeedCount++;
+ var wrapper = new CacheManager.RecordWrapper(element.InfoFilePath, element.DataFilePath, element.DataFileCRC, element.DataFileSize);
+ _cache.Record(element.CacheGUID, wrapper);
+ }
+ else
+ {
+ _failedCount++;
+
+ YooLogger.Warning($"Failed verify file and delete files : {element.FileRootPath}");
+ element.DeleteFiles();
+ }
+ }
+ }
}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/CacheSystem/Operation/Internal/VerifyTempFileOperation.cs b/Assets/YooAsset/Runtime/CacheSystem/Operation/Internal/VerifyTempFileOperation.cs
index 3ae558a..0b96ff6 100644
--- a/Assets/YooAsset/Runtime/CacheSystem/Operation/Internal/VerifyTempFileOperation.cs
+++ b/Assets/YooAsset/Runtime/CacheSystem/Operation/Internal/VerifyTempFileOperation.cs
@@ -6,136 +6,136 @@ using System.Threading;
namespace YooAsset
{
- internal abstract class VerifyTempFileOperation : AsyncOperationBase
- {
- public EVerifyResult VerifyResult { protected set; get; }
+ internal abstract class VerifyTempFileOperation : AsyncOperationBase
+ {
+ public EVerifyResult VerifyResult { protected set; get; }
- public static VerifyTempFileOperation CreateOperation(VerifyTempFileElement element)
- {
+ public static VerifyTempFileOperation CreateOperation(VerifyTempFileElement element)
+ {
#if UNITY_WEBGL
var operation = new VerifyTempFileWithoutThreadOperation(element);
#else
- var operation = new VerifyTempFileWithThreadOperation(element);
+ var operation = new VerifyTempFileWithThreadOperation(element);
#endif
- return operation;
- }
- }
+ return operation;
+ }
+ }
- ///
- /// 下载文件验证(线程版)
- ///
- internal class VerifyTempFileWithThreadOperation : VerifyTempFileOperation
- {
- private enum ESteps
- {
- None,
- VerifyFile,
- Waiting,
- Done,
- }
+ ///
+ /// 下载文件验证(线程版)
+ ///
+ internal class VerifyTempFileWithThreadOperation : VerifyTempFileOperation
+ {
+ private enum ESteps
+ {
+ None,
+ VerifyFile,
+ Waiting,
+ Done,
+ }
- private readonly VerifyTempFileElement _element;
- private ESteps _steps = ESteps.None;
+ private readonly VerifyTempFileElement _element;
+ private ESteps _steps = ESteps.None;
- public VerifyTempFileWithThreadOperation(VerifyTempFileElement element)
- {
- _element = element;
- }
- internal override void InternalOnStart()
- {
- _steps = ESteps.VerifyFile;
- }
- internal override void InternalOnUpdate()
- {
- if (_steps == ESteps.None || _steps == ESteps.Done)
- return;
+ public VerifyTempFileWithThreadOperation(VerifyTempFileElement element)
+ {
+ _element = element;
+ }
+ internal override void InternalOnStart()
+ {
+ _steps = ESteps.VerifyFile;
+ }
+ internal override void InternalOnUpdate()
+ {
+ if (_steps == ESteps.None || _steps == ESteps.Done)
+ return;
- if (_steps == ESteps.VerifyFile)
- {
- if (BeginVerifyFileWithThread(_element))
- {
- _steps = ESteps.Waiting;
- }
- }
+ if (_steps == ESteps.VerifyFile)
+ {
+ if (BeginVerifyFileWithThread(_element))
+ {
+ _steps = ESteps.Waiting;
+ }
+ }
- if (_steps == ESteps.Waiting)
- {
- int result = _element.Result;
- if (result == 0)
- return;
+ if (_steps == ESteps.Waiting)
+ {
+ int result = _element.Result;
+ if (result == 0)
+ return;
- VerifyResult = (EVerifyResult)result;
- if (VerifyResult == EVerifyResult.Succeed)
- {
- _steps = ESteps.Done;
- Status = EOperationStatus.Succeed;
- }
- else
- {
- _steps = ESteps.Done;
- Status = EOperationStatus.Failed;
- Error = $"Failed verify file : {_element.TempDataFilePath} ! ErrorCode : {VerifyResult}";
- }
- }
- }
+ VerifyResult = (EVerifyResult)result;
+ if (VerifyResult == EVerifyResult.Succeed)
+ {
+ _steps = ESteps.Done;
+ Status = EOperationStatus.Succeed;
+ }
+ else
+ {
+ _steps = ESteps.Done;
+ Status = EOperationStatus.Failed;
+ Error = $"Failed verify file : {_element.TempDataFilePath} ! ErrorCode : {VerifyResult}";
+ }
+ }
+ }
- private bool BeginVerifyFileWithThread(VerifyTempFileElement element)
- {
- return ThreadPool.QueueUserWorkItem(new WaitCallback(VerifyInThread), element);
- }
- private void VerifyInThread(object obj)
- {
- VerifyTempFileElement element = (VerifyTempFileElement)obj;
- int result = (int)CacheHelper.VerifyingTempFile(element);
- element.Result = result;
- }
- }
+ private bool BeginVerifyFileWithThread(VerifyTempFileElement element)
+ {
+ return ThreadPool.QueueUserWorkItem(new WaitCallback(VerifyInThread), element);
+ }
+ private void VerifyInThread(object obj)
+ {
+ VerifyTempFileElement element = (VerifyTempFileElement)obj;
+ int result = (int)CacheHelper.VerifyingTempFile(element);
+ element.Result = result;
+ }
+ }
- ///
- /// 下载文件验证(非线程版)
- ///
- internal class VerifyTempFileWithoutThreadOperation : VerifyTempFileOperation
- {
- private enum ESteps
- {
- None,
- VerifyFile,
- Done,
- }
+ ///
+ /// 下载文件验证(非线程版)
+ ///
+ internal class VerifyTempFileWithoutThreadOperation : VerifyTempFileOperation
+ {
+ private enum ESteps
+ {
+ None,
+ VerifyFile,
+ Done,
+ }
- private readonly VerifyTempFileElement _element;
- private ESteps _steps = ESteps.None;
+ private readonly VerifyTempFileElement _element;
+ private ESteps _steps = ESteps.None;
- public VerifyTempFileWithoutThreadOperation(VerifyTempFileElement element)
- {
- _element = element;
- }
- internal override void InternalOnStart()
- {
- _steps = ESteps.VerifyFile;
- }
- internal override void InternalOnUpdate()
- {
- if (_steps == ESteps.None || _steps == ESteps.Done)
- return;
+ public VerifyTempFileWithoutThreadOperation(VerifyTempFileElement element)
+ {
+ _element = element;
+ }
+ internal override void InternalOnStart()
+ {
+ _steps = ESteps.VerifyFile;
+ }
+ internal override void InternalOnUpdate()
+ {
+ if (_steps == ESteps.None || _steps == ESteps.Done)
+ return;
- if (_steps == ESteps.VerifyFile)
- {
- _element.Result = (int)CacheHelper.VerifyingTempFile(_element);
+ if (_steps == ESteps.VerifyFile)
+ {
+ _element.Result = (int)CacheHelper.VerifyingTempFile(_element);
- VerifyResult = (EVerifyResult)_element.Result;
- if (VerifyResult == EVerifyResult.Succeed)
- {
- _steps = ESteps.Done;
- Status = EOperationStatus.Succeed;
- }
- else
- {
- _steps = ESteps.Done;
- Status = EOperationStatus.Failed;
- Error = $"Failed verify file : {_element.TempDataFilePath} ! ErrorCode : {VerifyResult}";
- }
- }
- }
- }
+ VerifyResult = (EVerifyResult)_element.Result;
+ if (VerifyResult == EVerifyResult.Succeed)
+ {
+ _steps = ESteps.Done;
+ Status = EOperationStatus.Succeed;
+ }
+ else
+ {
+ _steps = ESteps.Done;
+ Status = EOperationStatus.Failed;
+ Error = $"Failed verify file : {_element.TempDataFilePath} ! ErrorCode : {VerifyResult}";
+ }
+ }
+ }
+ }
}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/CacheSystem/Operation/PackageCachingOperation.cs b/Assets/YooAsset/Runtime/CacheSystem/Operation/PackageCachingOperation.cs
index ad867a0..c8611bf 100644
--- a/Assets/YooAsset/Runtime/CacheSystem/Operation/PackageCachingOperation.cs
+++ b/Assets/YooAsset/Runtime/CacheSystem/Operation/PackageCachingOperation.cs
@@ -5,70 +5,70 @@ using System.Collections.Generic;
namespace YooAsset
{
- internal class PackageCachingOperation : AsyncOperationBase
- {
- private enum ESteps
- {
- None,
- FindCacheFiles,
- VerifyCacheFiles,
- Done,
- }
+ internal class PackageCachingOperation : AsyncOperationBase
+ {
+ private enum ESteps
+ {
+ None,
+ FindCacheFiles,
+ VerifyCacheFiles,
+ Done,
+ }
- private readonly PersistentManager _persistent;
- private readonly CacheManager _cache;
- private FindCacheFilesOperation _findCacheFilesOp;
- private VerifyCacheFilesOperation _verifyCacheFilesOp;
- private ESteps _steps = ESteps.None;
+ private readonly PersistentManager _persistent;
+ private readonly CacheManager _cache;
+ private FindCacheFilesOperation _findCacheFilesOp;
+ private VerifyCacheFilesOperation _verifyCacheFilesOp;
+ private ESteps _steps = ESteps.None;
- public PackageCachingOperation(PersistentManager persistent, CacheManager cache)
- {
- _persistent = persistent;
- _cache = cache;
- }
- internal override void InternalOnStart()
- {
- _steps = ESteps.FindCacheFiles;
- }
- internal override void InternalOnUpdate()
- {
- if (_steps == ESteps.None || _steps == ESteps.Done)
- return;
+ public PackageCachingOperation(PersistentManager persistent, CacheManager cache)
+ {
+ _persistent = persistent;
+ _cache = cache;
+ }
+ internal override void InternalOnStart()
+ {
+ _steps = ESteps.FindCacheFiles;
+ }
+ internal override void InternalOnUpdate()
+ {
+ if (_steps == ESteps.None || _steps == ESteps.Done)
+ return;
- if (_steps == ESteps.FindCacheFiles)
- {
- if (_findCacheFilesOp == null)
- {
- _findCacheFilesOp = new FindCacheFilesOperation(_persistent, _cache);
- OperationSystem.StartOperation(_cache.PackageName, _findCacheFilesOp);
- }
+ if (_steps == ESteps.FindCacheFiles)
+ {
+ if (_findCacheFilesOp == null)
+ {
+ _findCacheFilesOp = new FindCacheFilesOperation(_persistent, _cache);
+ OperationSystem.StartOperation(_cache.PackageName, _findCacheFilesOp);
+ }
- Progress = _findCacheFilesOp.Progress;
- if (_findCacheFilesOp.IsDone == false)
- return;
+ Progress = _findCacheFilesOp.Progress;
+ if (_findCacheFilesOp.IsDone == false)
+ return;
- _steps = ESteps.VerifyCacheFiles;
- }
+ _steps = ESteps.VerifyCacheFiles;
+ }
- if (_steps == ESteps.VerifyCacheFiles)
- {
- if (_verifyCacheFilesOp == null)
- {
- _verifyCacheFilesOp = VerifyCacheFilesOperation.CreateOperation(_cache, _findCacheFilesOp.VerifyElements);
- OperationSystem.StartOperation(_cache.PackageName, _verifyCacheFilesOp);
- }
+ if (_steps == ESteps.VerifyCacheFiles)
+ {
+ if (_verifyCacheFilesOp == null)
+ {
+ _verifyCacheFilesOp = VerifyCacheFilesOperation.CreateOperation(_cache, _findCacheFilesOp.VerifyElements);
+ OperationSystem.StartOperation(_cache.PackageName, _verifyCacheFilesOp);
+ }
- Progress = _verifyCacheFilesOp.Progress;
- if (_verifyCacheFilesOp.IsDone == false)
- return;
+ Progress = _verifyCacheFilesOp.Progress;
+ if (_verifyCacheFilesOp.IsDone == false)
+ return;
- // 注意:总是返回成功
- _steps = ESteps.Done;
- Status = EOperationStatus.Succeed;
+ // 注意:总是返回成功
+ _steps = ESteps.Done;
+ Status = EOperationStatus.Succeed;
- int totalCount = _cache.GetAllCachedFilesCount();
- YooLogger.Log($"Package '{_cache.PackageName}' cached files count : {totalCount}");
- }
- }
- }
+ int totalCount = _cache.GetAllCachedFilesCount();
+ YooLogger.Log($"Package '{_cache.PackageName}' cached files count : {totalCount}");
+ }
+ }
+ }
}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/CacheSystem/PersistentHelper.cs b/Assets/YooAsset/Runtime/CacheSystem/PersistentHelper.cs
index 8b6cbc1..ccd1b7a 100644
--- a/Assets/YooAsset/Runtime/CacheSystem/PersistentHelper.cs
+++ b/Assets/YooAsset/Runtime/CacheSystem/PersistentHelper.cs
@@ -1,15 +1,15 @@
namespace YooAsset
{
- internal static class PersistentHelper
- {
- ///
- /// 获取WWW加载本地资源的路径
- ///
- public static string ConvertToWWWPath(string path)
- {
+ internal static class PersistentHelper
+ {
+ ///
+ /// 获取WWW加载本地资源的路径
+ ///
+ public static string ConvertToWWWPath(string path)
+ {
#if UNITY_EDITOR
- return StringUtility.Format("file:///{0}", path);
+ return StringUtility.Format("file:///{0}", path);
#elif UNITY_WEBGL
return path;
#elif UNITY_IPHONE
@@ -23,6 +23,6 @@ namespace YooAsset
#else
return path;
#endif
- }
- }
+ }
+ }
}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/CacheSystem/PersistentManager.cs b/Assets/YooAsset/Runtime/CacheSystem/PersistentManager.cs
index bc9468a..1f163e2 100644
--- a/Assets/YooAsset/Runtime/CacheSystem/PersistentManager.cs
+++ b/Assets/YooAsset/Runtime/CacheSystem/PersistentManager.cs
@@ -5,207 +5,207 @@ using System.Collections.Generic;
namespace YooAsset
{
- internal class PersistentManager
- {
- private readonly Dictionary _cachedDataFilePaths = new Dictionary(10000);
- private readonly Dictionary _cachedInfoFilePaths = new Dictionary(10000);
- private readonly Dictionary _tempDataFilePaths = new Dictionary(10000);
- private readonly Dictionary _buildinFilePaths = new Dictionary(10000);
+ internal class PersistentManager
+ {
+ private readonly Dictionary _cachedDataFilePaths = new Dictionary(10000);
+ private readonly Dictionary _cachedInfoFilePaths = new Dictionary(10000);
+ private readonly Dictionary _tempDataFilePaths = new Dictionary(10000);
+ private readonly Dictionary _buildinFilePaths = new Dictionary(10000);
- ///
- /// 所属包裹
- ///
- public readonly string PackageName;
+ ///
+ /// 所属包裹
+ ///
+ public readonly string PackageName;
- public string BuildinRoot { private set; get; }
- public string BuildinPackageRoot { private set; get; }
+ public string BuildinRoot { private set; get; }
+ public string BuildinPackageRoot { private set; get; }
- public string SandboxRoot { private set; get; }
- public string SandboxPackageRoot { private set; get; }
- public string SandboxCacheFilesRoot { private set; get; }
- public string SandboxManifestFilesRoot { private set; get; }
- public string SandboxAppFootPrintFilePath { private set; get; }
+ public string SandboxRoot { private set; get; }
+ public string SandboxPackageRoot { private set; get; }
+ public string SandboxCacheFilesRoot { private set; get; }
+ public string SandboxManifestFilesRoot { private set; get; }
+ public string SandboxAppFootPrintFilePath { private set; get; }
- public bool AppendFileExtension { private set; get; }
+ public bool AppendFileExtension { private set; get; }
- public PersistentManager(string packageName)
- {
- PackageName = packageName;
- }
+ public PersistentManager(string packageName)
+ {
+ PackageName = packageName;
+ }
- ///
- /// 初始化
- ///
- public void Initialize(string buildinRoot, string sandboxRoot, bool appendFileExtension)
- {
- if (string.IsNullOrEmpty(buildinRoot))
- BuildinRoot = CreateDefaultBuildinRoot();
- else
- BuildinRoot = buildinRoot;
+ ///
+ /// 初始化
+ ///
+ public void Initialize(string buildinRoot, string sandboxRoot, bool appendFileExtension)
+ {
+ if (string.IsNullOrEmpty(buildinRoot))
+ BuildinRoot = CreateDefaultBuildinRoot();
+ else
+ BuildinRoot = buildinRoot;
- if (string.IsNullOrEmpty(sandboxRoot))
- SandboxRoot = CreateDefaultSandboxRoot();
- else
- SandboxRoot = sandboxRoot;
+ if (string.IsNullOrEmpty(sandboxRoot))
+ SandboxRoot = CreateDefaultSandboxRoot();
+ else
+ SandboxRoot = sandboxRoot;
- BuildinPackageRoot = PathUtility.Combine(BuildinRoot, PackageName);
- SandboxPackageRoot = PathUtility.Combine(SandboxRoot, PackageName);
- SandboxCacheFilesRoot = PathUtility.Combine(SandboxPackageRoot, YooAssetSettings.CacheFilesFolderName);
- SandboxManifestFilesRoot = PathUtility.Combine(SandboxPackageRoot, YooAssetSettings.ManifestFolderName);
- SandboxAppFootPrintFilePath = PathUtility.Combine(SandboxPackageRoot, YooAssetSettings.AppFootPrintFileName);
- AppendFileExtension = appendFileExtension;
- }
- private static string CreateDefaultBuildinRoot()
- {
- return PathUtility.Combine(UnityEngine.Application.streamingAssetsPath, YooAssetSettingsData.Setting.DefaultYooFolderName);
- }
- private static string CreateDefaultSandboxRoot()
- {
+ BuildinPackageRoot = PathUtility.Combine(BuildinRoot, PackageName);
+ SandboxPackageRoot = PathUtility.Combine(SandboxRoot, PackageName);
+ SandboxCacheFilesRoot = PathUtility.Combine(SandboxPackageRoot, YooAssetSettings.CacheFilesFolderName);
+ SandboxManifestFilesRoot = PathUtility.Combine(SandboxPackageRoot, YooAssetSettings.ManifestFolderName);
+ SandboxAppFootPrintFilePath = PathUtility.Combine(SandboxPackageRoot, YooAssetSettings.AppFootPrintFileName);
+ AppendFileExtension = appendFileExtension;
+ }
+ private static string CreateDefaultBuildinRoot()
+ {
+ return PathUtility.Combine(UnityEngine.Application.streamingAssetsPath, YooAssetSettingsData.Setting.DefaultYooFolderName);
+ }
+ private static string CreateDefaultSandboxRoot()
+ {
#if UNITY_EDITOR
- // 注意:为了方便调试查看,编辑器下把存储目录放到项目里。
- string projectPath = Path.GetDirectoryName(UnityEngine.Application.dataPath);
- projectPath = PathUtility.RegularPath(projectPath);
- return PathUtility.Combine(projectPath, YooAssetSettingsData.Setting.DefaultYooFolderName);
+ // 注意:为了方便调试查看,编辑器下把存储目录放到项目里。
+ string projectPath = Path.GetDirectoryName(UnityEngine.Application.dataPath);
+ projectPath = PathUtility.RegularPath(projectPath);
+ return PathUtility.Combine(projectPath, YooAssetSettingsData.Setting.DefaultYooFolderName);
#elif UNITY_STANDALONE
return PathUtility.Combine(UnityEngine.Application.dataPath, YooAssetSettingsData.Setting.DefaultYooFolderName);
#else
return PathUtility.Combine(UnityEngine.Application.persistentDataPath, YooAssetSettingsData.Setting.DefaultYooFolderName);
#endif
- }
+ }
- public string GetCachedDataFilePath(PackageBundle bundle)
- {
- if (_cachedDataFilePaths.TryGetValue(bundle.CacheGUID, out string filePath) == false)
- {
- string folderName = bundle.FileHash.Substring(0, 2);
- filePath = PathUtility.Combine(SandboxCacheFilesRoot, folderName, bundle.CacheGUID, YooAssetSettings.CacheBundleDataFileName);
- if (AppendFileExtension)
- filePath += bundle.FileExtension;
- _cachedDataFilePaths.Add(bundle.CacheGUID, filePath);
- }
- return filePath;
- }
- public string GetCachedInfoFilePath(PackageBundle bundle)
- {
- if (_cachedInfoFilePaths.TryGetValue(bundle.CacheGUID, out string filePath) == false)
- {
- string folderName = bundle.FileHash.Substring(0, 2);
- filePath = PathUtility.Combine(SandboxCacheFilesRoot, folderName, bundle.CacheGUID, YooAssetSettings.CacheBundleInfoFileName);
- _cachedInfoFilePaths.Add(bundle.CacheGUID, filePath);
- }
- return filePath;
- }
- public string GetTempDataFilePath(PackageBundle bundle)
- {
- if (_tempDataFilePaths.TryGetValue(bundle.CacheGUID, out string filePath) == false)
- {
- string cachedDataFilePath = GetCachedDataFilePath(bundle);
- filePath = $"{cachedDataFilePath}.temp";
- _tempDataFilePaths.Add(bundle.CacheGUID, filePath);
- }
- return filePath;
- }
- public string GetBuildinFilePath(PackageBundle bundle)
- {
- if (_buildinFilePaths.TryGetValue(bundle.CacheGUID, out string filePath) == false)
- {
- filePath = PathUtility.Combine(BuildinPackageRoot, bundle.FileName);
- _buildinFilePaths.Add(bundle.CacheGUID, filePath);
- }
- return filePath;
- }
+ public string GetCachedDataFilePath(PackageBundle bundle)
+ {
+ if (_cachedDataFilePaths.TryGetValue(bundle.CacheGUID, out string filePath) == false)
+ {
+ string folderName = bundle.FileHash.Substring(0, 2);
+ filePath = PathUtility.Combine(SandboxCacheFilesRoot, folderName, bundle.CacheGUID, YooAssetSettings.CacheBundleDataFileName);
+ if (AppendFileExtension)
+ filePath += bundle.FileExtension;
+ _cachedDataFilePaths.Add(bundle.CacheGUID, filePath);
+ }
+ return filePath;
+ }
+ public string GetCachedInfoFilePath(PackageBundle bundle)
+ {
+ if (_cachedInfoFilePaths.TryGetValue(bundle.CacheGUID, out string filePath) == false)
+ {
+ string folderName = bundle.FileHash.Substring(0, 2);
+ filePath = PathUtility.Combine(SandboxCacheFilesRoot, folderName, bundle.CacheGUID, YooAssetSettings.CacheBundleInfoFileName);
+ _cachedInfoFilePaths.Add(bundle.CacheGUID, filePath);
+ }
+ return filePath;
+ }
+ public string GetTempDataFilePath(PackageBundle bundle)
+ {
+ if (_tempDataFilePaths.TryGetValue(bundle.CacheGUID, out string filePath) == false)
+ {
+ string cachedDataFilePath = GetCachedDataFilePath(bundle);
+ filePath = $"{cachedDataFilePath}.temp";
+ _tempDataFilePaths.Add(bundle.CacheGUID, filePath);
+ }
+ return filePath;
+ }
+ public string GetBuildinFilePath(PackageBundle bundle)
+ {
+ if (_buildinFilePaths.TryGetValue(bundle.CacheGUID, out string filePath) == false)
+ {
+ filePath = PathUtility.Combine(BuildinPackageRoot, bundle.FileName);
+ _buildinFilePaths.Add(bundle.CacheGUID, filePath);
+ }
+ return filePath;
+ }
- ///
- /// 删除沙盒里的包裹目录
- ///
- public void DeleteSandboxPackageFolder()
- {
- if (Directory.Exists(SandboxPackageRoot))
- Directory.Delete(SandboxPackageRoot, true);
- }
+ ///
+ /// 删除沙盒里的包裹目录
+ ///
+ public void DeleteSandboxPackageFolder()
+ {
+ if (Directory.Exists(SandboxPackageRoot))
+ Directory.Delete(SandboxPackageRoot, true);
+ }
- ///
- /// 删除沙盒内的缓存文件夹
- ///
- public void DeleteSandboxCacheFilesFolder()
- {
- if (Directory.Exists(SandboxCacheFilesRoot))
- Directory.Delete(SandboxCacheFilesRoot, true);
- }
+ ///
+ /// 删除沙盒内的缓存文件夹
+ ///
+ public void DeleteSandboxCacheFilesFolder()
+ {
+ if (Directory.Exists(SandboxCacheFilesRoot))
+ Directory.Delete(SandboxCacheFilesRoot, true);
+ }
- ///
- /// 删除沙盒内的清单文件夹
- ///
- public void DeleteSandboxManifestFilesFolder()
- {
- if (Directory.Exists(SandboxManifestFilesRoot))
- Directory.Delete(SandboxManifestFilesRoot, true);
- }
+ ///
+ /// 删除沙盒内的清单文件夹
+ ///
+ public void DeleteSandboxManifestFilesFolder()
+ {
+ if (Directory.Exists(SandboxManifestFilesRoot))
+ Directory.Delete(SandboxManifestFilesRoot, true);
+ }
- ///
- /// 获取沙盒内包裹的清单文件的路径
- ///
- public string GetSandboxPackageManifestFilePath(string packageVersion)
- {
- string fileName = YooAssetSettingsData.GetManifestBinaryFileName(PackageName, packageVersion);
- return PathUtility.Combine(SandboxManifestFilesRoot, fileName);
- }
+ ///
+ /// 获取沙盒内包裹的清单文件的路径
+ ///
+ public string GetSandboxPackageManifestFilePath(string packageVersion)
+ {
+ string fileName = YooAssetSettingsData.GetManifestBinaryFileName(PackageName, packageVersion);
+ return PathUtility.Combine(SandboxManifestFilesRoot, fileName);
+ }
- ///
- /// 获取沙盒内包裹的哈希文件的路径
- ///
- public string GetSandboxPackageHashFilePath(string packageVersion)
- {
- string fileName = YooAssetSettingsData.GetPackageHashFileName(PackageName, packageVersion);
- return PathUtility.Combine(SandboxManifestFilesRoot, fileName);
- }
+ ///
+ /// 获取沙盒内包裹的哈希文件的路径
+ ///
+ public string GetSandboxPackageHashFilePath(string packageVersion)
+ {
+ string fileName = YooAssetSettingsData.GetPackageHashFileName(PackageName, packageVersion);
+ return PathUtility.Combine(SandboxManifestFilesRoot, fileName);
+ }
- ///
- /// 获取沙盒内包裹的版本文件的路径
- ///
- public string GetSandboxPackageVersionFilePath()
- {
- string fileName = YooAssetSettingsData.GetPackageVersionFileName(PackageName);
- return PathUtility.Combine(SandboxManifestFilesRoot, fileName);
- }
+ ///
+ /// 获取沙盒内包裹的版本文件的路径
+ ///
+ public string GetSandboxPackageVersionFilePath()
+ {
+ string fileName = YooAssetSettingsData.GetPackageVersionFileName(PackageName);
+ return PathUtility.Combine(SandboxManifestFilesRoot, fileName);
+ }
- ///
- /// 保存沙盒内默认的包裹版本
- ///
- public void SaveSandboxPackageVersionFile(string version)
- {
- string filePath = GetSandboxPackageVersionFilePath();
- FileUtility.WriteAllText(filePath, version);
- }
+ ///
+ /// 保存沙盒内默认的包裹版本
+ ///
+ public void SaveSandboxPackageVersionFile(string version)
+ {
+ string filePath = GetSandboxPackageVersionFilePath();
+ FileUtility.WriteAllText(filePath, version);
+ }
- ///
- /// 获取APP内包裹的清单文件的路径
- ///
- public string GetBuildinPackageManifestFilePath(string packageVersion)
- {
- string fileName = YooAssetSettingsData.GetManifestBinaryFileName(PackageName, packageVersion);
- return PathUtility.Combine(BuildinPackageRoot, fileName);
- }
+ ///
+ /// 获取APP内包裹的清单文件的路径
+ ///
+ public string GetBuildinPackageManifestFilePath(string packageVersion)
+ {
+ string fileName = YooAssetSettingsData.GetManifestBinaryFileName(PackageName, packageVersion);
+ return PathUtility.Combine(BuildinPackageRoot, fileName);
+ }
- ///
- /// 获取APP内包裹的哈希文件的路径
- ///
- public string GetBuildinPackageHashFilePath(string packageVersion)
- {
- string fileName = YooAssetSettingsData.GetPackageHashFileName(PackageName, packageVersion);
- return PathUtility.Combine(BuildinPackageRoot, fileName);
- }
+ ///
+ /// 获取APP内包裹的哈希文件的路径
+ ///
+ public string GetBuildinPackageHashFilePath(string packageVersion)
+ {
+ string fileName = YooAssetSettingsData.GetPackageHashFileName(PackageName, packageVersion);
+ return PathUtility.Combine(BuildinPackageRoot, fileName);
+ }
- ///
- /// 获取APP内包裹的版本文件的路径
- ///
- public string GetBuildinPackageVersionFilePath()
- {
- string fileName = YooAssetSettingsData.GetPackageVersionFileName(PackageName);
- return PathUtility.Combine(BuildinPackageRoot, fileName);
- }
- }
+ ///
+ /// 获取APP内包裹的版本文件的路径
+ ///
+ public string GetBuildinPackageVersionFilePath()
+ {
+ string fileName = YooAssetSettingsData.GetPackageVersionFileName(PackageName);
+ return PathUtility.Combine(BuildinPackageRoot, fileName);
+ }
+ }
}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/CacheSystem/VerifyElement.cs b/Assets/YooAsset/Runtime/CacheSystem/VerifyElement.cs
index 83ca07b..c8cbb46 100644
--- a/Assets/YooAsset/Runtime/CacheSystem/VerifyElement.cs
+++ b/Assets/YooAsset/Runtime/CacheSystem/VerifyElement.cs
@@ -2,59 +2,59 @@
namespace YooAsset
{
- ///
- /// 缓存文件验证元素
- ///
- internal class VerifyCacheFileElement
- {
- public string PackageName { private set; get; }
- public string CacheGUID { private set; get; }
- public string FileRootPath { private set; get; }
- public string DataFilePath { private set; get; }
- public string InfoFilePath { private set; get; }
+ ///
+ /// 缓存文件验证元素
+ ///
+ internal class VerifyCacheFileElement
+ {
+ public string PackageName { private set; get; }
+ public string CacheGUID { private set; get; }
+ public string FileRootPath { private set; get; }
+ public string DataFilePath { private set; get; }
+ public string InfoFilePath { private set; get; }
- public EVerifyResult Result;
- public string DataFileCRC;
- public long DataFileSize;
+ public EVerifyResult Result;
+ public string DataFileCRC;
+ public long DataFileSize;
- public VerifyCacheFileElement(string packageName, string cacheGUID, string fileRootPath, string dataFilePath, string infoFilePath)
- {
- PackageName = packageName;
- CacheGUID = cacheGUID;
- FileRootPath = fileRootPath;
- DataFilePath = dataFilePath;
- InfoFilePath = infoFilePath;
- }
+ public VerifyCacheFileElement(string packageName, string cacheGUID, string fileRootPath, string dataFilePath, string infoFilePath)
+ {
+ PackageName = packageName;
+ CacheGUID = cacheGUID;
+ FileRootPath = fileRootPath;
+ DataFilePath = dataFilePath;
+ InfoFilePath = infoFilePath;
+ }
- public void DeleteFiles()
- {
- try
- {
- Directory.Delete(FileRootPath, true);
- }
- catch(System.Exception e)
- {
- YooLogger.Warning($"Failed delete cache bundle folder : {e}");
- }
- }
- }
+ public void DeleteFiles()
+ {
+ try
+ {
+ Directory.Delete(FileRootPath, true);
+ }
+ catch (System.Exception e)
+ {
+ YooLogger.Warning($"Failed delete cache bundle folder : {e}");
+ }
+ }
+ }
- ///
- /// 下载文件验证元素
- ///
- internal class VerifyTempFileElement
- {
- public string TempDataFilePath { private set; get; }
- public string FileCRC { private set; get; }
- public long FileSize { private set; get; }
+ ///
+ /// 下载文件验证元素
+ ///
+ internal class VerifyTempFileElement
+ {
+ public string TempDataFilePath { private set; get; }
+ public string FileCRC { private set; get; }
+ public long FileSize { private set; get; }
- public int Result = 0; // 注意:原子操作对象
+ public int Result = 0; // 注意:原子操作对象
- public VerifyTempFileElement(string tempDataFilePath, string fileCRC, long fileSize)
- {
- TempDataFilePath = tempDataFilePath;
- FileCRC = fileCRC;
- FileSize = fileSize;
- }
- }
+ public VerifyTempFileElement(string tempDataFilePath, string fileCRC, long fileSize)
+ {
+ TempDataFilePath = tempDataFilePath;
+ FileCRC = fileCRC;
+ FileSize = fileSize;
+ }
+ }
}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/DiagnosticSystem/DebugBundleInfo.cs b/Assets/YooAsset/Runtime/DiagnosticSystem/DebugBundleInfo.cs
index 68ef204..fa564c4 100644
--- a/Assets/YooAsset/Runtime/DiagnosticSystem/DebugBundleInfo.cs
+++ b/Assets/YooAsset/Runtime/DiagnosticSystem/DebugBundleInfo.cs
@@ -4,36 +4,36 @@ using System.Collections.Generic;
namespace YooAsset
{
- [Serializable]
- internal class DebugBundleInfo : IComparer, IComparable
- {
- ///
- /// 包裹名
- ///
- public string PackageName { set; get; }
+ [Serializable]
+ internal class DebugBundleInfo : IComparer, IComparable
+ {
+ ///
+ /// 包裹名
+ ///
+ public string PackageName { set; get; }
- ///
- /// 资源包名称
- ///
- public string BundleName;
+ ///
+ /// 资源包名称
+ ///
+ public string BundleName;
- ///
- /// 引用计数
- ///
- public int RefCount;
+ ///
+ /// 引用计数
+ ///
+ public int RefCount;
- ///
- /// 加载状态
- ///
- public string Status;
+ ///
+ /// 加载状态
+ ///
+ public string Status;
- public int CompareTo(DebugBundleInfo other)
- {
- return Compare(this, other);
- }
- public int Compare(DebugBundleInfo a, DebugBundleInfo b)
- {
- return string.CompareOrdinal(a.BundleName, b.BundleName);
- }
- }
+ public int CompareTo(DebugBundleInfo other)
+ {
+ return Compare(this, other);
+ }
+ public int Compare(DebugBundleInfo a, DebugBundleInfo b)
+ {
+ return string.CompareOrdinal(a.BundleName, b.BundleName);
+ }
+ }
}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/DiagnosticSystem/DebugPackageData.cs b/Assets/YooAsset/Runtime/DiagnosticSystem/DebugPackageData.cs
index 12ac443..dd01afe 100644
--- a/Assets/YooAsset/Runtime/DiagnosticSystem/DebugPackageData.cs
+++ b/Assets/YooAsset/Runtime/DiagnosticSystem/DebugPackageData.cs
@@ -5,17 +5,17 @@ using System.Collections.Generic;
namespace YooAsset
{
- [Serializable]
- internal class DebugPackageData
- {
- ///
- /// 包裹名称
- ///
- public string PackageName;
+ [Serializable]
+ internal class DebugPackageData
+ {
+ ///
+ /// 包裹名称
+ ///
+ public string PackageName;
- ///
- /// 调试数据列表
- ///
- public List ProviderInfos = new List(1000);
- }
+ ///
+ /// 调试数据列表
+ ///
+ public List ProviderInfos = new List(1000);
+ }
}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/DiagnosticSystem/DebugProviderInfo.cs b/Assets/YooAsset/Runtime/DiagnosticSystem/DebugProviderInfo.cs
index 389b80e..f609a0c 100644
--- a/Assets/YooAsset/Runtime/DiagnosticSystem/DebugProviderInfo.cs
+++ b/Assets/YooAsset/Runtime/DiagnosticSystem/DebugProviderInfo.cs
@@ -4,56 +4,56 @@ using System.Collections.Generic;
namespace YooAsset
{
- [Serializable]
- internal class DebugProviderInfo : IComparer, IComparable
- {
- ///
- /// 包裹名
- ///
- public string PackageName { set; get; }
+ [Serializable]
+ internal class DebugProviderInfo : IComparer, IComparable
+ {
+ ///
+ /// 包裹名
+ ///
+ public string PackageName { set; get; }
- ///
- /// 资源对象路径
- ///
- public string AssetPath;
+ ///
+ /// 资源对象路径
+ ///
+ public string AssetPath;
- ///
- /// 资源出生的场景
- ///
- public string SpawnScene;
+ ///
+ /// 资源出生的场景
+ ///
+ public string SpawnScene;
- ///
- /// 资源出生的时间
- ///
- public string SpawnTime;
+ ///
+ /// 资源出生的时间
+ ///
+ public string SpawnTime;
- ///
- /// 加载耗时(单位:毫秒)
- ///
- public long LoadingTime;
+ ///
+ /// 加载耗时(单位:毫秒)
+ ///
+ public long LoadingTime;
- ///
- /// 引用计数
- ///
- public int RefCount;
+ ///
+ /// 引用计数
+ ///
+ public int RefCount;
- ///
- /// 加载状态
- ///
- public string Status;
+ ///
+ /// 加载状态
+ ///
+ public string Status;
- ///
- /// 依赖的资源包列表
- ///
- public List DependBundleInfos;
+ ///
+ /// 依赖的资源包列表
+ ///
+ public List DependBundleInfos;
- public int CompareTo(DebugProviderInfo other)
- {
- return Compare(this, other);
- }
- public int Compare(DebugProviderInfo a, DebugProviderInfo b)
- {
- return string.CompareOrdinal(a.AssetPath, b.AssetPath);
- }
- }
+ public int CompareTo(DebugProviderInfo other)
+ {
+ return Compare(this, other);
+ }
+ public int Compare(DebugProviderInfo a, DebugProviderInfo b)
+ {
+ return string.CompareOrdinal(a.AssetPath, b.AssetPath);
+ }
+ }
}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/DiagnosticSystem/DebugReport.cs b/Assets/YooAsset/Runtime/DiagnosticSystem/DebugReport.cs
index a049f48..1a3a748 100644
--- a/Assets/YooAsset/Runtime/DiagnosticSystem/DebugReport.cs
+++ b/Assets/YooAsset/Runtime/DiagnosticSystem/DebugReport.cs
@@ -6,34 +6,34 @@ using UnityEngine;
namespace YooAsset
{
- ///
- /// 资源系统调试信息
- ///
- [Serializable]
- internal class DebugReport
- {
- ///
- /// 游戏帧
- ///
- public int FrameCount;
+ ///
+ /// 资源系统调试信息
+ ///
+ [Serializable]
+ internal class DebugReport
+ {
+ ///
+ /// 游戏帧
+ ///
+ public int FrameCount;
- ///
- /// 调试的包裹数据列表
- ///
- public List PackageDatas = new List(10);
-
+ ///
+ /// 调试的包裹数据列表
+ ///
+ public List PackageDatas = new List(10);
- ///
- /// 序列化
- ///
- public static byte[] Serialize(DebugReport debugReport)
+
+ ///
+ /// 序列化
+ ///
+ public static byte[] Serialize(DebugReport debugReport)
{
return Encoding.UTF8.GetBytes(JsonUtility.ToJson(debugReport));
}
- ///
- /// 反序列化
- ///
+ ///
+ /// 反序列化
+ ///
public static DebugReport Deserialize(byte[] data)
{
return JsonUtility.FromJson(Encoding.UTF8.GetString(data));
diff --git a/Assets/YooAsset/Runtime/DiagnosticSystem/RemoteCommand.cs b/Assets/YooAsset/Runtime/DiagnosticSystem/RemoteCommand.cs
index 3d706be..fabf279 100644
--- a/Assets/YooAsset/Runtime/DiagnosticSystem/RemoteCommand.cs
+++ b/Assets/YooAsset/Runtime/DiagnosticSystem/RemoteCommand.cs
@@ -4,42 +4,42 @@ using UnityEngine;
namespace YooAsset
{
- internal enum ERemoteCommand
- {
- ///
- /// 采样一次
- ///
- SampleOnce = 0,
- }
+ internal enum ERemoteCommand
+ {
+ ///
+ /// 采样一次
+ ///
+ SampleOnce = 0,
+ }
- [Serializable]
- internal class RemoteCommand
- {
- ///
- /// 命令类型
- ///
- public int CommandType;
+ [Serializable]
+ internal class RemoteCommand
+ {
+ ///
+ /// 命令类型
+ ///
+ public int CommandType;
- ///
- /// 命令附加参数
- ///
- public string CommandParam;
+ ///
+ /// 命令附加参数
+ ///
+ public string CommandParam;
- ///
- /// 序列化
- ///
- public static byte[] Serialize(RemoteCommand command)
- {
- return Encoding.UTF8.GetBytes(JsonUtility.ToJson(command));
- }
+ ///
+ /// 序列化
+ ///
+ public static byte[] Serialize(RemoteCommand command)
+ {
+ return Encoding.UTF8.GetBytes(JsonUtility.ToJson(command));
+ }
- ///
- /// 反序列化
- ///
- public static RemoteCommand Deserialize(byte[] data)
- {
- return JsonUtility.FromJson(Encoding.UTF8.GetString(data));
- }
- }
+ ///
+ /// 反序列化
+ ///
+ public static RemoteCommand Deserialize(byte[] data)
+ {
+ return JsonUtility.FromJson(Encoding.UTF8.GetString(data));
+ }
+ }
}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/DiagnosticSystem/RemoteDebuggerDefine.cs b/Assets/YooAsset/Runtime/DiagnosticSystem/RemoteDebuggerDefine.cs
index edd66b0..c94b842 100644
--- a/Assets/YooAsset/Runtime/DiagnosticSystem/RemoteDebuggerDefine.cs
+++ b/Assets/YooAsset/Runtime/DiagnosticSystem/RemoteDebuggerDefine.cs
@@ -1,12 +1,11 @@
using System;
using System.Text;
-using UnityEngine;
namespace YooAsset
{
- internal class RemoteDebuggerDefine
- {
- public static readonly Guid kMsgSendPlayerToEditor = new Guid("e34a5702dd353724aa315fb8011f08c3");
- public static readonly Guid kMsgSendEditorToPlayer = new Guid("4d1926c9df5b052469a1c63448b7609a");
- }
+ internal class RemoteDebuggerDefine
+ {
+ public static readonly Guid kMsgSendPlayerToEditor = new Guid("e34a5702dd353724aa315fb8011f08c3");
+ public static readonly Guid kMsgSendEditorToPlayer = new Guid("4d1926c9df5b052469a1c63448b7609a");
+ }
}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/DiagnosticSystem/RemoteDebuggerInRuntime.cs b/Assets/YooAsset/Runtime/DiagnosticSystem/RemoteDebuggerInRuntime.cs
index af2e48f..b61295d 100644
--- a/Assets/YooAsset/Runtime/DiagnosticSystem/RemoteDebuggerInRuntime.cs
+++ b/Assets/YooAsset/Runtime/DiagnosticSystem/RemoteDebuggerInRuntime.cs
@@ -5,25 +5,25 @@ using UnityEngine.Networking.PlayerConnection;
namespace YooAsset
{
- internal class RemoteDebuggerInRuntime : MonoBehaviour
- {
+ internal class RemoteDebuggerInRuntime : MonoBehaviour
+ {
#if UNITY_EDITOR
- ///
- /// 编辑器下获取报告的回调
- ///
- public static Action EditorHandleDebugReportCallback;
+ ///
+ /// 编辑器下获取报告的回调
+ ///
+ public static Action EditorHandleDebugReportCallback;
- ///
- /// 编辑器下请求报告数据
- ///
- public static void EditorRequestDebugReport()
- {
- if(UnityEditor.EditorApplication.isPlaying)
- {
- var report = YooAssets.GetDebugReport();
- EditorHandleDebugReportCallback?.Invoke(0, report);
- }
- }
+ ///
+ /// 编辑器下请求报告数据
+ ///
+ public static void EditorRequestDebugReport()
+ {
+ if (UnityEditor.EditorApplication.isPlaying)
+ {
+ var report = YooAssets.GetDebugReport();
+ EditorHandleDebugReportCallback?.Invoke(0, report);
+ }
+ }
#else
private void OnEnable()
{
@@ -49,5 +49,5 @@ namespace YooAsset
}
}
#endif
- }
+ }
}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/DownloadSystem/DownloadHelper.cs b/Assets/YooAsset/Runtime/DownloadSystem/DownloadHelper.cs
index 8aa06e1..458529f 100644
--- a/Assets/YooAsset/Runtime/DownloadSystem/DownloadHelper.cs
+++ b/Assets/YooAsset/Runtime/DownloadSystem/DownloadHelper.cs
@@ -7,35 +7,35 @@ using UnityEngine.Networking;
namespace YooAsset
{
- ///
- /// 自定义下载器的请求委托
- ///
- public delegate UnityWebRequest DownloadRequestDelegate(string url);
+ ///
+ /// 自定义下载器的请求委托
+ ///
+ public delegate UnityWebRequest DownloadRequestDelegate(string url);
- internal static class DownloadHelper
- {
- ///
- /// 下载失败后清理文件的HTTP错误码
- ///
- public static List ClearFileResponseCodes { set; get; }
+ internal static class DownloadHelper
+ {
+ ///
+ /// 下载失败后清理文件的HTTP错误码
+ ///
+ public static List ClearFileResponseCodes { set; get; }
- ///
- /// 自定义下载器的请求委托
- ///
- public static DownloadRequestDelegate RequestDelegate = null;
+ ///
+ /// 自定义下载器的请求委托
+ ///
+ public static DownloadRequestDelegate RequestDelegate = null;
- ///
- /// 创建一个新的网络请求
- ///
- public static UnityWebRequest NewRequest(string requestURL)
- {
- UnityWebRequest webRequest;
- if (RequestDelegate != null)
- webRequest = RequestDelegate.Invoke(requestURL);
- else
- webRequest = new UnityWebRequest(requestURL, UnityWebRequest.kHttpVerbGET);
- return webRequest;
- }
- }
+ ///
+ /// 创建一个新的网络请求
+ ///
+ public static UnityWebRequest NewRequest(string requestURL)
+ {
+ UnityWebRequest webRequest;
+ if (RequestDelegate != null)
+ webRequest = RequestDelegate.Invoke(requestURL);
+ else
+ webRequest = new UnityWebRequest(requestURL, UnityWebRequest.kHttpVerbGET);
+ return webRequest;
+ }
+ }
}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/DownloadSystem/DownloadManager.cs b/Assets/YooAsset/Runtime/DownloadSystem/DownloadManager.cs
index 6daf127..71a693c 100644
--- a/Assets/YooAsset/Runtime/DownloadSystem/DownloadManager.cs
+++ b/Assets/YooAsset/Runtime/DownloadSystem/DownloadManager.cs
@@ -6,99 +6,99 @@ using UnityEngine.Networking;
namespace YooAsset
{
- ///
- /// 1. 保证每一时刻资源文件只存在一个下载器
- /// 2. 保证下载器下载完成后立刻验证并缓存
- /// 3. 保证资源文件不会被重复下载
- ///
- internal class DownloadManager
- {
- private readonly Dictionary _downloaders = new Dictionary(1000);
- private readonly List _removeList = new List(1000);
+ ///
+ /// 1. 保证每一时刻资源文件只存在一个下载器
+ /// 2. 保证下载器下载完成后立刻验证并缓存
+ /// 3. 保证资源文件不会被重复下载
+ ///
+ internal class DownloadManager
+ {
+ private readonly Dictionary _downloaders = new Dictionary(1000);
+ private readonly List _removeList = new List(1000);
- private uint _breakpointResumeFileSize;
+ private uint _breakpointResumeFileSize;
- ///
- /// 所属包裹
- ///
- public readonly string PackageName;
+ ///
+ /// 所属包裹
+ ///
+ public readonly string PackageName;
- public DownloadManager(string packageName)
- {
- PackageName = packageName;
- }
+ public DownloadManager(string packageName)
+ {
+ PackageName = packageName;
+ }
- ///
- /// 初始化
- ///
- public void Initialize(uint breakpointResumeFileSize)
- {
- _breakpointResumeFileSize = breakpointResumeFileSize;
- }
+ ///
+ /// 初始化
+ ///
+ public void Initialize(uint breakpointResumeFileSize)
+ {
+ _breakpointResumeFileSize = breakpointResumeFileSize;
+ }
- ///
- /// 更新下载器
- ///
- public void Update()
- {
- // 更新下载器
- _removeList.Clear();
- foreach (var valuePair in _downloaders)
- {
- var downloader = valuePair.Value;
- downloader.Update();
- if (downloader.IsDone())
- {
- _removeList.Add(valuePair.Key);
- }
- }
+ ///
+ /// 更新下载器
+ ///
+ public void Update()
+ {
+ // 更新下载器
+ _removeList.Clear();
+ foreach (var valuePair in _downloaders)
+ {
+ var downloader = valuePair.Value;
+ downloader.Update();
+ if (downloader.IsDone())
+ {
+ _removeList.Add(valuePair.Key);
+ }
+ }
- // 移除下载器
- foreach (var key in _removeList)
- {
- _downloaders.Remove(key);
- }
- }
+ // 移除下载器
+ foreach (var key in _removeList)
+ {
+ _downloaders.Remove(key);
+ }
+ }
- ///
- /// 销毁所有下载器
- ///
- public void DestroyAll()
- {
- foreach (var valuePair in _downloaders)
- {
- var downloader = valuePair.Value;
- downloader.Abort();
- }
+ ///
+ /// 销毁所有下载器
+ ///
+ public void DestroyAll()
+ {
+ foreach (var valuePair in _downloaders)
+ {
+ var downloader = valuePair.Value;
+ downloader.Abort();
+ }
- _downloaders.Clear();
- _removeList.Clear();
- }
+ _downloaders.Clear();
+ _removeList.Clear();
+ }
- ///
- /// 创建下载器
- /// 注意:只有第一次请求的参数才有效
- ///
- public DownloaderBase CreateDownload(BundleInfo bundleInfo, int failedTryAgain, int timeout = 60)
- {
- // 查询存在的下载器
- if (_downloaders.TryGetValue(bundleInfo.CachedDataFilePath, out var downloader))
- {
- downloader.Reference();
- return downloader;
- }
+ ///
+ /// 创建下载器
+ /// 注意:只有第一次请求的参数才有效
+ ///
+ public DownloaderBase CreateDownload(BundleInfo bundleInfo, int failedTryAgain, int timeout = 60)
+ {
+ // 查询存在的下载器
+ if (_downloaders.TryGetValue(bundleInfo.CachedDataFilePath, out var downloader))
+ {
+ downloader.Reference();
+ return downloader;
+ }
- // 如果资源已经缓存
- if (bundleInfo.IsCached())
- {
- var completedDownloader = new CompletedDownloader(bundleInfo);
- return completedDownloader;
- }
+ // 如果资源已经缓存
+ if (bundleInfo.IsCached())
+ {
+ var completedDownloader = new CompletedDownloader(bundleInfo);
+ return completedDownloader;
+ }
- // 创建新的下载器
- DownloaderBase newDownloader = null;
- YooLogger.Log($"Beginning to download bundle : {bundleInfo.Bundle.BundleName} URL : {bundleInfo.RemoteMainURL}");
+ // 创建新的下载器
+ DownloaderBase newDownloader = null;
+ YooLogger.Log($"Beginning to download bundle : {bundleInfo.Bundle.BundleName} URL : {bundleInfo.RemoteMainURL}");
#if UNITY_WEBGL
if (bundleInfo.Bundle.Buildpipeline == EDefaultBuildPipeline.RawFileBuildPipeline.ToString())
{
@@ -112,39 +112,39 @@ namespace YooAsset
newDownloader = new WebDownloader(bundleInfo, requesterType, failedTryAgain, timeout);
}
#else
- FileUtility.CreateFileDirectory(bundleInfo.CachedDataFilePath);
- bool resumeDownload = bundleInfo.Bundle.FileSize >= _breakpointResumeFileSize;
- if (resumeDownload)
- {
- System.Type requesterType = typeof(FileResumeRequest);
- newDownloader = new FileDownloader(bundleInfo, requesterType, failedTryAgain, timeout);
- }
- else
- {
- System.Type requesterType = typeof(FileGeneralRequest);
- newDownloader = new FileDownloader(bundleInfo, requesterType, failedTryAgain, timeout);
- }
+ FileUtility.CreateFileDirectory(bundleInfo.CachedDataFilePath);
+ bool resumeDownload = bundleInfo.Bundle.FileSize >= _breakpointResumeFileSize;
+ if (resumeDownload)
+ {
+ System.Type requesterType = typeof(FileResumeRequest);
+ newDownloader = new FileDownloader(bundleInfo, requesterType, failedTryAgain, timeout);
+ }
+ else
+ {
+ System.Type requesterType = typeof(FileGeneralRequest);
+ newDownloader = new FileDownloader(bundleInfo, requesterType, failedTryAgain, timeout);
+ }
#endif
- // 返回新创建的下载器
- _downloaders.Add(bundleInfo.CachedDataFilePath, newDownloader);
- newDownloader.Reference();
- return newDownloader;
- }
+ // 返回新创建的下载器
+ _downloaders.Add(bundleInfo.CachedDataFilePath, newDownloader);
+ newDownloader.Reference();
+ return newDownloader;
+ }
- ///
- /// 停止不再使用的下载器
- ///
- public void AbortUnusedDownloader()
- {
- foreach (var valuePair in _downloaders)
- {
- var downloader = valuePair.Value;
- if (downloader.RefCount <= 0)
- {
- downloader.Abort();
- }
- }
- }
- }
+ ///
+ /// 停止不再使用的下载器
+ ///
+ public void AbortUnusedDownloader()
+ {
+ foreach (var valuePair in _downloaders)
+ {
+ var downloader = valuePair.Value;
+ if (downloader.RefCount <= 0)
+ {
+ downloader.Abort();
+ }
+ }
+ }
+ }
}
diff --git a/Assets/YooAsset/Runtime/DownloadSystem/DownloadStatus.cs b/Assets/YooAsset/Runtime/DownloadSystem/DownloadStatus.cs
index d9296ea..880d81d 100644
--- a/Assets/YooAsset/Runtime/DownloadSystem/DownloadStatus.cs
+++ b/Assets/YooAsset/Runtime/DownloadSystem/DownloadStatus.cs
@@ -1,36 +1,36 @@
namespace YooAsset
{
- public struct DownloadStatus
- {
- ///
- /// 下载是否完成
- ///
- public bool IsDone;
+ public struct DownloadStatus
+ {
+ ///
+ /// 下载是否完成
+ ///
+ public bool IsDone;
- ///
- /// 下载进度(0f~1f)
- ///
- public float Progress;
+ ///
+ /// 下载进度(0f~1f)
+ ///
+ public float Progress;
- ///
- /// 需要下载的总字节数
- ///
- public ulong TotalBytes;
+ ///
+ /// 需要下载的总字节数
+ ///
+ public ulong TotalBytes;
- ///
- /// 已经下载的字节数
- ///
- public ulong DownloadedBytes;
+ ///
+ /// 已经下载的字节数
+ ///
+ public ulong DownloadedBytes;
- public static DownloadStatus CreateDefaultStatus()
- {
- DownloadStatus status = new DownloadStatus();
- status.IsDone = false;
- status.Progress = 0f;
- status.TotalBytes = 0;
- status.DownloadedBytes = 0;
- return status;
- }
- }
+ public static DownloadStatus CreateDefaultStatus()
+ {
+ DownloadStatus status = new DownloadStatus();
+ status.IsDone = false;
+ status.Progress = 0f;
+ status.TotalBytes = 0;
+ status.DownloadedBytes = 0;
+ return status;
+ }
+ }
}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/DownloadSystem/Downloader/CompletedDownloader.cs b/Assets/YooAsset/Runtime/DownloadSystem/Downloader/CompletedDownloader.cs
index a027bd8..4495409 100644
--- a/Assets/YooAsset/Runtime/DownloadSystem/Downloader/CompletedDownloader.cs
+++ b/Assets/YooAsset/Runtime/DownloadSystem/Downloader/CompletedDownloader.cs
@@ -1,29 +1,28 @@
-
-using UnityEngine;
+using UnityEngine;
namespace YooAsset
{
- internal sealed class CompletedDownloader : DownloaderBase
- {
- public CompletedDownloader(BundleInfo bundleInfo) : base(bundleInfo, null, 0, 0)
- {
- DownloadProgress = 1f;
- DownloadedBytes = (ulong)bundleInfo.Bundle.FileSize;
- _status = EStatus.Succeed;
- }
+ internal sealed class CompletedDownloader : DownloaderBase
+ {
+ public CompletedDownloader(BundleInfo bundleInfo) : base(bundleInfo, null, 0, 0)
+ {
+ DownloadProgress = 1f;
+ DownloadedBytes = (ulong)bundleInfo.Bundle.FileSize;
+ _status = EStatus.Succeed;
+ }
- public override void SendRequest(params object[] param)
- {
- }
- public override void Update()
- {
- }
- public override void Abort()
- {
- }
- public override AssetBundle GetAssetBundle()
- {
- throw new System.NotImplementedException();
- }
- }
+ public override void SendRequest(params object[] param)
+ {
+ }
+ public override void Update()
+ {
+ }
+ public override void Abort()
+ {
+ }
+ public override AssetBundle GetAssetBundle()
+ {
+ throw new System.NotImplementedException();
+ }
+ }
}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/DownloadSystem/Downloader/DownloaderBase.cs b/Assets/YooAsset/Runtime/DownloadSystem/Downloader/DownloaderBase.cs
index e64f954..df531d5 100644
--- a/Assets/YooAsset/Runtime/DownloadSystem/Downloader/DownloaderBase.cs
+++ b/Assets/YooAsset/Runtime/DownloadSystem/Downloader/DownloaderBase.cs
@@ -4,179 +4,179 @@ using UnityEngine.Networking;
namespace YooAsset
{
- internal abstract class DownloaderBase
- {
- public enum EStatus
- {
- None = 0,
- Succeed,
- Failed
- }
+ internal abstract class DownloaderBase
+ {
+ public enum EStatus
+ {
+ None = 0,
+ Succeed,
+ Failed
+ }
- protected readonly BundleInfo _bundleInfo;
- protected readonly System.Type _requesterType;
- protected readonly int _timeout;
- protected int _failedTryAgain;
+ protected readonly BundleInfo _bundleInfo;
+ protected readonly System.Type _requesterType;
+ protected readonly int _timeout;
+ protected int _failedTryAgain;
- protected IWebRequester _requester;
- protected EStatus _status = EStatus.None;
- protected string _lastestNetError = string.Empty;
- protected long _lastestHttpCode = 0;
+ protected IWebRequester _requester;
+ protected EStatus _status = EStatus.None;
+ protected string _lastestNetError = string.Empty;
+ protected long _lastestHttpCode = 0;
- // 请求次数
- protected int _requestCount = 0;
- protected string _requestURL;
+ // 请求次数
+ protected int _requestCount = 0;
+ protected string _requestURL;
- // 超时相关
- protected bool _isAbort = false;
- protected ulong _latestDownloadBytes;
- protected float _latestDownloadRealtime;
- protected float _tryAgainTimer;
+ // 超时相关
+ protected bool _isAbort = false;
+ protected ulong _latestDownloadBytes;
+ protected float _latestDownloadRealtime;
+ protected float _tryAgainTimer;
- ///
- /// 是否等待异步结束
- /// 警告:只能用于解压APP内部资源
- ///
- public bool WaitForAsyncComplete = false;
+ ///
+ /// 是否等待异步结束
+ /// 警告:只能用于解压APP内部资源
+ ///
+ public bool WaitForAsyncComplete = false;
- ///
- /// 下载进度(0f~1f)
- ///
- public float DownloadProgress { protected set; get; }
+ ///
+ /// 下载进度(0f~1f)
+ ///
+ public float DownloadProgress { protected set; get; }
- ///
- /// 已经下载的总字节数
- ///
- public ulong DownloadedBytes { protected set; get; }
+ ///
+ /// 已经下载的总字节数
+ ///
+ public ulong DownloadedBytes { protected set; get; }
- ///
- /// 引用计数
- ///
- public int RefCount { private set; get; }
+ ///
+ /// 引用计数
+ ///
+ public int RefCount { private set; get; }
- public DownloaderBase(BundleInfo bundleInfo, System.Type requesterType, int failedTryAgain, int timeout)
- {
- _bundleInfo = bundleInfo;
- _requesterType = requesterType;
- _failedTryAgain = failedTryAgain;
- _timeout = timeout;
- }
- public abstract void SendRequest(params object[] args);
- public abstract void Update();
- public abstract void Abort();
- public abstract AssetBundle GetAssetBundle();
+ public DownloaderBase(BundleInfo bundleInfo, System.Type requesterType, int failedTryAgain, int timeout)
+ {
+ _bundleInfo = bundleInfo;
+ _requesterType = requesterType;
+ _failedTryAgain = failedTryAgain;
+ _timeout = timeout;
+ }
+ public abstract void SendRequest(params object[] args);
+ public abstract void Update();
+ public abstract void Abort();
+ public abstract AssetBundle GetAssetBundle();
- ///
- /// 引用(引用计数递加)
- ///
- public void Reference()
- {
- RefCount++;
- }
+ ///
+ /// 引用(引用计数递加)
+ ///
+ public void Reference()
+ {
+ RefCount++;
+ }
- ///
- /// 释放(引用计数递减)
- ///
- public void Release()
- {
- RefCount--;
- }
+ ///
+ /// 释放(引用计数递减)
+ ///
+ public void Release()
+ {
+ RefCount--;
+ }
- ///
- /// 检测下载器是否已经完成(无论成功或失败)
- ///
- public bool IsDone()
- {
- return _status == EStatus.Succeed || _status == EStatus.Failed;
- }
+ ///
+ /// 检测下载器是否已经完成(无论成功或失败)
+ ///
+ public bool IsDone()
+ {
+ return _status == EStatus.Succeed || _status == EStatus.Failed;
+ }
- ///
- /// 下载过程是否发生错误
- ///
- public bool HasError()
- {
- return _status == EStatus.Failed;
- }
+ ///
+ /// 下载过程是否发生错误
+ ///
+ public bool HasError()
+ {
+ return _status == EStatus.Failed;
+ }
- ///
- /// 按照错误级别打印错误
- ///
- public void ReportError()
- {
- YooLogger.Error(GetLastError());
- }
+ ///
+ /// 按照错误级别打印错误
+ ///
+ public void ReportError()
+ {
+ YooLogger.Error(GetLastError());
+ }
- ///
- /// 按照警告级别打印错误
- ///
- public void ReportWarning()
- {
- YooLogger.Warning(GetLastError());
- }
+ ///
+ /// 按照警告级别打印错误
+ ///
+ public void ReportWarning()
+ {
+ YooLogger.Warning(GetLastError());
+ }
- ///
- /// 获取最近发生的错误信息
- ///
- public string GetLastError()
- {
- return $"Failed to download : {_requestURL} Error : {_lastestNetError} Code : {_lastestHttpCode}";
- }
+ ///
+ /// 获取最近发生的错误信息
+ ///
+ public string GetLastError()
+ {
+ return $"Failed to download : {_requestURL} Error : {_lastestNetError} Code : {_lastestHttpCode}";
+ }
- ///
- /// 获取下载文件的大小
- ///
- ///
- public long GetDownloadFileSize()
- {
- return _bundleInfo.Bundle.FileSize;
- }
+ ///
+ /// 获取下载文件的大小
+ ///
+ ///
+ public long GetDownloadFileSize()
+ {
+ return _bundleInfo.Bundle.FileSize;
+ }
- ///
- /// 获取下载的资源包名称
- ///
- public string GetDownloadBundleName()
- {
- return _bundleInfo.Bundle.BundleName;
- }
+ ///
+ /// 获取下载的资源包名称
+ ///
+ public string GetDownloadBundleName()
+ {
+ return _bundleInfo.Bundle.BundleName;
+ }
- ///
- /// 获取网络请求地址
- ///
- protected string GetRequestURL()
- {
- // 轮流返回请求地址
- _requestCount++;
- if (_requestCount % 2 == 0)
- return _bundleInfo.RemoteFallbackURL;
- else
- return _bundleInfo.RemoteMainURL;
- }
+ ///
+ /// 获取网络请求地址
+ ///
+ protected string GetRequestURL()
+ {
+ // 轮流返回请求地址
+ _requestCount++;
+ if (_requestCount % 2 == 0)
+ return _bundleInfo.RemoteFallbackURL;
+ else
+ return _bundleInfo.RemoteMainURL;
+ }
- ///
- /// 超时判定方法
- ///
- protected void CheckTimeout()
- {
- // 注意:在连续时间段内无新增下载数据及判定为超时
- if (_isAbort == false)
- {
- if (_latestDownloadBytes != DownloadedBytes)
- {
- _latestDownloadBytes = DownloadedBytes;
- _latestDownloadRealtime = Time.realtimeSinceStartup;
- }
+ ///
+ /// 超时判定方法
+ ///
+ protected void CheckTimeout()
+ {
+ // 注意:在连续时间段内无新增下载数据及判定为超时
+ if (_isAbort == false)
+ {
+ if (_latestDownloadBytes != DownloadedBytes)
+ {
+ _latestDownloadBytes = DownloadedBytes;
+ _latestDownloadRealtime = Time.realtimeSinceStartup;
+ }
- float offset = Time.realtimeSinceStartup - _latestDownloadRealtime;
- if (offset > _timeout)
- {
- YooLogger.Warning($"Web file request timeout : {_requestURL}");
- if(_requester != null)
- _requester.Abort();
- _isAbort = true;
- }
- }
- }
- }
+ float offset = Time.realtimeSinceStartup - _latestDownloadRealtime;
+ if (offset > _timeout)
+ {
+ YooLogger.Warning($"Web file request timeout : {_requestURL}");
+ if (_requester != null)
+ _requester.Abort();
+ _isAbort = true;
+ }
+ }
+ }
+ }
}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/DownloadSystem/Downloader/FileDownloader.cs b/Assets/YooAsset/Runtime/DownloadSystem/Downloader/FileDownloader.cs
index f34338f..f7a2b99 100644
--- a/Assets/YooAsset/Runtime/DownloadSystem/Downloader/FileDownloader.cs
+++ b/Assets/YooAsset/Runtime/DownloadSystem/Downloader/FileDownloader.cs
@@ -6,211 +6,211 @@ using UnityEngine;
namespace YooAsset
{
- ///
- /// 文件下载器
- ///
- internal sealed class FileDownloader : DownloaderBase
- {
- private enum ESteps
- {
- None,
- PrepareDownload,
- CreateDownloader,
- CheckDownload,
- VerifyTempFile,
- WaitingVerifyTempFile,
- CachingFile,
- TryAgain,
- Done,
- }
+ ///
+ /// 文件下载器
+ ///
+ internal sealed class FileDownloader : DownloaderBase
+ {
+ private enum ESteps
+ {
+ None,
+ PrepareDownload,
+ CreateDownloader,
+ CheckDownload,
+ VerifyTempFile,
+ WaitingVerifyTempFile,
+ CachingFile,
+ TryAgain,
+ Done,
+ }
- private VerifyTempFileOperation _verifyFileOp = null;
- private ESteps _steps = ESteps.None;
+ private VerifyTempFileOperation _verifyFileOp = null;
+ private ESteps _steps = ESteps.None;
- public FileDownloader(BundleInfo bundleInfo, System.Type requesterType, int failedTryAgain, int timeout) : base(bundleInfo, requesterType, failedTryAgain, timeout)
- {
- }
- public override void SendRequest(params object[] args)
- {
- if (_steps == ESteps.None)
- {
- _steps = ESteps.PrepareDownload;
- }
- }
- public override void Update()
- {
- if (_steps == ESteps.None)
- return;
- if (IsDone())
- return;
+ public FileDownloader(BundleInfo bundleInfo, System.Type requesterType, int failedTryAgain, int timeout) : base(bundleInfo, requesterType, failedTryAgain, timeout)
+ {
+ }
+ public override void SendRequest(params object[] args)
+ {
+ if (_steps == ESteps.None)
+ {
+ _steps = ESteps.PrepareDownload;
+ }
+ }
+ public override void Update()
+ {
+ if (_steps == ESteps.None)
+ return;
+ if (IsDone())
+ return;
- // 准备下载
- if (_steps == ESteps.PrepareDownload)
- {
- // 获取请求地址
- _requestURL = GetRequestURL();
+ // 准备下载
+ if (_steps == ESteps.PrepareDownload)
+ {
+ // 获取请求地址
+ _requestURL = GetRequestURL();
- // 重置变量
- DownloadProgress = 0f;
- DownloadedBytes = 0;
+ // 重置变量
+ DownloadProgress = 0f;
+ DownloadedBytes = 0;
- // 重置变量
- _isAbort = false;
- _latestDownloadBytes = 0;
- _latestDownloadRealtime = Time.realtimeSinceStartup;
+ // 重置变量
+ _isAbort = false;
+ _latestDownloadBytes = 0;
+ _latestDownloadRealtime = Time.realtimeSinceStartup;
- // 重置计时器
- if (_tryAgainTimer > 0f)
- YooLogger.Warning($"Try again download : {_requestURL}");
- _tryAgainTimer = 0f;
+ // 重置计时器
+ if (_tryAgainTimer > 0f)
+ YooLogger.Warning($"Try again download : {_requestURL}");
+ _tryAgainTimer = 0f;
- _steps = ESteps.CreateDownloader;
- }
+ _steps = ESteps.CreateDownloader;
+ }
- // 创建下载器
- if (_steps == ESteps.CreateDownloader)
- {
- _requester = (IWebRequester)Activator.CreateInstance(_requesterType);
- _requester.Create(_requestURL, _bundleInfo);
- _steps = ESteps.CheckDownload;
- }
+ // 创建下载器
+ if (_steps == ESteps.CreateDownloader)
+ {
+ _requester = (IWebRequester)Activator.CreateInstance(_requesterType);
+ _requester.Create(_requestURL, _bundleInfo);
+ _steps = ESteps.CheckDownload;
+ }
- // 检测下载结果
- if (_steps == ESteps.CheckDownload)
- {
- _requester.Update();
- DownloadedBytes = _requester.DownloadedBytes;
- DownloadProgress = _requester.DownloadProgress;
- if (_requester.IsDone() == false)
- {
- CheckTimeout();
- return;
- }
+ // 检测下载结果
+ if (_steps == ESteps.CheckDownload)
+ {
+ _requester.Update();
+ DownloadedBytes = _requester.DownloadedBytes;
+ DownloadProgress = _requester.DownloadProgress;
+ if (_requester.IsDone() == false)
+ {
+ CheckTimeout();
+ return;
+ }
- _lastestNetError = _requester.RequestNetError;
- _lastestHttpCode = _requester.RequestHttpCode;
- if (_requester.Status != ERequestStatus.Success)
- {
- _steps = ESteps.TryAgain;
- }
- else
- {
- _steps = ESteps.VerifyTempFile;
- }
- }
+ _lastestNetError = _requester.RequestNetError;
+ _lastestHttpCode = _requester.RequestHttpCode;
+ if (_requester.Status != ERequestStatus.Success)
+ {
+ _steps = ESteps.TryAgain;
+ }
+ else
+ {
+ _steps = ESteps.VerifyTempFile;
+ }
+ }
- // 验证下载文件
- if (_steps == ESteps.VerifyTempFile)
- {
- VerifyTempFileElement element = new VerifyTempFileElement(_bundleInfo.TempDataFilePath, _bundleInfo.Bundle.FileCRC, _bundleInfo.Bundle.FileSize);
- _verifyFileOp = VerifyTempFileOperation.CreateOperation(element);
- OperationSystem.StartOperation(_bundleInfo.Bundle.PackageName, _verifyFileOp);
- _steps = ESteps.WaitingVerifyTempFile;
- }
+ // 验证下载文件
+ if (_steps == ESteps.VerifyTempFile)
+ {
+ VerifyTempFileElement element = new VerifyTempFileElement(_bundleInfo.TempDataFilePath, _bundleInfo.Bundle.FileCRC, _bundleInfo.Bundle.FileSize);
+ _verifyFileOp = VerifyTempFileOperation.CreateOperation(element);
+ OperationSystem.StartOperation(_bundleInfo.Bundle.PackageName, _verifyFileOp);
+ _steps = ESteps.WaitingVerifyTempFile;
+ }
- // 等待验证完成
- if (_steps == ESteps.WaitingVerifyTempFile)
- {
- if (WaitForAsyncComplete)
- _verifyFileOp.InternalOnUpdate();
+ // 等待验证完成
+ if (_steps == ESteps.WaitingVerifyTempFile)
+ {
+ if (WaitForAsyncComplete)
+ _verifyFileOp.InternalOnUpdate();
- if (_verifyFileOp.IsDone == false)
- return;
+ if (_verifyFileOp.IsDone == false)
+ return;
- if (_verifyFileOp.Status == EOperationStatus.Succeed)
- {
- _steps = ESteps.CachingFile;
- }
- else
- {
- string tempFilePath = _bundleInfo.TempDataFilePath;
- if (File.Exists(tempFilePath))
- File.Delete(tempFilePath);
+ if (_verifyFileOp.Status == EOperationStatus.Succeed)
+ {
+ _steps = ESteps.CachingFile;
+ }
+ else
+ {
+ string tempFilePath = _bundleInfo.TempDataFilePath;
+ if (File.Exists(tempFilePath))
+ File.Delete(tempFilePath);
- _lastestNetError = _verifyFileOp.Error;
- _steps = ESteps.TryAgain;
- }
- }
+ _lastestNetError = _verifyFileOp.Error;
+ _steps = ESteps.TryAgain;
+ }
+ }
- // 缓存下载文件
- if (_steps == ESteps.CachingFile)
- {
- try
- {
- CachingFile();
- _status = EStatus.Succeed;
- _steps = ESteps.Done;
- }
- catch (Exception e)
- {
- _lastestNetError = e.Message;
- _steps = ESteps.TryAgain;
- }
- }
+ // 缓存下载文件
+ if (_steps == ESteps.CachingFile)
+ {
+ try
+ {
+ CachingFile();
+ _status = EStatus.Succeed;
+ _steps = ESteps.Done;
+ }
+ catch (Exception e)
+ {
+ _lastestNetError = e.Message;
+ _steps = ESteps.TryAgain;
+ }
+ }
- // 重新尝试下载
- if (_steps == ESteps.TryAgain)
- {
- if (_failedTryAgain <= 0)
- {
- ReportError();
- _status = EStatus.Failed;
- _steps = ESteps.Done;
- return;
- }
+ // 重新尝试下载
+ if (_steps == ESteps.TryAgain)
+ {
+ if (_failedTryAgain <= 0)
+ {
+ ReportError();
+ _status = EStatus.Failed;
+ _steps = ESteps.Done;
+ return;
+ }
- _tryAgainTimer += Time.unscaledDeltaTime;
- if (_tryAgainTimer > 1f)
- {
- _failedTryAgain--;
- _steps = ESteps.PrepareDownload;
- ReportWarning();
- }
- }
- }
- public override void Abort()
- {
- if (_requester != null)
- _requester.Abort();
+ _tryAgainTimer += Time.unscaledDeltaTime;
+ if (_tryAgainTimer > 1f)
+ {
+ _failedTryAgain--;
+ _steps = ESteps.PrepareDownload;
+ ReportWarning();
+ }
+ }
+ }
+ public override void Abort()
+ {
+ if (_requester != null)
+ _requester.Abort();
- if (IsDone() == false)
- {
- _status = EStatus.Failed;
- _steps = ESteps.Done;
- _lastestNetError = "user abort";
- _lastestHttpCode = 0;
- }
- }
- public override AssetBundle GetAssetBundle()
- {
- throw new NotImplementedException();
- }
+ if (IsDone() == false)
+ {
+ _status = EStatus.Failed;
+ _steps = ESteps.Done;
+ _lastestNetError = "user abort";
+ _lastestHttpCode = 0;
+ }
+ }
+ public override AssetBundle GetAssetBundle()
+ {
+ throw new NotImplementedException();
+ }
- ///
- /// 缓存下载文件
- ///
- private void CachingFile()
- {
- string tempFilePath = _bundleInfo.TempDataFilePath;
- string infoFilePath = _bundleInfo.CachedInfoFilePath;
- string dataFilePath = _bundleInfo.CachedDataFilePath;
- string dataFileCRC = _bundleInfo.Bundle.FileCRC;
- long dataFileSize = _bundleInfo.Bundle.FileSize;
+ ///
+ /// 缓存下载文件
+ ///
+ private void CachingFile()
+ {
+ string tempFilePath = _bundleInfo.TempDataFilePath;
+ string infoFilePath = _bundleInfo.CachedInfoFilePath;
+ string dataFilePath = _bundleInfo.CachedDataFilePath;
+ string dataFileCRC = _bundleInfo.Bundle.FileCRC;
+ long dataFileSize = _bundleInfo.Bundle.FileSize;
- if (File.Exists(infoFilePath))
- File.Delete(infoFilePath);
- if (File.Exists(dataFilePath))
- File.Delete(dataFilePath);
+ if (File.Exists(infoFilePath))
+ File.Delete(infoFilePath);
+ if (File.Exists(dataFilePath))
+ File.Delete(dataFilePath);
- // 移动临时文件路径
- FileInfo fileInfo = new FileInfo(tempFilePath);
- fileInfo.MoveTo(dataFilePath);
+ // 移动临时文件路径
+ FileInfo fileInfo = new FileInfo(tempFilePath);
+ fileInfo.MoveTo(dataFilePath);
- // 写入信息文件记录验证数据
- CacheFileInfo.WriteInfoToFile(infoFilePath, dataFileCRC, dataFileSize);
+ // 写入信息文件记录验证数据
+ CacheFileInfo.WriteInfoToFile(infoFilePath, dataFileCRC, dataFileSize);
- // 记录缓存文件
- _bundleInfo.CacheRecord();
- }
- }
+ // 记录缓存文件
+ _bundleInfo.CacheRecord();
+ }
+ }
}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/DownloadSystem/Downloader/WebDownloader.cs b/Assets/YooAsset/Runtime/DownloadSystem/Downloader/WebDownloader.cs
index 87fb363..83ac7e5 100644
--- a/Assets/YooAsset/Runtime/DownloadSystem/Downloader/WebDownloader.cs
+++ b/Assets/YooAsset/Runtime/DownloadSystem/Downloader/WebDownloader.cs
@@ -6,135 +6,135 @@ using UnityEngine;
namespace YooAsset
{
- internal sealed class WebDownloader : DownloaderBase
- {
- private enum ESteps
- {
- None,
- PrepareDownload,
- CreateDownloader,
- CheckDownload,
- TryAgain,
- Done,
- }
+ internal sealed class WebDownloader : DownloaderBase
+ {
+ private enum ESteps
+ {
+ None,
+ PrepareDownload,
+ CreateDownloader,
+ CheckDownload,
+ TryAgain,
+ Done,
+ }
- private ESteps _steps = ESteps.None;
- private bool _getAssetBundle = false;
+ private ESteps _steps = ESteps.None;
+ private bool _getAssetBundle = false;
- public WebDownloader(BundleInfo bundleInfo, System.Type requesterType, int failedTryAgain, int timeout) : base(bundleInfo, requesterType, failedTryAgain, timeout)
- {
- }
- public override void SendRequest(params object[] args)
- {
- if (_steps == ESteps.None)
- {
- if (args.Length > 0)
- {
- _getAssetBundle = (bool)args[0];
- }
- _steps = ESteps.PrepareDownload;
- }
- }
- public override void Update()
- {
- if (_steps == ESteps.None)
- return;
- if (IsDone())
- return;
+ public WebDownloader(BundleInfo bundleInfo, System.Type requesterType, int failedTryAgain, int timeout) : base(bundleInfo, requesterType, failedTryAgain, timeout)
+ {
+ }
+ public override void SendRequest(params object[] args)
+ {
+ if (_steps == ESteps.None)
+ {
+ if (args.Length > 0)
+ {
+ _getAssetBundle = (bool)args[0];
+ }
+ _steps = ESteps.PrepareDownload;
+ }
+ }
+ public override void Update()
+ {
+ if (_steps == ESteps.None)
+ return;
+ if (IsDone())
+ return;
- // 创建下载器
- if (_steps == ESteps.PrepareDownload)
- {
- // 获取请求地址
- _requestURL = GetRequestURL();
+ // 创建下载器
+ if (_steps == ESteps.PrepareDownload)
+ {
+ // 获取请求地址
+ _requestURL = GetRequestURL();
- // 重置变量
- DownloadProgress = 0f;
- DownloadedBytes = 0;
+ // 重置变量
+ DownloadProgress = 0f;
+ DownloadedBytes = 0;
- // 重置变量
- _isAbort = false;
- _latestDownloadBytes = 0;
- _latestDownloadRealtime = Time.realtimeSinceStartup;
+ // 重置变量
+ _isAbort = false;
+ _latestDownloadBytes = 0;
+ _latestDownloadRealtime = Time.realtimeSinceStartup;
- // 重置计时器
- if (_tryAgainTimer > 0f)
- YooLogger.Warning($"Try again download : {_requestURL}");
- _tryAgainTimer = 0f;
+ // 重置计时器
+ if (_tryAgainTimer > 0f)
+ YooLogger.Warning($"Try again download : {_requestURL}");
+ _tryAgainTimer = 0f;
- _steps = ESteps.CreateDownloader;
- }
+ _steps = ESteps.CreateDownloader;
+ }
- // 创建下载器
- if (_steps == ESteps.CreateDownloader)
- {
- _requester = (IWebRequester)Activator.CreateInstance(_requesterType);
- _requester.Create(_requestURL, _bundleInfo, _getAssetBundle);
- _steps = ESteps.CheckDownload;
- }
+ // 创建下载器
+ if (_steps == ESteps.CreateDownloader)
+ {
+ _requester = (IWebRequester)Activator.CreateInstance(_requesterType);
+ _requester.Create(_requestURL, _bundleInfo, _getAssetBundle);
+ _steps = ESteps.CheckDownload;
+ }
- // 检测下载结果
- if (_steps == ESteps.CheckDownload)
- {
- _requester.Update();
- DownloadedBytes = _requester.DownloadedBytes;
- DownloadProgress = _requester.DownloadProgress;
- if (_requester.IsDone() == false)
- {
- CheckTimeout();
- return;
- }
+ // 检测下载结果
+ if (_steps == ESteps.CheckDownload)
+ {
+ _requester.Update();
+ DownloadedBytes = _requester.DownloadedBytes;
+ DownloadProgress = _requester.DownloadProgress;
+ if (_requester.IsDone() == false)
+ {
+ CheckTimeout();
+ return;
+ }
- _lastestNetError = _requester.RequestNetError;
- _lastestHttpCode = _requester.RequestHttpCode;
- if (_requester.Status != ERequestStatus.Success)
- {
- _steps = ESteps.TryAgain;
- }
- else
- {
- _status = EStatus.Succeed;
- _steps = ESteps.Done;
- }
- }
+ _lastestNetError = _requester.RequestNetError;
+ _lastestHttpCode = _requester.RequestHttpCode;
+ if (_requester.Status != ERequestStatus.Success)
+ {
+ _steps = ESteps.TryAgain;
+ }
+ else
+ {
+ _status = EStatus.Succeed;
+ _steps = ESteps.Done;
+ }
+ }
- // 重新尝试下载
- if (_steps == ESteps.TryAgain)
- {
- if (_failedTryAgain <= 0)
- {
- ReportError();
- _status = EStatus.Failed;
- _steps = ESteps.Done;
- return;
- }
+ // 重新尝试下载
+ if (_steps == ESteps.TryAgain)
+ {
+ if (_failedTryAgain <= 0)
+ {
+ ReportError();
+ _status = EStatus.Failed;
+ _steps = ESteps.Done;
+ return;
+ }
- _tryAgainTimer += Time.unscaledDeltaTime;
- if (_tryAgainTimer > 1f)
- {
- _failedTryAgain--;
- _steps = ESteps.PrepareDownload;
- ReportWarning();
- YooLogger.Warning($"Try again download : {_requestURL}");
- }
- }
- }
- public override void Abort()
- {
- if (_requester != null)
- _requester.Abort();
+ _tryAgainTimer += Time.unscaledDeltaTime;
+ if (_tryAgainTimer > 1f)
+ {
+ _failedTryAgain--;
+ _steps = ESteps.PrepareDownload;
+ ReportWarning();
+ YooLogger.Warning($"Try again download : {_requestURL}");
+ }
+ }
+ }
+ public override void Abort()
+ {
+ if (_requester != null)
+ _requester.Abort();
- if (IsDone() == false)
- {
- _status = EStatus.Failed;
- _steps = ESteps.Done;
- _lastestNetError = "user abort";
- _lastestHttpCode = 0;
- }
- }
- public override AssetBundle GetAssetBundle()
- {
- return (AssetBundle)_requester.GetRequestObject();
- }
- }
+ if (IsDone() == false)
+ {
+ _status = EStatus.Failed;
+ _steps = ESteps.Done;
+ _lastestNetError = "user abort";
+ _lastestHttpCode = 0;
+ }
+ }
+ public override AssetBundle GetAssetBundle()
+ {
+ return (AssetBundle)_requester.GetRequestObject();
+ }
+ }
}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/DownloadSystem/RequestHelper.cs b/Assets/YooAsset/Runtime/DownloadSystem/RequestHelper.cs
index 22f4652..3f99b6f 100644
--- a/Assets/YooAsset/Runtime/DownloadSystem/RequestHelper.cs
+++ b/Assets/YooAsset/Runtime/DownloadSystem/RequestHelper.cs
@@ -4,33 +4,33 @@ using System.Collections.Generic;
namespace YooAsset
{
- public class RequestHelper
- {
- ///
- /// 记录网络请求失败事件的次数
- ///
- private static readonly Dictionary _requestFailedRecorder = new Dictionary(1000);
+ public class RequestHelper
+ {
+ ///
+ /// 记录网络请求失败事件的次数
+ ///
+ private static readonly Dictionary _requestFailedRecorder = new Dictionary(1000);
- ///
- /// 记录请求失败事件
- ///
- public static void RecordRequestFailed(string packageName, string eventName)
- {
- string key = $"{packageName}_{eventName}";
- if (_requestFailedRecorder.ContainsKey(key) == false)
- _requestFailedRecorder.Add(key, 0);
- _requestFailedRecorder[key]++;
- }
+ ///
+ /// 记录请求失败事件
+ ///
+ public static void RecordRequestFailed(string packageName, string eventName)
+ {
+ string key = $"{packageName}_{eventName}";
+ if (_requestFailedRecorder.ContainsKey(key) == false)
+ _requestFailedRecorder.Add(key, 0);
+ _requestFailedRecorder[key]++;
+ }
- ///
- /// 获取请求失败的次数
- ///
- public static int GetRequestFailedCount(string packageName, string eventName)
- {
- string key = $"{packageName}_{eventName}";
- if (_requestFailedRecorder.ContainsKey(key) == false)
- _requestFailedRecorder.Add(key, 0);
- return _requestFailedRecorder[key];
- }
- }
+ ///
+ /// 获取请求失败的次数
+ ///
+ public static int GetRequestFailedCount(string packageName, string eventName)
+ {
+ string key = $"{packageName}_{eventName}";
+ if (_requestFailedRecorder.ContainsKey(key) == false)
+ _requestFailedRecorder.Add(key, 0);
+ return _requestFailedRecorder[key];
+ }
+ }
}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/DownloadSystem/Requester/AssetBundleWebRequest.cs b/Assets/YooAsset/Runtime/DownloadSystem/Requester/AssetBundleWebRequest.cs
index 234f7d8..797b8c7 100644
--- a/Assets/YooAsset/Runtime/DownloadSystem/Requester/AssetBundleWebRequest.cs
+++ b/Assets/YooAsset/Runtime/DownloadSystem/Requester/AssetBundleWebRequest.cs
@@ -4,76 +4,76 @@ using UnityEngine.Networking;
namespace YooAsset
{
- internal class AssetBundleWebRequest : IWebRequester
- {
- private UnityWebRequest _webRequest;
- private DownloadHandlerAssetBundle _downloadhandler;
- private AssetBundle _cacheAssetBundle;
- private bool _getAssetBundle = false;
+ internal class AssetBundleWebRequest : IWebRequester
+ {
+ private UnityWebRequest _webRequest;
+ private DownloadHandlerAssetBundle _downloadhandler;
+ private AssetBundle _cacheAssetBundle;
+ private bool _getAssetBundle = false;
- public ERequestStatus Status { private set; get; } = ERequestStatus.None;
- public float DownloadProgress { private set; get; }
- public ulong DownloadedBytes { private set; get; }
- public string RequestNetError { private set; get; }
- public long RequestHttpCode { private set; get; }
+ public ERequestStatus Status { private set; get; } = ERequestStatus.None;
+ public float DownloadProgress { private set; get; }
+ public ulong DownloadedBytes { private set; get; }
+ public string RequestNetError { private set; get; }
+ public long RequestHttpCode { private set; get; }
- public AssetBundleWebRequest() { }
- public void Create(string requestURL, BundleInfo bundleInfo, params object[] args)
- {
- if (Status != ERequestStatus.None)
- throw new System.Exception("Should never get here !");
+ public AssetBundleWebRequest() { }
+ public void Create(string requestURL, BundleInfo bundleInfo, params object[] args)
+ {
+ if (Status != ERequestStatus.None)
+ throw new System.Exception("Should never get here !");
- if (args.Length == 0)
- throw new System.Exception("Not found param value");
+ if (args.Length == 0)
+ throw new System.Exception("Not found param value");
- // 解析附加参数
- _getAssetBundle = (bool)args[0];
+ // 解析附加参数
+ _getAssetBundle = (bool)args[0];
- // 创建下载器
- _webRequest = DownloadHelper.NewRequest(requestURL);
- if (CacheHelper.DisableUnityCacheOnWebGL)
- {
- uint crc = bundleInfo.Bundle.UnityCRC;
- _downloadhandler = new DownloadHandlerAssetBundle(requestURL, crc);
- }
- else
- {
- uint crc = bundleInfo.Bundle.UnityCRC;
- var hash = Hash128.Parse(bundleInfo.Bundle.FileHash);
- _downloadhandler = new DownloadHandlerAssetBundle(requestURL, hash, crc);
- }
+ // 创建下载器
+ _webRequest = DownloadHelper.NewRequest(requestURL);
+ if (CacheHelper.DisableUnityCacheOnWebGL)
+ {
+ uint crc = bundleInfo.Bundle.UnityCRC;
+ _downloadhandler = new DownloadHandlerAssetBundle(requestURL, crc);
+ }
+ else
+ {
+ uint crc = bundleInfo.Bundle.UnityCRC;
+ var hash = Hash128.Parse(bundleInfo.Bundle.FileHash);
+ _downloadhandler = new DownloadHandlerAssetBundle(requestURL, hash, crc);
+ }
#if UNITY_2020_3_OR_NEWER
- _downloadhandler.autoLoadAssetBundle = false;
+ _downloadhandler.autoLoadAssetBundle = false;
#endif
- _webRequest.downloadHandler = _downloadhandler;
- _webRequest.disposeDownloadHandlerOnDispose = true;
- _webRequest.SendWebRequest();
- Status = ERequestStatus.InProgress;
- }
- public void Update()
- {
- if (Status == ERequestStatus.None)
- return;
- if (IsDone())
- return;
+ _webRequest.downloadHandler = _downloadhandler;
+ _webRequest.disposeDownloadHandlerOnDispose = true;
+ _webRequest.SendWebRequest();
+ Status = ERequestStatus.InProgress;
+ }
+ public void Update()
+ {
+ if (Status == ERequestStatus.None)
+ return;
+ if (IsDone())
+ return;
- DownloadProgress = _webRequest.downloadProgress;
- DownloadedBytes = _webRequest.downloadedBytes;
- if (_webRequest.isDone == false)
- return;
+ DownloadProgress = _webRequest.downloadProgress;
+ DownloadedBytes = _webRequest.downloadedBytes;
+ if (_webRequest.isDone == false)
+ return;
- // 检查网络错误
+ // 检查网络错误
#if UNITY_2020_3_OR_NEWER
- RequestHttpCode = _webRequest.responseCode;
- if (_webRequest.result != UnityWebRequest.Result.Success)
- {
- RequestNetError = _webRequest.error;
- Status = ERequestStatus.Error;
- }
- else
- {
- Status = ERequestStatus.Success;
- }
+ RequestHttpCode = _webRequest.responseCode;
+ if (_webRequest.result != UnityWebRequest.Result.Success)
+ {
+ RequestNetError = _webRequest.error;
+ Status = ERequestStatus.Error;
+ }
+ else
+ {
+ Status = ERequestStatus.Success;
+ }
#else
RequestHttpCode = _webRequest.responseCode;
if (_webRequest.isNetworkError || _webRequest.isHttpError)
@@ -87,59 +87,59 @@ namespace YooAsset
}
#endif
- // 缓存加载的AssetBundle对象
- if (Status == ERequestStatus.Success)
- {
- if (_getAssetBundle)
- {
- _cacheAssetBundle = _downloadhandler.assetBundle;
- if (_cacheAssetBundle == null)
- {
- RequestNetError = "assetBundle is null";
- Status = ERequestStatus.Error;
- }
- }
- }
+ // 缓存加载的AssetBundle对象
+ if (Status == ERequestStatus.Success)
+ {
+ if (_getAssetBundle)
+ {
+ _cacheAssetBundle = _downloadhandler.assetBundle;
+ if (_cacheAssetBundle == null)
+ {
+ RequestNetError = "assetBundle is null";
+ Status = ERequestStatus.Error;
+ }
+ }
+ }
- // 最终释放下载器
- DisposeWebRequest();
- }
- public void Abort()
- {
- // 如果下载任务还未开始
- if (Status == ERequestStatus.None)
- {
- RequestNetError = "user cancel";
- Status = ERequestStatus.Error;
- }
- else
- {
- // 注意:为了防止同一个文件强制停止之后立马创建新的请求,应该让进行中的请求自然终止。
- if (_webRequest != null)
- {
- if (_webRequest.isDone == false)
- _webRequest.Abort(); // If in progress, halts the UnityWebRequest as soon as possible.
- }
- }
- }
- public bool IsDone()
- {
- if (Status == ERequestStatus.Success || Status == ERequestStatus.Error)
- return true;
- else
- return false;
- }
- public object GetRequestObject()
- {
- return _cacheAssetBundle;
- }
- private void DisposeWebRequest()
- {
- if (_webRequest != null)
- {
- _webRequest.Dispose();
- _webRequest = null;
- }
- }
- }
+ // 最终释放下载器
+ DisposeWebRequest();
+ }
+ public void Abort()
+ {
+ // 如果下载任务还未开始
+ if (Status == ERequestStatus.None)
+ {
+ RequestNetError = "user cancel";
+ Status = ERequestStatus.Error;
+ }
+ else
+ {
+ // 注意:为了防止同一个文件强制停止之后立马创建新的请求,应该让进行中的请求自然终止。
+ if (_webRequest != null)
+ {
+ if (_webRequest.isDone == false)
+ _webRequest.Abort(); // If in progress, halts the UnityWebRequest as soon as possible.
+ }
+ }
+ }
+ public bool IsDone()
+ {
+ if (Status == ERequestStatus.Success || Status == ERequestStatus.Error)
+ return true;
+ else
+ return false;
+ }
+ public object GetRequestObject()
+ {
+ return _cacheAssetBundle;
+ }
+ private void DisposeWebRequest()
+ {
+ if (_webRequest != null)
+ {
+ _webRequest.Dispose();
+ _webRequest = null;
+ }
+ }
+ }
}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/DownloadSystem/Requester/DownloadHandlerFileRange.cs b/Assets/YooAsset/Runtime/DownloadSystem/Requester/DownloadHandlerFileRange.cs
index f439e47..c2e11f4 100644
--- a/Assets/YooAsset/Runtime/DownloadSystem/Requester/DownloadHandlerFileRange.cs
+++ b/Assets/YooAsset/Runtime/DownloadSystem/Requester/DownloadHandlerFileRange.cs
@@ -5,83 +5,83 @@ using UnityEngine.Networking;
namespace YooAsset
{
- ///
- /// 支持Unity2018版本的断点续传下载器
- ///
- internal class DownloadHandlerFileRange : DownloadHandlerScript
- {
- private string _fileSavePath;
- private long _fileTotalSize;
- private UnityWebRequest _webRequest;
- private FileStream _fileStream;
+ ///
+ /// 支持Unity2018版本的断点续传下载器
+ ///
+ internal class DownloadHandlerFileRange : DownloadHandlerScript
+ {
+ private string _fileSavePath;
+ private long _fileTotalSize;
+ private UnityWebRequest _webRequest;
+ private FileStream _fileStream;
- private long _localFileSize = 0;
- private long _curFileSize = 0;
+ private long _localFileSize = 0;
+ private long _curFileSize = 0;
- public DownloadHandlerFileRange(string fileSavePath, long fileTotalSize, UnityWebRequest webRequest) : base(new byte[1024 * 1024])
- {
- _fileSavePath = fileSavePath;
- _fileTotalSize = fileTotalSize;
- _webRequest = webRequest;
+ public DownloadHandlerFileRange(string fileSavePath, long fileTotalSize, UnityWebRequest webRequest) : base(new byte[1024 * 1024])
+ {
+ _fileSavePath = fileSavePath;
+ _fileTotalSize = fileTotalSize;
+ _webRequest = webRequest;
- if (File.Exists(fileSavePath))
- {
- FileInfo fileInfo = new FileInfo(fileSavePath);
- _localFileSize = fileInfo.Length;
- }
+ if (File.Exists(fileSavePath))
+ {
+ FileInfo fileInfo = new FileInfo(fileSavePath);
+ _localFileSize = fileInfo.Length;
+ }
- _fileStream = new FileStream(_fileSavePath, FileMode.Append, FileAccess.Write);
- _curFileSize = _localFileSize;
- }
- protected override bool ReceiveData(byte[] data, int dataLength)
- {
- if (data == null || dataLength == 0 || _webRequest.responseCode >= 400)
- return false;
+ _fileStream = new FileStream(_fileSavePath, FileMode.Append, FileAccess.Write);
+ _curFileSize = _localFileSize;
+ }
+ protected override bool ReceiveData(byte[] data, int dataLength)
+ {
+ if (data == null || dataLength == 0 || _webRequest.responseCode >= 400)
+ return false;
- if (_fileStream == null)
- return false;
+ if (_fileStream == null)
+ return false;
- _fileStream.Write(data, 0, dataLength);
- _curFileSize += dataLength;
- return true;
- }
+ _fileStream.Write(data, 0, dataLength);
+ _curFileSize += dataLength;
+ return true;
+ }
- ///
- /// UnityWebRequest.downloadHandler.data
- ///
- protected override byte[] GetData()
- {
- return null;
- }
+ ///
+ /// UnityWebRequest.downloadHandler.data
+ ///
+ protected override byte[] GetData()
+ {
+ return null;
+ }
- ///
- /// UnityWebRequest.downloadHandler.text
- ///
- protected override string GetText()
- {
- return null;
- }
+ ///
+ /// UnityWebRequest.downloadHandler.text
+ ///
+ protected override string GetText()
+ {
+ return null;
+ }
- ///
- /// UnityWebRequest.downloadProgress
- ///
- protected override float GetProgress()
- {
- return _fileTotalSize == 0 ? 0 : ((float)_curFileSize) / _fileTotalSize;
- }
+ ///
+ /// UnityWebRequest.downloadProgress
+ ///
+ protected override float GetProgress()
+ {
+ return _fileTotalSize == 0 ? 0 : ((float)_curFileSize) / _fileTotalSize;
+ }
- ///
- /// 释放下载句柄
- ///
- public void Cleanup()
- {
- if (_fileStream != null)
- {
- _fileStream.Flush();
- _fileStream.Dispose();
- _fileStream = null;
- }
- }
- }
+ ///
+ /// 释放下载句柄
+ ///
+ public void Cleanup()
+ {
+ if (_fileStream != null)
+ {
+ _fileStream.Flush();
+ _fileStream.Dispose();
+ _fileStream = null;
+ }
+ }
+ }
}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/DownloadSystem/Requester/FileGeneralRequest.cs b/Assets/YooAsset/Runtime/DownloadSystem/Requester/FileGeneralRequest.cs
index 0838f53..4d90ba3 100644
--- a/Assets/YooAsset/Runtime/DownloadSystem/Requester/FileGeneralRequest.cs
+++ b/Assets/YooAsset/Runtime/DownloadSystem/Requester/FileGeneralRequest.cs
@@ -3,61 +3,61 @@ using UnityEngine.Networking;
namespace YooAsset
{
- internal class FileGeneralRequest : IWebRequester
- {
- private UnityWebRequest _webRequest;
+ internal class FileGeneralRequest : IWebRequester
+ {
+ private UnityWebRequest _webRequest;
- public ERequestStatus Status { private set; get; } = ERequestStatus.None;
- public float DownloadProgress { private set; get; }
- public ulong DownloadedBytes { private set; get; }
- public string RequestNetError { private set; get; }
- public long RequestHttpCode { private set; get; }
-
- public FileGeneralRequest() { }
- public void Create(string requestURL, BundleInfo bundleInfo, params object[] args)
- {
- if (Status != ERequestStatus.None)
- throw new System.Exception("Should never get here !");
+ public ERequestStatus Status { private set; get; } = ERequestStatus.None;
+ public float DownloadProgress { private set; get; }
+ public ulong DownloadedBytes { private set; get; }
+ public string RequestNetError { private set; get; }
+ public long RequestHttpCode { private set; get; }
- string tempFilePath = bundleInfo.TempDataFilePath;
+ public FileGeneralRequest() { }
+ public void Create(string requestURL, BundleInfo bundleInfo, params object[] args)
+ {
+ if (Status != ERequestStatus.None)
+ throw new System.Exception("Should never get here !");
- // 删除临时文件
- if (File.Exists(tempFilePath))
- File.Delete(tempFilePath);
+ string tempFilePath = bundleInfo.TempDataFilePath;
- // 创建下载器
- _webRequest = DownloadHelper.NewRequest(requestURL);
- DownloadHandlerFile handler = new DownloadHandlerFile(tempFilePath);
- handler.removeFileOnAbort = true;
- _webRequest.downloadHandler = handler;
- _webRequest.disposeDownloadHandlerOnDispose = true;
- _webRequest.SendWebRequest();
- Status = ERequestStatus.InProgress;
- }
- public void Update()
- {
- if (Status == ERequestStatus.None)
- return;
- if (IsDone())
- return;
+ // 删除临时文件
+ if (File.Exists(tempFilePath))
+ File.Delete(tempFilePath);
- DownloadProgress = _webRequest.downloadProgress;
- DownloadedBytes = _webRequest.downloadedBytes;
- if (_webRequest.isDone == false)
- return;
+ // 创建下载器
+ _webRequest = DownloadHelper.NewRequest(requestURL);
+ DownloadHandlerFile handler = new DownloadHandlerFile(tempFilePath);
+ handler.removeFileOnAbort = true;
+ _webRequest.downloadHandler = handler;
+ _webRequest.disposeDownloadHandlerOnDispose = true;
+ _webRequest.SendWebRequest();
+ Status = ERequestStatus.InProgress;
+ }
+ public void Update()
+ {
+ if (Status == ERequestStatus.None)
+ return;
+ if (IsDone())
+ return;
- // 检查网络错误
+ DownloadProgress = _webRequest.downloadProgress;
+ DownloadedBytes = _webRequest.downloadedBytes;
+ if (_webRequest.isDone == false)
+ return;
+
+ // 检查网络错误
#if UNITY_2020_3_OR_NEWER
- RequestHttpCode = _webRequest.responseCode;
- if (_webRequest.result != UnityWebRequest.Result.Success)
- {
- RequestNetError = _webRequest.error;
- Status = ERequestStatus.Error;
- }
- else
- {
- Status = ERequestStatus.Success;
- }
+ RequestHttpCode = _webRequest.responseCode;
+ if (_webRequest.result != UnityWebRequest.Result.Success)
+ {
+ RequestNetError = _webRequest.error;
+ Status = ERequestStatus.Error;
+ }
+ else
+ {
+ Status = ERequestStatus.Success;
+ }
#else
RequestHttpCode = _webRequest.responseCode;
if (_webRequest.isNetworkError || _webRequest.isHttpError)
@@ -71,37 +71,37 @@ namespace YooAsset
}
#endif
- // 最终释放下载器
- DisposeWebRequest();
- }
- public void Abort()
- {
- DisposeWebRequest();
- if (IsDone() == false)
- {
- RequestNetError = "user abort";
- RequestHttpCode = 0;
- Status = ERequestStatus.Error;
- }
- }
- public bool IsDone()
- {
- if (Status == ERequestStatus.Success || Status == ERequestStatus.Error)
- return true;
- else
- return false;
- }
- public object GetRequestObject()
- {
- throw new System.NotImplementedException();
- }
- private void DisposeWebRequest()
- {
- if (_webRequest != null)
- {
- _webRequest.Dispose(); //注意:引擎底层会自动调用Abort方法
- _webRequest = null;
- }
- }
- }
+ // 最终释放下载器
+ DisposeWebRequest();
+ }
+ public void Abort()
+ {
+ DisposeWebRequest();
+ if (IsDone() == false)
+ {
+ RequestNetError = "user abort";
+ RequestHttpCode = 0;
+ Status = ERequestStatus.Error;
+ }
+ }
+ public bool IsDone()
+ {
+ if (Status == ERequestStatus.Success || Status == ERequestStatus.Error)
+ return true;
+ else
+ return false;
+ }
+ public object GetRequestObject()
+ {
+ throw new System.NotImplementedException();
+ }
+ private void DisposeWebRequest()
+ {
+ if (_webRequest != null)
+ {
+ _webRequest.Dispose(); //注意:引擎底层会自动调用Abort方法
+ _webRequest = null;
+ }
+ }
+ }
}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/DownloadSystem/Requester/FileResumeRequest.cs b/Assets/YooAsset/Runtime/DownloadSystem/Requester/FileResumeRequest.cs
index d04d8ce..ff304d1 100644
--- a/Assets/YooAsset/Runtime/DownloadSystem/Requester/FileResumeRequest.cs
+++ b/Assets/YooAsset/Runtime/DownloadSystem/Requester/FileResumeRequest.cs
@@ -3,85 +3,85 @@ using UnityEngine.Networking;
namespace YooAsset
{
- internal class FileResumeRequest : IWebRequester
- {
- private string _tempFilePath;
- private UnityWebRequest _webRequest;
- private DownloadHandlerFileRange _downloadHandle;
- private ulong _fileOriginLength = 0;
+ internal class FileResumeRequest : IWebRequester
+ {
+ private string _tempFilePath;
+ private UnityWebRequest _webRequest;
+ private DownloadHandlerFileRange _downloadHandle;
+ private ulong _fileOriginLength = 0;
- public ERequestStatus Status { private set; get; } = ERequestStatus.None;
- public float DownloadProgress { private set; get; }
- public ulong DownloadedBytes { private set; get; }
- public string RequestNetError { private set; get; }
- public long RequestHttpCode { private set; get; }
-
- public FileResumeRequest() { }
- public void Create(string requestURL, BundleInfo bundleInfo, params object[] args)
- {
- if (Status != ERequestStatus.None)
- throw new System.Exception("Should never get here !");
+ public ERequestStatus Status { private set; get; } = ERequestStatus.None;
+ public float DownloadProgress { private set; get; }
+ public ulong DownloadedBytes { private set; get; }
+ public string RequestNetError { private set; get; }
+ public long RequestHttpCode { private set; get; }
- _tempFilePath = bundleInfo.TempDataFilePath;
- long fileBytes = bundleInfo.Bundle.FileSize;
+ public FileResumeRequest() { }
+ public void Create(string requestURL, BundleInfo bundleInfo, params object[] args)
+ {
+ if (Status != ERequestStatus.None)
+ throw new System.Exception("Should never get here !");
- // 获取下载的起始位置
- long fileLength = -1;
- if (File.Exists(_tempFilePath))
- {
- FileInfo fileInfo = new FileInfo(_tempFilePath);
- fileLength = fileInfo.Length;
- _fileOriginLength = (ulong)fileLength;
- DownloadedBytes = _fileOriginLength;
- }
+ _tempFilePath = bundleInfo.TempDataFilePath;
+ long fileBytes = bundleInfo.Bundle.FileSize;
- // 检测下载起始位置是否有效
- if (fileLength >= fileBytes)
- {
- if (File.Exists(_tempFilePath))
- File.Delete(_tempFilePath);
- }
+ // 获取下载的起始位置
+ long fileLength = -1;
+ if (File.Exists(_tempFilePath))
+ {
+ FileInfo fileInfo = new FileInfo(_tempFilePath);
+ fileLength = fileInfo.Length;
+ _fileOriginLength = (ulong)fileLength;
+ DownloadedBytes = _fileOriginLength;
+ }
- // 创建下载器
- _webRequest = DownloadHelper.NewRequest(requestURL);
+ // 检测下载起始位置是否有效
+ if (fileLength >= fileBytes)
+ {
+ if (File.Exists(_tempFilePath))
+ File.Delete(_tempFilePath);
+ }
+
+ // 创建下载器
+ _webRequest = DownloadHelper.NewRequest(requestURL);
#if UNITY_2019_4_OR_NEWER
- var handler = new DownloadHandlerFile(_tempFilePath, true);
- handler.removeFileOnAbort = false;
+ var handler = new DownloadHandlerFile(_tempFilePath, true);
+ handler.removeFileOnAbort = false;
#else
var handler = new DownloadHandlerFileRange(tempFilePath, _bundleInfo.Bundle.FileSize, _webRequest);
_downloadHandle = handler;
#endif
- _webRequest.downloadHandler = handler;
- _webRequest.disposeDownloadHandlerOnDispose = true;
- if (fileLength > 0)
- _webRequest.SetRequestHeader("Range", $"bytes={fileLength}-");
- _webRequest.SendWebRequest();
- Status = ERequestStatus.InProgress;
- }
- public void Update()
- {
- if (Status == ERequestStatus.None)
- return;
- if (IsDone())
- return;
+ _webRequest.downloadHandler = handler;
+ _webRequest.disposeDownloadHandlerOnDispose = true;
+ if (fileLength > 0)
+ _webRequest.SetRequestHeader("Range", $"bytes={fileLength}-");
+ _webRequest.SendWebRequest();
+ Status = ERequestStatus.InProgress;
+ }
+ public void Update()
+ {
+ if (Status == ERequestStatus.None)
+ return;
+ if (IsDone())
+ return;
- DownloadProgress = _webRequest.downloadProgress;
- DownloadedBytes = _fileOriginLength + _webRequest.downloadedBytes;
- if (_webRequest.isDone == false)
- return;
+ DownloadProgress = _webRequest.downloadProgress;
+ DownloadedBytes = _fileOriginLength + _webRequest.downloadedBytes;
+ if (_webRequest.isDone == false)
+ return;
- // 检查网络错误
+ // 检查网络错误
#if UNITY_2020_3_OR_NEWER
- RequestHttpCode = _webRequest.responseCode;
- if (_webRequest.result != UnityWebRequest.Result.Success)
- {
- RequestNetError = _webRequest.error;
- Status = ERequestStatus.Error;
- }
- else
- {
- Status = ERequestStatus.Success;
- }
+ RequestHttpCode = _webRequest.responseCode;
+ if (_webRequest.result != UnityWebRequest.Result.Success)
+ {
+ RequestNetError = _webRequest.error;
+ Status = ERequestStatus.Error;
+ }
+ else
+ {
+ Status = ERequestStatus.Success;
+ }
#else
RequestHttpCode = _webRequest.responseCode;
if (_webRequest.isNetworkError || _webRequest.isHttpError)
@@ -95,56 +95,56 @@ namespace YooAsset
}
#endif
- // 注意:下载断点续传文件发生特殊错误码之后删除文件
- if (Status == ERequestStatus.Error)
- {
- if (DownloadHelper.ClearFileResponseCodes != null)
- {
- if (DownloadHelper.ClearFileResponseCodes.Contains(RequestHttpCode))
- {
- if (File.Exists(_tempFilePath))
- File.Delete(_tempFilePath);
- }
- }
- }
+ // 注意:下载断点续传文件发生特殊错误码之后删除文件
+ if (Status == ERequestStatus.Error)
+ {
+ if (DownloadHelper.ClearFileResponseCodes != null)
+ {
+ if (DownloadHelper.ClearFileResponseCodes.Contains(RequestHttpCode))
+ {
+ if (File.Exists(_tempFilePath))
+ File.Delete(_tempFilePath);
+ }
+ }
+ }
- // 最终释放下载器
- DisposeWebRequest();
- }
- public void Abort()
- {
- DisposeWebRequest();
- if (IsDone() == false)
- {
- RequestNetError = "user abort";
- RequestHttpCode = 0;
- Status = ERequestStatus.Error;
- }
- }
- public bool IsDone()
- {
- if (Status == ERequestStatus.Success || Status == ERequestStatus.Error)
- return true;
- else
- return false;
- }
- public object GetRequestObject()
- {
- throw new System.NotImplementedException();
- }
- private void DisposeWebRequest()
- {
- if (_downloadHandle != null)
- {
- _downloadHandle.Cleanup();
- _downloadHandle = null;
- }
+ // 最终释放下载器
+ DisposeWebRequest();
+ }
+ public void Abort()
+ {
+ DisposeWebRequest();
+ if (IsDone() == false)
+ {
+ RequestNetError = "user abort";
+ RequestHttpCode = 0;
+ Status = ERequestStatus.Error;
+ }
+ }
+ public bool IsDone()
+ {
+ if (Status == ERequestStatus.Success || Status == ERequestStatus.Error)
+ return true;
+ else
+ return false;
+ }
+ public object GetRequestObject()
+ {
+ throw new System.NotImplementedException();
+ }
+ private void DisposeWebRequest()
+ {
+ if (_downloadHandle != null)
+ {
+ _downloadHandle.Cleanup();
+ _downloadHandle = null;
+ }
- if (_webRequest != null)
- {
- _webRequest.Dispose();
- _webRequest = null;
- }
- }
- }
+ if (_webRequest != null)
+ {
+ _webRequest.Dispose();
+ _webRequest = null;
+ }
+ }
+ }
}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/DownloadSystem/Requester/IWebRequester.cs b/Assets/YooAsset/Runtime/DownloadSystem/Requester/IWebRequester.cs
index 4274451..65a9558 100644
--- a/Assets/YooAsset/Runtime/DownloadSystem/Requester/IWebRequester.cs
+++ b/Assets/YooAsset/Runtime/DownloadSystem/Requester/IWebRequester.cs
@@ -1,65 +1,65 @@
namespace YooAsset
{
- internal enum ERequestStatus
- {
- None,
- InProgress,
- Error,
- Success,
- }
+ internal enum ERequestStatus
+ {
+ None,
+ InProgress,
+ Error,
+ Success,
+ }
- internal interface IWebRequester
- {
- ///
- /// 任务状态
- ///
- public ERequestStatus Status { get; }
+ internal interface IWebRequester
+ {
+ ///
+ /// 任务状态
+ ///
+ public ERequestStatus Status { get; }
- ///
- /// 下载进度(0f~1f)
- ///
- public float DownloadProgress { get; }
+ ///
+ /// 下载进度(0f~1f)
+ ///
+ public float DownloadProgress { get; }
- ///
- /// 已经下载的总字节数
- ///
- public ulong DownloadedBytes { get; }
+ ///
+ /// 已经下载的总字节数
+ ///
+ public ulong DownloadedBytes { get; }
- ///
- /// 返回的网络错误
- ///
- public string RequestNetError { get; }
+ ///
+ /// 返回的网络错误
+ ///
+ public string RequestNetError { get; }
- ///
- /// 返回的HTTP CODE
- ///
- public long RequestHttpCode { get; }
+ ///
+ /// 返回的HTTP CODE
+ ///
+ public long RequestHttpCode { get; }
- ///
- /// 创建任务
- ///
- public void Create(string url, BundleInfo bundleInfo, params object[] args);
+ ///
+ /// 创建任务
+ ///
+ public void Create(string url, BundleInfo bundleInfo, params object[] args);
- ///
- /// 更新任务
- ///
- public void Update();
+ ///
+ /// 更新任务
+ ///
+ public void Update();
- ///
- /// 终止任务
- ///
- public void Abort();
+ ///
+ /// 终止任务
+ ///
+ public void Abort();
- ///
- /// 是否已经完成(无论成功或失败)
- ///
- public bool IsDone();
+ ///
+ /// 是否已经完成(无论成功或失败)
+ ///
+ public bool IsDone();
- ///
- /// 获取请求的对象
- ///
- public object GetRequestObject();
- }
+ ///
+ /// 获取请求的对象
+ ///
+ public object GetRequestObject();
+ }
}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/DownloadSystem/ThreadSyncContext.cs b/Assets/YooAsset/Runtime/DownloadSystem/ThreadSyncContext.cs
index fb5f5c5..65af1f1 100644
--- a/Assets/YooAsset/Runtime/DownloadSystem/ThreadSyncContext.cs
+++ b/Assets/YooAsset/Runtime/DownloadSystem/ThreadSyncContext.cs
@@ -5,34 +5,34 @@ using System.Threading;
namespace YooAsset
{
- ///
- /// 同步其它线程里的回调到主线程里
- /// 注意:Unity3D中需要设置Scripting Runtime Version为.NET4.6
- ///
- internal sealed class ThreadSyncContext : SynchronizationContext
- {
- private readonly ConcurrentQueue _safeQueue = new ConcurrentQueue();
+ ///
+ /// 同步其它线程里的回调到主线程里
+ /// 注意:Unity3D中需要设置Scripting Runtime Version为.NET4.6
+ ///
+ internal sealed class ThreadSyncContext : SynchronizationContext
+ {
+ private readonly ConcurrentQueue _safeQueue = new ConcurrentQueue();
- ///
- /// 更新同步队列
- ///
- public void Update()
- {
- while (true)
- {
- if (_safeQueue.TryDequeue(out Action action) == false)
- return;
- action.Invoke();
- }
- }
+ ///
+ /// 更新同步队列
+ ///
+ public void Update()
+ {
+ while (true)
+ {
+ if (_safeQueue.TryDequeue(out Action action) == false)
+ return;
+ action.Invoke();
+ }
+ }
- ///
- /// 向同步队列里投递一个回调方法
- ///
- public override void Post(SendOrPostCallback callback, object state)
- {
- Action action = new Action(() => { callback(state); });
- _safeQueue.Enqueue(action);
- }
- }
+ ///
+ /// 向同步队列里投递一个回调方法
+ ///
+ public override void Post(SendOrPostCallback callback, object state)
+ {
+ Action action = new Action(() => { callback(state); });
+ _safeQueue.Enqueue(action);
+ }
+ }
}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/DownloadSystem/UnityWebDataRequester.cs b/Assets/YooAsset/Runtime/DownloadSystem/UnityWebDataRequester.cs
index fb84e7c..fb109dc 100644
--- a/Assets/YooAsset/Runtime/DownloadSystem/UnityWebDataRequester.cs
+++ b/Assets/YooAsset/Runtime/DownloadSystem/UnityWebDataRequester.cs
@@ -6,46 +6,46 @@ using UnityEngine;
namespace YooAsset
{
- internal class UnityWebDataRequester : UnityWebRequesterBase
- {
- ///
- /// 发送GET请求
- ///
- public void SendRequest(string url, int timeout = 60)
- {
- if (_webRequest == null)
- {
- URL = url;
- ResetTimeout(timeout);
+ internal class UnityWebDataRequester : UnityWebRequesterBase
+ {
+ ///
+ /// 发送GET请求
+ ///
+ public void SendRequest(string url, int timeout = 60)
+ {
+ if (_webRequest == null)
+ {
+ URL = url;
+ ResetTimeout(timeout);
- _webRequest = DownloadHelper.NewRequest(URL);
- DownloadHandlerBuffer handler = new DownloadHandlerBuffer();
- _webRequest.downloadHandler = handler;
- _webRequest.disposeDownloadHandlerOnDispose = true;
- _operationHandle = _webRequest.SendWebRequest();
- }
- }
+ _webRequest = DownloadHelper.NewRequest(URL);
+ DownloadHandlerBuffer handler = new DownloadHandlerBuffer();
+ _webRequest.downloadHandler = handler;
+ _webRequest.disposeDownloadHandlerOnDispose = true;
+ _operationHandle = _webRequest.SendWebRequest();
+ }
+ }
- ///
- /// 获取下载的字节数据
- ///
- public byte[] GetData()
- {
- if (_webRequest != null && IsDone())
- return _webRequest.downloadHandler.data;
- else
- return null;
- }
+ ///
+ /// 获取下载的字节数据
+ ///
+ public byte[] GetData()
+ {
+ if (_webRequest != null && IsDone())
+ return _webRequest.downloadHandler.data;
+ else
+ return null;
+ }
- ///
- /// 获取下载的文本数据
- ///
- public string GetText()
- {
- if (_webRequest != null && IsDone())
- return _webRequest.downloadHandler.text;
- else
- return null;
- }
- }
+ ///
+ /// 获取下载的文本数据
+ ///
+ public string GetText()
+ {
+ if (_webRequest != null && IsDone())
+ return _webRequest.downloadHandler.text;
+ else
+ return null;
+ }
+ }
}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/DownloadSystem/UnityWebFileRequester.cs b/Assets/YooAsset/Runtime/DownloadSystem/UnityWebFileRequester.cs
index 2d15aac..09e1745 100644
--- a/Assets/YooAsset/Runtime/DownloadSystem/UnityWebFileRequester.cs
+++ b/Assets/YooAsset/Runtime/DownloadSystem/UnityWebFileRequester.cs
@@ -6,25 +6,25 @@ using UnityEngine;
namespace YooAsset
{
- internal class UnityWebFileRequester : UnityWebRequesterBase
- {
- ///
- /// 发送GET请求
- ///
- public void SendRequest(string url, string fileSavePath, int timeout = 60)
- {
- if (_webRequest == null)
- {
- URL = url;
- ResetTimeout(timeout);
+ internal class UnityWebFileRequester : UnityWebRequesterBase
+ {
+ ///
+ /// 发送GET请求
+ ///
+ public void SendRequest(string url, string fileSavePath, int timeout = 60)
+ {
+ if (_webRequest == null)
+ {
+ URL = url;
+ ResetTimeout(timeout);
- _webRequest = DownloadHelper.NewRequest(URL);
- DownloadHandlerFile handler = new DownloadHandlerFile(fileSavePath);
- handler.removeFileOnAbort = true;
- _webRequest.downloadHandler = handler;
- _webRequest.disposeDownloadHandlerOnDispose = true;
- _operationHandle = _webRequest.SendWebRequest();
- }
- }
- }
+ _webRequest = DownloadHelper.NewRequest(URL);
+ DownloadHandlerFile handler = new DownloadHandlerFile(fileSavePath);
+ handler.removeFileOnAbort = true;
+ _webRequest.downloadHandler = handler;
+ _webRequest.disposeDownloadHandlerOnDispose = true;
+ _operationHandle = _webRequest.SendWebRequest();
+ }
+ }
+ }
}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/DownloadSystem/UnityWebRequesterBase.cs b/Assets/YooAsset/Runtime/DownloadSystem/UnityWebRequesterBase.cs
index 86753f7..620230f 100644
--- a/Assets/YooAsset/Runtime/DownloadSystem/UnityWebRequesterBase.cs
+++ b/Assets/YooAsset/Runtime/DownloadSystem/UnityWebRequesterBase.cs
@@ -6,111 +6,111 @@ using UnityEngine;
namespace YooAsset
{
- internal abstract class UnityWebRequesterBase
- {
- protected UnityWebRequest _webRequest;
- protected UnityWebRequestAsyncOperation _operationHandle;
+ internal abstract class UnityWebRequesterBase
+ {
+ protected UnityWebRequest _webRequest;
+ protected UnityWebRequestAsyncOperation _operationHandle;
- // 超时相关
- private float _timeout;
- private bool _isAbort = false;
- private ulong _latestDownloadBytes;
- private float _latestDownloadRealtime;
+ // 超时相关
+ private float _timeout;
+ private bool _isAbort = false;
+ private ulong _latestDownloadBytes;
+ private float _latestDownloadRealtime;
- ///
- /// 请求URL地址
- ///
- public string URL { protected set; get; }
+ ///
+ /// 请求URL地址
+ ///
+ public string URL { protected set; get; }
- protected void ResetTimeout(float timeout)
- {
- _timeout = timeout;
- _latestDownloadBytes = 0;
- _latestDownloadRealtime = Time.realtimeSinceStartup;
- }
+ protected void ResetTimeout(float timeout)
+ {
+ _timeout = timeout;
+ _latestDownloadBytes = 0;
+ _latestDownloadRealtime = Time.realtimeSinceStartup;
+ }
- ///
- /// 释放下载器
- ///
- public void Dispose()
- {
- if (_webRequest != null)
- {
- _webRequest.Dispose();
- _webRequest = null;
- _operationHandle = null;
- }
- }
+ ///
+ /// 释放下载器
+ ///
+ public void Dispose()
+ {
+ if (_webRequest != null)
+ {
+ _webRequest.Dispose();
+ _webRequest = null;
+ _operationHandle = null;
+ }
+ }
- ///
- /// 是否完毕(无论成功失败)
- ///
- public bool IsDone()
- {
- if (_operationHandle == null)
- return false;
- return _operationHandle.isDone;
- }
+ ///
+ /// 是否完毕(无论成功失败)
+ ///
+ public bool IsDone()
+ {
+ if (_operationHandle == null)
+ return false;
+ return _operationHandle.isDone;
+ }
- ///
- /// 下载进度
- ///
- public float Progress()
- {
- if (_operationHandle == null)
- return 0;
- return _operationHandle.progress;
- }
+ ///
+ /// 下载进度
+ ///
+ public float Progress()
+ {
+ if (_operationHandle == null)
+ return 0;
+ return _operationHandle.progress;
+ }
- ///
- /// 下载是否发生错误
- ///
- public bool HasError()
- {
+ ///
+ /// 下载是否发生错误
+ ///
+ public bool HasError()
+ {
#if UNITY_2020_3_OR_NEWER
- return _webRequest.result != UnityWebRequest.Result.Success;
+ return _webRequest.result != UnityWebRequest.Result.Success;
#else
if (_webRequest.isNetworkError || _webRequest.isHttpError)
return true;
else
return false;
#endif
- }
+ }
- ///
- /// 获取错误信息
- ///
- public string GetError()
- {
- if (_webRequest != null)
- {
- return $"URL : {URL} Error : {_webRequest.error}";
- }
- return string.Empty;
- }
+ ///
+ /// 获取错误信息
+ ///
+ public string GetError()
+ {
+ if (_webRequest != null)
+ {
+ return $"URL : {URL} Error : {_webRequest.error}";
+ }
+ return string.Empty;
+ }
- ///
- /// 检测超时
- ///
- public void CheckTimeout()
- {
- // 注意:在连续时间段内无新增下载数据及判定为超时
- if (_isAbort == false)
- {
- if (_latestDownloadBytes != _webRequest.downloadedBytes)
- {
- _latestDownloadBytes = _webRequest.downloadedBytes;
- _latestDownloadRealtime = Time.realtimeSinceStartup;
- }
+ ///
+ /// 检测超时
+ ///
+ public void CheckTimeout()
+ {
+ // 注意:在连续时间段内无新增下载数据及判定为超时
+ if (_isAbort == false)
+ {
+ if (_latestDownloadBytes != _webRequest.downloadedBytes)
+ {
+ _latestDownloadBytes = _webRequest.downloadedBytes;
+ _latestDownloadRealtime = Time.realtimeSinceStartup;
+ }
- float offset = Time.realtimeSinceStartup - _latestDownloadRealtime;
- if (offset > _timeout)
- {
- _webRequest.Abort();
- _isAbort = true;
- }
- }
- }
- }
+ float offset = Time.realtimeSinceStartup - _latestDownloadRealtime;
+ if (offset > _timeout)
+ {
+ _webRequest.Abort();
+ _isAbort = true;
+ }
+ }
+ }
+ }
}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/InitializeParameters.cs b/Assets/YooAsset/Runtime/InitializeParameters.cs
index fb2cbce..8925dbb 100644
--- a/Assets/YooAsset/Runtime/InitializeParameters.cs
+++ b/Assets/YooAsset/Runtime/InitializeParameters.cs
@@ -1,154 +1,154 @@
namespace YooAsset
{
- ///
- /// 默认的构建管线
- ///
- public enum EDefaultBuildPipeline
- {
- ///
- /// 内置构建管线
- ///
- BuiltinBuildPipeline,
+ ///
+ /// 默认的构建管线
+ ///
+ public enum EDefaultBuildPipeline
+ {
+ ///
+ /// 内置构建管线
+ ///
+ BuiltinBuildPipeline,
- ///
- /// 可编程构建管线
- ///
- ScriptableBuildPipeline,
+ ///
+ /// 可编程构建管线
+ ///
+ ScriptableBuildPipeline,
- ///
- /// 原生文件构建管线
- ///
- RawFileBuildPipeline,
- }
+ ///
+ /// 原生文件构建管线
+ ///
+ RawFileBuildPipeline,
+ }
- ///
- /// 运行模式
- ///
- public enum EPlayMode
- {
- ///
- /// 编辑器下的模拟模式
- ///
- EditorSimulateMode,
+ ///
+ /// 运行模式
+ ///
+ public enum EPlayMode
+ {
+ ///
+ /// 编辑器下的模拟模式
+ ///
+ EditorSimulateMode,
- ///
- /// 离线运行模式
- ///
- OfflinePlayMode,
+ ///
+ /// 离线运行模式
+ ///
+ OfflinePlayMode,
- ///
- /// 联机运行模式
- ///
- HostPlayMode,
+ ///
+ /// 联机运行模式
+ ///
+ HostPlayMode,
- ///
- /// WebGL运行模式
- ///
- WebPlayMode,
- }
+ ///
+ /// WebGL运行模式
+ ///
+ WebPlayMode,
+ }
- ///
- /// 初始化参数
- ///
- public abstract class InitializeParameters
- {
- ///
- /// 内置文件的根路径
- /// 注意:当参数为空的时候会使用默认的根目录。
- ///
- public string BuildinRootDirectory = string.Empty;
+ ///
+ /// 初始化参数
+ ///
+ public abstract class InitializeParameters
+ {
+ ///
+ /// 内置文件的根路径
+ /// 注意:当参数为空的时候会使用默认的根目录。
+ ///
+ public string BuildinRootDirectory = string.Empty;
- ///
- /// 沙盒文件的根路径
- /// 注意:当参数为空的时候会使用默认的根目录。
- ///
- public string SandboxRootDirectory = string.Empty;
+ ///
+ /// 沙盒文件的根路径
+ /// 注意:当参数为空的时候会使用默认的根目录。
+ ///
+ public string SandboxRootDirectory = string.Empty;
- ///
- /// 缓存文件追加原始后缀格式
- ///
- public bool CacheFileAppendExtension = false;
+ ///
+ /// 缓存文件追加原始后缀格式
+ ///
+ public bool CacheFileAppendExtension = false;
- ///
- /// 缓存系统启动时的验证级别
- ///
- public EVerifyLevel CacheBootVerifyLevel = EVerifyLevel.Middle;
+ ///
+ /// 缓存系统启动时的验证级别
+ ///
+ public EVerifyLevel CacheBootVerifyLevel = EVerifyLevel.Middle;
- ///
- /// 自动销毁不再使用的资源提供者
- ///
- public bool AutoDestroyAssetProvider = false;
+ ///
+ /// 自动销毁不再使用的资源提供者
+ ///
+ public bool AutoDestroyAssetProvider = false;
- ///
- /// 启用断点续传参数
- /// 说明:当文件的大小大于设置的字节数时启用断点续传下载器
- ///
- public uint BreakpointResumeFileSize = int.MaxValue;
+ ///
+ /// 启用断点续传参数
+ /// 说明:当文件的大小大于设置的字节数时启用断点续传下载器
+ ///
+ public uint BreakpointResumeFileSize = int.MaxValue;
- ///
- /// 文件解密服务接口
- ///
- public IDecryptionServices DecryptionServices = null;
- }
+ ///
+ /// 文件解密服务接口
+ ///
+ public IDecryptionServices DecryptionServices = null;
+ }
- ///
- /// 编辑器下模拟运行模式的初始化参数
- ///
- public class EditorSimulateModeParameters : InitializeParameters
- {
- ///
- /// 用于模拟运行的资源清单路径
- ///
- public string SimulateManifestFilePath = string.Empty;
- }
+ ///
+ /// 编辑器下模拟运行模式的初始化参数
+ ///
+ public class EditorSimulateModeParameters : InitializeParameters
+ {
+ ///
+ /// 用于模拟运行的资源清单路径
+ ///
+ public string SimulateManifestFilePath = string.Empty;
+ }
- ///
- /// 离线运行模式的初始化参数
- ///
- public class OfflinePlayModeParameters : InitializeParameters
- {
- }
+ ///
+ /// 离线运行模式的初始化参数
+ ///
+ public class OfflinePlayModeParameters : InitializeParameters
+ {
+ }
- ///
- /// 联机运行模式的初始化参数
- ///
- public class HostPlayModeParameters : InitializeParameters
- {
- ///
- /// 远端资源地址查询服务类
- ///
- public IRemoteServices RemoteServices = null;
+ ///
+ /// 联机运行模式的初始化参数
+ ///
+ public class HostPlayModeParameters : InitializeParameters
+ {
+ ///
+ /// 远端资源地址查询服务类
+ ///
+ public IRemoteServices RemoteServices = null;
- ///
- /// 内置资源查询服务接口
- ///
- public IBuildinQueryServices BuildinQueryServices = null;
+ ///
+ /// 内置资源查询服务接口
+ ///
+ public IBuildinQueryServices BuildinQueryServices = null;
- ///
- /// 分发资源查询服务接口
- ///
- public IDeliveryQueryServices DeliveryQueryServices = null;
+ ///
+ /// 分发资源查询服务接口
+ ///
+ public IDeliveryQueryServices DeliveryQueryServices = null;
- ///
- /// 分发资源加载服务接口
- ///
- public IDeliveryLoadServices DeliveryLoadServices = null;
- }
+ ///
+ /// 分发资源加载服务接口
+ ///
+ public IDeliveryLoadServices DeliveryLoadServices = null;
+ }
- ///
- /// WebGL运行模式的初始化参数
- ///
- public class WebPlayModeParameters : InitializeParameters
- {
- ///
- /// 远端资源地址查询服务类
- ///
- public IRemoteServices RemoteServices = null;
+ ///
+ /// WebGL运行模式的初始化参数
+ ///
+ public class WebPlayModeParameters : InitializeParameters
+ {
+ ///
+ /// 远端资源地址查询服务类
+ ///
+ public IRemoteServices RemoteServices = null;
- ///
- /// 内置资源查询服务接口
- ///
- public IBuildinQueryServices BuildinQueryServices = null;
- }
+ ///
+ /// 内置资源查询服务接口
+ ///
+ public IBuildinQueryServices BuildinQueryServices = null;
+ }
}
\ No newline at end of file
diff --git a/Assets/YooAsset/Runtime/OperationSystem/AsyncOperationBase.cs b/Assets/YooAsset/Runtime/OperationSystem/AsyncOperationBase.cs
index b09522d..892b77f 100644
--- a/Assets/YooAsset/Runtime/OperationSystem/AsyncOperationBase.cs
+++ b/Assets/YooAsset/Runtime/OperationSystem/AsyncOperationBase.cs
@@ -5,148 +5,148 @@ using System.Threading.Tasks;
namespace YooAsset
{
- public abstract class AsyncOperationBase : IEnumerator, IComparable
- {
- // 用户请求的回调
- private Action _callback;
+ public abstract class AsyncOperationBase : IEnumerator, IComparable
+ {
+ // 用户请求的回调
+ private Action _callback;
- // 是否已经完成
- internal bool IsFinish = false;
-
- ///
- /// 所属包裹
- ///
- public string PackageName { private set; get; }
+ // 是否已经完成
+ internal bool IsFinish = false;
- ///
- /// 优先级
- ///
- public uint Priority { set; get; } = 0;
+ ///
+ /// 所属包裹
+ ///
+ public string PackageName { private set; get; }
- ///
- /// 状态
- ///
- public EOperationStatus Status { get; protected set; } = EOperationStatus.None;
+ ///
+ /// 优先级
+ ///
+ public uint Priority { set; get; } = 0;
- ///
- /// 错误信息
- ///
- public string Error { get; protected set; }
+ ///
+ /// 状态
+ ///
+ public EOperationStatus Status { get; protected set; } = EOperationStatus.None;
- ///
- /// 处理进度
- ///
- public float Progress { get; protected set; }
+ ///
+ /// 错误信息
+ ///
+ public string Error { get; protected set; }
- ///
- /// 是否已经完成
- ///
- public bool IsDone
- {
- get
- {
- return Status == EOperationStatus.Failed || Status == EOperationStatus.Succeed;
- }
- }
+ ///
+ /// 处理进度
+ ///
+ public float Progress { get; protected set; }
- ///
- /// 完成事件
- ///
- public event Action Completed
- {
- add
- {
- if (IsDone)
- value.Invoke(this);
- else
- _callback += value;
- }
- remove
- {
- _callback -= value;
- }
- }
+ ///
+ /// 是否已经完成
+ ///
+ public bool IsDone
+ {
+ get
+ {
+ return Status == EOperationStatus.Failed || Status == EOperationStatus.Succeed;
+ }
+ }
- ///
- /// 异步操作任务
- ///
- public Task Task
- {
- get
- {
- if (_taskCompletionSource == null)
- {
- _taskCompletionSource = new TaskCompletionSource