Compare commits

..

2 Commits

13 changed files with 76 additions and 120 deletions

3
.gitignore vendored
View File

@@ -16,8 +16,6 @@
/ProjectSettings/
/App/
/yoo/
/Assets/Docs
/Assets/Docs.meta
/Assets/StreamingAssets
/Assets/StreamingAssets.meta
/Assets/Samples
@@ -72,7 +70,6 @@ sysinfo.txt
# Builds
*.apk
*.unitypackage
*.zip
# Crashlytics generated file
crashlytics-build.properties

View File

@@ -2,20 +2,6 @@
All notable changes to this package will be documented in this file.
## [2.3.19] - 2026-06-02
### Fixed
- (#734) 修复了强制回收所有资源与自动卸载Bundle冲突。
- (#712) 修复了在禁用边玩边下的时候,加载原生文件流程未处理的问题。
- (#702) 修复了解压行为在包体内文件被篡改后,会无限尝试的问题。
- 修复了释放零引用待处理 Provider 时 UnloadAllAssetsOperation 死锁的问题。
- 修复了缓存文件校验改用清单的 FileCRC/FileSize而非来自 .info 文件的自记录值。
### Improvements
- 优化了资源清单重名键校验仅在 UNITY_EDITOR || DEBUG 下执行。
## [2.3.18] - 2025-12-04
### Fixed

View File

@@ -73,8 +73,10 @@ namespace YooAsset
/// <summary>
/// 自定义参数:初始化的时候缓存文件校验最大并发数
/// 默认值32推荐范围 1-128
/// 说明:过大的值可能导致线程池任务过多,影响系统稳定性
/// </summary>
public int FileVerifyMaxConcurrency { private set; get; } = int.MaxValue;
public int FileVerifyMaxConcurrency { private set; get; } = 32;
/// <summary>
/// 自定义参数:数据文件追加文件格式
@@ -88,13 +90,17 @@ namespace YooAsset
/// <summary>
/// 自定义参数:最大并发连接数
/// 默认值10推荐范围 1-32
/// 说明:过大的并发数可能被服务器限流,也会增加本地资源消耗
/// </summary>
public int DownloadMaxConcurrency { private set; get; } = int.MaxValue;
public int DownloadMaxConcurrency { private set; get; } = 10;
/// <summary>
/// 自定义参数:每帧发起的最大请求数
/// 默认值5推荐范围 1-10
/// 说明:避免单帧发起过多请求导致卡顿
/// </summary>
public int DownloadMaxRequestPerFrame { private set; get; } = int.MaxValue;
public int DownloadMaxRequestPerFrame { private set; get; } = 5;
/// <summary>
/// 自定义参数:下载任务的看门狗机制监控时间
@@ -242,7 +248,14 @@ namespace YooAsset
else if (name == FileSystemParametersDefine.FILE_VERIFY_MAX_CONCURRENCY)
{
int convertValue = Convert.ToInt32(value);
FileVerifyMaxConcurrency = Mathf.Clamp(convertValue, 1, int.MaxValue);
if (convertValue > 256)
{
YooLogger.Warning($"FILE_VERIFY_MAX_CONCURRENCY value {convertValue} is too large, clamped to 256. Recommended range: 1 - 128.");
}
// 限制在合理范围内1-256
// 超过 256 的并发数对于文件验证来说没有意义,反而会增加线程池压力
FileVerifyMaxConcurrency = Mathf.Clamp(convertValue, 1, 256);
}
else if (name == FileSystemParametersDefine.APPEND_FILE_EXTENSION)
{
@@ -255,12 +268,22 @@ namespace YooAsset
else if (name == FileSystemParametersDefine.DOWNLOAD_MAX_CONCURRENCY)
{
int convertValue = Convert.ToInt32(value);
DownloadMaxConcurrency = Mathf.Clamp(convertValue, 1, int.MaxValue);
if (convertValue > 64)
{
YooLogger.Warning($"DOWNLOAD_MAX_CONCURRENCY value {convertValue} is too large, clamped to 64. Recommended range: 1 - 32.");
}
DownloadMaxConcurrency = Mathf.Clamp(convertValue, 1, 64);
}
else if (name == FileSystemParametersDefine.DOWNLOAD_MAX_REQUEST_PER_FRAME)
{
int convertValue = Convert.ToInt32(value);
DownloadMaxRequestPerFrame = Mathf.Clamp(convertValue, 1, int.MaxValue);
if (convertValue > 20)
{
YooLogger.Warning($"DOWNLOAD_MAX_REQUEST_PER_FRAME value {convertValue} is too large, clamped to 20. Recommended range: 1 - 10.");
}
DownloadMaxRequestPerFrame = Mathf.Clamp(convertValue, 1, 20);
}
else if (name == FileSystemParametersDefine.DOWNLOAD_WATCH_DOG_TIME)
{
@@ -469,9 +492,7 @@ namespace YooAsset
if (_records.TryGetValue(bundle.BundleGUID, out RecordFileElement element) == false)
return EFileVerifyResult.CacheNotFound;
// 注意:使用清单里的权威校验值(与下载/解压时的校验基准一致),而不是缓存记录里来源于本地 .info 文件的自描述值,
// 否则数据文件与 .info 文件被一并篡改时仍会校验通过。
EFileVerifyResult result = FileVerifyHelper.FileVerify(element.DataFilePath, bundle.FileSize, bundle.FileCRC, EFileVerifyLevel.High);
EFileVerifyResult result = FileVerifyHelper.FileVerify(element.DataFilePath, element.DataFileSize, element.DataFileCRC, EFileVerifyLevel.High);
return result;
}
public bool WriteCacheBundleFile(PackageBundle bundle, string copyPath)

View File

@@ -335,20 +335,10 @@ namespace YooAsset
}
}
else
{
if (_fileSystem.DisableOnDemandDownload)
{
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = $"The bundle not cached : {_bundle.BundleName}";
YooLogger.Warning(Error);
}
else
{
_steps = ESteps.DownloadFile;
}
}
}
if (_steps == ESteps.DownloadFile)
{

View File

@@ -95,8 +95,7 @@ namespace YooAsset
}
else
{
// 注意:本地文件(解压/导入)校验失败属于确定性失败,重试只会重复读取同一文件,直接判定失败防止无限重试。
if (IsWaitForAsyncComplete == false && _failedTryAgain > 0 && _unityDownloadFileOp.VerifyFailed == false)
if (IsWaitForAsyncComplete == false && _failedTryAgain > 0)
{
_steps = ESteps.TryAgain;
YooLogger.Warning($"Failed download : {_unityDownloadFileOp.URL} Try again !");

View File

@@ -27,12 +27,6 @@ namespace YooAsset
/// </summary>
public int RefCount { private set; get; }
/// <summary>
/// 文件校验是否失败
/// 注意:本地文件(解压/导入)校验失败属于确定性失败,重试无意义,上层不应重试。
/// </summary>
public bool VerifyFailed { protected set; get; } = false;
internal UnityDownloadFileOperation(DefaultCacheFileSystem fileSystem, PackageBundle bundle, string url) : base(url)
{
_fileSystem = fileSystem;

View File

@@ -133,8 +133,6 @@ namespace YooAsset
}
else
{
// 注意:本地内置文件被篡改或损坏时校验会失败,重试只会重复读取同一文件,因此标记为不可重试。
VerifyFailed = true;
_steps = ESteps.Done;
Status = EOperationStatus.Failed;
Error = _verifyOperation.Error;

View File

@@ -188,13 +188,21 @@ namespace YooAsset
// 结束记录
DebugEndRecording();
//注意如果完成回调内发生异常会导致Task无限期等待
try
{
_callback?.Invoke(this);
}
catch (Exception ex)
{
YooLogger.Error($"Exception in completion callback: {ex}");
}
finally
{
if (_taskCompletionSource != null)
_taskCompletionSource.TrySetResult(null);
}
}
}
/// <summary>
/// 终止异步任务

View File

@@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace YooAsset
@@ -25,7 +24,6 @@ namespace YooAsset
CheckOptions,
ReleaseAll,
TryAbortLoader,
RequestForceDestroy,
CheckLoading,
DestroyAll,
Done,
@@ -74,10 +72,7 @@ namespace YooAsset
// 释放所有资源句柄
if (_options.ReleaseAllHandles)
{
// 注意创建快照因为释放句柄可能触发自动卸载逻辑AutoUnloadBundleWhenUnused
// 进而修改 ProviderDic 容器,导致遍历时抛出 InvalidOperationException。
var snapshot = new List<ProviderOperation>(_resManager.ProviderDic.Values);
foreach (var provider in snapshot)
foreach (var provider in _resManager.ProviderDic.Values)
{
provider.ReleaseAllHandles();
}
@@ -94,17 +89,6 @@ namespace YooAsset
{
loader.TryAbortLoader();
}
_steps = ESteps.RequestForceDestroy;
}
if (_steps == ESteps.RequestForceDestroy)
{
// 向所有资源提供者下发强制销毁请求
// 注意:防止零引用且尚未进入加载阶段的任务被无限挂起,从而导致 CheckLoading 死锁。
foreach (var provider in _resManager.ProviderDic.Values)
{
provider.RequestForceDestroy();
}
_steps = ESteps.CheckLoading;
}

View File

@@ -67,11 +67,6 @@ namespace YooAsset
/// </summary>
public bool IsDestroyed { private set; get; } = false;
/// <summary>
/// 是否已收到强制销毁请求
/// </summary>
public bool ForceDestroyRequested { private set; get; } = false;
/// <summary>
/// 加载任务是否进行中
/// </summary>
@@ -124,18 +119,6 @@ namespace YooAsset
if (_steps == ESteps.None || _steps == ESteps.Done)
return;
// 注意:收到强制销毁请求时,未在加载中的任务立即结束,防止零引用任务被无限挂起导致卸载流程死锁!
if (ForceDestroyRequested)
{
if (IsLoading == false)
{
InvokeCompletion("Provider force destroyed during unload all assets !", EOperationStatus.Failed);
return;
}
// 注意:已进入加载阶段则继续等待自然完成
}
// 注意:未在加载中的任务可以挂起!
if (IsLoading == false)
{
@@ -216,24 +199,11 @@ namespace YooAsset
}
protected abstract void ProcessBundleResult();
/// <summary>
/// 请求强制销毁
/// 注意:用于卸载流程,标记后未在加载中的任务会在下一次更新时立即结束。
/// </summary>
public void RequestForceDestroy()
{
ForceDestroyRequested = true;
}
/// <summary>
/// 销毁资源提供者
/// 注意:该方法是幂等的,重复调用不会重复释放资源。
/// </summary>
public void DestroyProvider()
{
if (IsDestroyed)
return;
IsDestroyed = true;
// 检测是否为正常销毁
@@ -299,6 +269,7 @@ namespace YooAsset
if (_resManager.UseWeakReferenceHandle)
{
// TODO 高危风险:如果移除弱引用失败,会导致资源永远无法释放。
if (RemoveWeakReference(handle) == false)
throw new System.Exception("Should never get here !");
}
@@ -365,11 +336,18 @@ namespace YooAsset
List<WeakReference<HandleBase>> tempers = _weakReferences.ToList();
foreach (var weakRef in tempers)
{
if (weakRef.TryGetTarget(out HandleBase target))
if (weakRef.TryGetTarget(out HandleBase handle))
{
if (target.IsValid)
if (handle.IsValid)
{
target.InvokeCallback();
try
{
handle.InvokeCallback();
}
catch (Exception ex)
{
YooLogger.Error($"Exception in completion callback: {ex}");
}
}
}
}
@@ -380,9 +358,16 @@ namespace YooAsset
foreach (var handle in tempers)
{
if (handle.IsValid)
{
try
{
handle.InvokeCallback();
}
catch (Exception ex)
{
YooLogger.Error($"Exception in completion callback: {ex}");
}
}
}
}
}

View File

@@ -264,12 +264,10 @@ namespace YooAsset
manifest.AssetList.Add(packageAsset);
// 注意:我们不允许原始路径存在重名
// 说明:清单是构建期生成的可信数据,重名只会因构建错误产生,仅在开发期校验即可,发行版省去一次哈希查找。
string assetPath = packageAsset.AssetPath;
#if UNITY_EDITOR || DEBUG
if (manifest.AssetDic.ContainsKey(assetPath))
throw new System.Exception($"AssetPath have existed : {assetPath}");
#endif
else
manifest.AssetDic.Add(assetPath, packageAsset);
// 填充AssetPathMapping1
@@ -277,14 +275,12 @@ namespace YooAsset
string location = packageAsset.AssetPath;
// 添加原生路径的映射
#if UNITY_EDITOR || DEBUG
if (manifest.AssetPathMapping1.ContainsKey(location))
throw new System.Exception($"Location have existed : {location}");
#endif
else
manifest.AssetPathMapping1.Add(location, packageAsset.AssetPath);
// 添加无后缀名路径的映射
// 注意:无后缀名重名属于合法运行时情况(仅警告并跳过),因此该校验必须在发行版也执行。
if (manifest.SupportExtensionless)
{
string locationWithoutExtension = Path.ChangeExtension(location, null);
@@ -301,10 +297,9 @@ namespace YooAsset
// 填充AssetPathMapping2
if (manifest.IncludeAssetGUID)
{
#if UNITY_EDITOR || DEBUG
if (manifest.AssetPathMapping2.ContainsKey(packageAsset.AssetGUID))
throw new System.Exception($"AssetGUID have existed : {packageAsset.AssetGUID}");
#endif
else
manifest.AssetPathMapping2.Add(packageAsset.AssetGUID, packageAsset.AssetPath);
}
@@ -314,10 +309,9 @@ namespace YooAsset
string location = packageAsset.Address;
if (string.IsNullOrEmpty(location) == false)
{
#if UNITY_EDITOR || DEBUG
if (manifest.AssetPathMapping1.ContainsKey(location))
throw new System.Exception($"Location have existed : {location}");
#endif
else
manifest.AssetPathMapping1.Add(location, packageAsset.AssetPath);
}
}

View File

@@ -1,7 +1,7 @@
{
"name": "com.tuyoogame.yooasset",
"displayName": "YooAsset",
"version": "2.3.19",
"version": "2.3.18",
"unity": "2019.4",
"description": "unity3d resources management system.",
"author": {

View File

@@ -187,7 +187,7 @@
identification within third-party archives.
Copyright 2018-2021 何冠峰
Copyright 2021-2026 TuYoo Games
Copyright 2021-2025 TuYoo Games
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.