mirror of
https://github.com/tuyoogame/YooAsset.git
synced 2026-05-26 10:40:14 +00:00
refactor : 重构代码
This commit is contained in:
@@ -76,7 +76,7 @@ namespace YooAsset
|
||||
else
|
||||
{
|
||||
if (string.IsNullOrEmpty(_args.FileHash))
|
||||
throw new YooInternalException("File hash is null or empty !");
|
||||
throw new YooInternalException("File hash is null or empty!");
|
||||
|
||||
// 使用 Unity 缓存
|
||||
// 说明:The file hash defining the version of the asset bundle.
|
||||
|
||||
@@ -99,7 +99,7 @@ namespace YooAsset
|
||||
if (_webRequest == null)
|
||||
{
|
||||
Status = EDownloadRequestStatus.Failed;
|
||||
Error = $"[{GetType().Name}] Created web request is null.";
|
||||
Error = $"[{GetType().Name}] Created web request is null!";
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -109,7 +109,7 @@ namespace YooAsset
|
||||
catch (Exception ex)
|
||||
{
|
||||
Status = EDownloadRequestStatus.Failed;
|
||||
Error = $"[{GetType().Name}] Failed to create web request : {ex.Message}";
|
||||
Error = $"[{GetType().Name}] Failed to create web request: {ex.Message}";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -144,7 +144,7 @@ namespace YooAsset
|
||||
else
|
||||
{
|
||||
Status = EDownloadRequestStatus.Failed;
|
||||
Error = $"[{GetType().Name}] URL: {URL} - 错误: {_webRequest.error}";
|
||||
Error = $"[{GetType().Name}] URL: {URL} - Error: {_webRequest.error}";
|
||||
OnRequestFailed();
|
||||
}
|
||||
|
||||
@@ -226,7 +226,7 @@ namespace YooAsset
|
||||
protected void ApplyRequestOptions(int timeout, int watchdogTime, Dictionary<string, string> headers)
|
||||
{
|
||||
if (_webRequest == null)
|
||||
throw new YooInternalException("Web request is null !");
|
||||
throw new YooInternalException("Web request is null!");
|
||||
|
||||
// 设置看门狗超时时间
|
||||
_watchdogTime = watchdogTime;
|
||||
|
||||
@@ -57,7 +57,7 @@ namespace YooAsset
|
||||
#elif UNITY_STANDALONE_LINUX
|
||||
url = StringUtility.Format("file:///root/{0}", path);
|
||||
#else
|
||||
throw new System.NotSupportedException($"[{nameof(DownloadSystemHelper.ConvertToWWWPath)}] not implemented platform: {UnityEngine.Application.platform}");
|
||||
throw new System.NotSupportedException($"[{nameof(DownloadSystemHelper.ConvertToWWWPath)}] Platform '{UnityEngine.Application.platform}' is not supported!");
|
||||
#endif
|
||||
|
||||
// For some special cases when users have special characters in their devices, url paths can not be identified correctly.
|
||||
|
||||
@@ -408,8 +408,6 @@ namespace YooAsset
|
||||
}
|
||||
|
||||
#region 调试信息
|
||||
private const int MaxCycleCheckDepth = 4096; // 循环检测最大深度
|
||||
|
||||
/// <summary>
|
||||
/// 开始的时间
|
||||
/// </summary>
|
||||
@@ -466,6 +464,7 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
private bool WouldCreateCycle(AsyncOperationBase child)
|
||||
{
|
||||
const int MaxCycleCheckDepth = 4096; // 循环检测最大深度
|
||||
var stack = new Stack<AsyncOperationBase>();
|
||||
var visited = new HashSet<AsyncOperationBase>();
|
||||
stack.Push(child);
|
||||
|
||||
@@ -19,17 +19,17 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 所属包裹
|
||||
/// </summary>
|
||||
public string PackageName { private set; get; }
|
||||
public string PackageName { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 资源类型
|
||||
/// </summary>
|
||||
public System.Type AssetType { private set; get; }
|
||||
public System.Type AssetType { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 错误信息
|
||||
/// </summary>
|
||||
public string Error { private set; get; }
|
||||
public string Error { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 加载方法
|
||||
|
||||
@@ -6,17 +6,17 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 清理模式
|
||||
/// </summary>
|
||||
public string ClearMode { set; get; }
|
||||
public string ClearMode { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 附加参数
|
||||
/// </summary>
|
||||
public object ClearParam { set; get; }
|
||||
public object ClearParam { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 资源清单
|
||||
/// </summary>
|
||||
internal PackageManifest Manifest { set; get; }
|
||||
internal PackageManifest Manifest { get; set; }
|
||||
|
||||
public ClearCacheFilesOptions(EFileClearMode clearMode)
|
||||
{
|
||||
|
||||
@@ -35,12 +35,12 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 统计的下载文件总数量
|
||||
/// </summary>
|
||||
public int TotalDownloadCount { private set; get; }
|
||||
public int TotalDownloadCount { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 统计的下载文件的总大小
|
||||
/// </summary>
|
||||
public long TotalDownloadBytes { private set; get; }
|
||||
public long TotalDownloadBytes { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 当前已经完成的下载总数量
|
||||
@@ -61,29 +61,29 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 下载完成事件委托(无论成功或失败)
|
||||
/// </summary>
|
||||
public DownloadFinishedEventHandler DownloadFinishedHandler { set; get; }
|
||||
public DownloadFinishedEventHandler DownloadFinishedHandler { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 下载进度更新事件委托
|
||||
/// </summary>
|
||||
public DownloadProgressChangedEventHandler DownloadProgressChangedHandler { set; get; }
|
||||
public DownloadProgressChangedEventHandler DownloadProgressChangedHandler { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 下载错误事件委托
|
||||
/// </summary>
|
||||
public DownloadErrorEventHandler DownloadErrorHandler { set; get; }
|
||||
public DownloadErrorEventHandler DownloadErrorHandler { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 开始下载单个文件事件委托
|
||||
/// </summary>
|
||||
public DownloadFileStartedEventHandler DownloadFileStartedHandler { set; get; }
|
||||
public DownloadFileStartedEventHandler DownloadFileStartedHandler { get; set; }
|
||||
|
||||
|
||||
internal DownloaderOperation(string packageName, List<BundleInfo> downloadList, int maximumConcurrency, int failedTryAgain)
|
||||
{
|
||||
_packageName = packageName;
|
||||
_bundleInfoList = downloadList;
|
||||
_maximumConcurrency = UnityEngine.Mathf.Clamp(maximumConcurrency, 1, MAX_LOADER_COUNT); ;
|
||||
_maximumConcurrency = UnityEngine.Mathf.Clamp(maximumConcurrency, 1, MAX_LOADER_COUNT);
|
||||
_failedTryAgain = failedTryAgain;
|
||||
|
||||
// 统计下载信息
|
||||
@@ -91,7 +91,7 @@ namespace YooAsset
|
||||
}
|
||||
internal override void InternalStart()
|
||||
{
|
||||
YooLogger.Log($"Begine to download {TotalDownloadCount} files and {TotalDownloadBytes} bytes");
|
||||
YooLogger.Log($"Begin to download {TotalDownloadCount} files and {TotalDownloadBytes} bytes");
|
||||
_steps = ESteps.Check;
|
||||
}
|
||||
internal override void InternalUpdate()
|
||||
|
||||
@@ -9,23 +9,23 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 最大并发数量
|
||||
/// </summary>
|
||||
public int MaximumConcurrency { set; get; }
|
||||
public int MaximumConcurrency { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 失败后的重试次数
|
||||
/// </summary>
|
||||
public int FailedTryAgain { set; get; }
|
||||
public int FailedTryAgain { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 下载资源对象所属资源包内所有资源对象依赖的资源包
|
||||
/// </summary>
|
||||
public bool DownloadBundleDependencies { set; get; }
|
||||
public bool DownloadBundleDependencies { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 资源信息列表
|
||||
/// 说明:如果列表为NULL,则下载所有资产
|
||||
/// </summary>
|
||||
public AssetInfo[] AssetInfos { set; get; }
|
||||
public AssetInfo[] AssetInfos { get; set; }
|
||||
|
||||
public BundleDownloaderOptions(AssetInfo assetInfo, bool downloadDependencies, int maximumConcurrency, int failedTryAgain)
|
||||
{
|
||||
@@ -51,18 +51,18 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 最大并发数量
|
||||
/// </summary>
|
||||
public int MaximumConcurrency { set; get; }
|
||||
public int MaximumConcurrency { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 失败后的重试次数
|
||||
/// </summary>
|
||||
public int FailedTryAgain { set; get; }
|
||||
public int FailedTryAgain { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 资源标签列表
|
||||
/// 说明:如果列表为NULL,则下载所有资产
|
||||
/// </summary>
|
||||
public string[] Tags { set; get; }
|
||||
public string[] Tags { get; set; }
|
||||
|
||||
public ResourceDownloaderOptions(int maximumConcurrency, int failedTryAgain)
|
||||
{
|
||||
@@ -92,18 +92,18 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 最大并发数量
|
||||
/// </summary>
|
||||
public int MaximumConcurrency { set; get; }
|
||||
public int MaximumConcurrency { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 失败后的重试次数
|
||||
/// </summary>
|
||||
public int FailedTryAgain { set; get; }
|
||||
public int FailedTryAgain { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 资源标签列表
|
||||
/// 说明:如果列表为NULL,则解压所有资产
|
||||
/// </summary>
|
||||
public string[] Tags { set; get; }
|
||||
public string[] Tags { get; set; }
|
||||
|
||||
public ResourceUnpackerOptions(int maximumConcurrency, int failedTryAgain)
|
||||
{
|
||||
@@ -133,17 +133,17 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 最大并发数量
|
||||
/// </summary>
|
||||
public int MaximumConcurrency { set; get; }
|
||||
public int MaximumConcurrency { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 失败后的重试次数
|
||||
/// </summary>
|
||||
public int FailedTryAgain { set; get; }
|
||||
public int FailedTryAgain { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 资源包信息列表
|
||||
/// </summary>
|
||||
public ImportBundleInfo[] BundleInfos { set; get; }
|
||||
public ImportBundleInfo[] BundleInfos { get; set; }
|
||||
|
||||
public BundleImporterOptions(ImportBundleInfo[] bundleInfos, int maximumConcurrency, int failedTryAgain)
|
||||
{
|
||||
|
||||
@@ -6,12 +6,12 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 包裹版本
|
||||
/// </summary>
|
||||
public string PackageVersion { set; get; }
|
||||
public string PackageVersion { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 超时时间
|
||||
/// </summary>
|
||||
public int Timeout { set; get; }
|
||||
public int Timeout { get; set; }
|
||||
|
||||
public LoadPackageManifestOptions(string packageVersion, int timeout)
|
||||
{
|
||||
|
||||
@@ -6,12 +6,12 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 预下载的包裹版本
|
||||
/// </summary>
|
||||
public string PackageVersion { set; get; }
|
||||
public string PackageVersion { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 资源清单请求超时时间
|
||||
/// </summary>
|
||||
public int Timeout { set; get; }
|
||||
public int Timeout { get; set; }
|
||||
|
||||
public PreDownloadContentOptions(string packageVersion, int timeout)
|
||||
{
|
||||
|
||||
@@ -18,7 +18,7 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 当前最新的包裹版本
|
||||
/// </summary>
|
||||
public string PackageVersion { private set; get; }
|
||||
public string PackageVersion { get; private set; }
|
||||
|
||||
|
||||
internal RequestPackageVersionOperation(FileSystemHost host, RequestPackageVersionOptions options)
|
||||
|
||||
@@ -6,12 +6,12 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 在URL末尾添加时间戳
|
||||
/// </summary>
|
||||
public bool AppendTimeTicks { set; get; }
|
||||
public bool AppendTimeTicks { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 超时时间
|
||||
/// </summary>
|
||||
public int Timeout { set; get; }
|
||||
public int Timeout { get; set; }
|
||||
|
||||
public RequestPackageVersionOptions(bool appendTimeTicks, int timeout)
|
||||
{
|
||||
|
||||
@@ -900,7 +900,7 @@ namespace YooAsset
|
||||
else if (InitializeStatus == EOperationStatus.Failed)
|
||||
{
|
||||
string error = _initializeOp == null ? string.Empty : _initializeOp.Error;
|
||||
throw new YooPackageException(PackageName, $"Resource package initialization failed! Error : {error}");
|
||||
throw new YooPackageException(PackageName, $"Resource package initialization failed! Error: {error}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user