mirror of
https://github.com/tuyoogame/YooAsset.git
synced 2026-05-28 19:48:47 +00:00
Compare commits
105 Commits
2.3.13
...
c87efdb509
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c87efdb509 | ||
|
|
1884fab0c2 | ||
|
|
e5d0a856a5 | ||
|
|
5da8c6baf8 | ||
|
|
33356cb270 | ||
|
|
4b6a8ca406 | ||
|
|
c8e45a6cae | ||
|
|
1fbc9d26a6 | ||
|
|
abb087b02e | ||
|
|
aeaf03011f | ||
|
|
78d24ad3a6 | ||
|
|
aab2c4625e | ||
|
|
079ef75605 | ||
|
|
75881b55f6 | ||
|
|
2020c7d508 | ||
|
|
088d939346 | ||
|
|
fa50e91c9f | ||
|
|
2e7b992a4b | ||
|
|
29fbbd97ff | ||
|
|
abb150e33f | ||
|
|
78e20f434e | ||
|
|
304222b788 | ||
|
|
101236db8a | ||
|
|
37de007b3f | ||
|
|
d570ba8d74 | ||
|
|
2a956099ae | ||
|
|
74037a5a29 | ||
|
|
861f850a32 | ||
|
|
8b1b5f988a | ||
|
|
efafd1173f | ||
|
|
03e49ff1fb | ||
|
|
ea34be1f00 | ||
|
|
831a9981e3 | ||
|
|
9de4aaa658 | ||
|
|
3579a23bd5 | ||
|
|
c865ddc7f2 | ||
|
|
0bde506aec | ||
|
|
15005b3d30 | ||
|
|
4caf733ac6 | ||
|
|
014b17f5cb | ||
|
|
f3ebda0c04 | ||
|
|
5602addaca | ||
|
|
c4ae67aa8e | ||
|
|
bbcc3bf971 | ||
|
|
8b0e75b9b3 | ||
|
|
b1f02049cc | ||
|
|
512886cdf6 | ||
|
|
0c3ccc5c2f | ||
|
|
b0ea03170f | ||
|
|
2c3b890329 | ||
|
|
0f39cb9444 | ||
|
|
8acc16d3f6 | ||
|
|
fd1715a89b | ||
|
|
0934c813d1 | ||
|
|
be71d38cd8 | ||
|
|
4cdfde31da | ||
|
|
0133549ef8 | ||
|
|
81d9eb47c8 | ||
|
|
5fde689f1f | ||
|
|
5d51bfe751 | ||
|
|
ed86edd2b0 | ||
|
|
f627b5b59a | ||
|
|
549ec74519 | ||
|
|
247ee31348 | ||
|
|
90d3a53bc3 | ||
|
|
19f1d67a61 | ||
|
|
a71c46d1c4 | ||
|
|
82d7bc8fef | ||
|
|
cc85099253 | ||
|
|
d392b02bd4 | ||
|
|
a5138b9846 | ||
|
|
e1b6458c26 | ||
|
|
0f73dc3047 | ||
|
|
a85e49c22a | ||
|
|
6b291de922 | ||
|
|
a4b1300195 | ||
|
|
6f34951a74 | ||
|
|
c798250258 | ||
|
|
6fc82bb55a | ||
|
|
c22cf5ffeb | ||
|
|
36bc24f9fd | ||
|
|
addb0ecdfe | ||
|
|
89e23e0df8 | ||
|
|
e2f582834e | ||
|
|
d2c2844f61 | ||
|
|
1de64278ad | ||
|
|
227f2332a9 | ||
|
|
131614687c | ||
|
|
b8ec902f60 | ||
|
|
eb3e29b6ad | ||
|
|
11ed9d391a | ||
|
|
9cd50bc7f3 | ||
|
|
e92505ba88 | ||
|
|
06a670730c | ||
|
|
ccd21e56cb | ||
|
|
522bcc529a | ||
|
|
2254ac9f5e | ||
|
|
956b3db71d | ||
|
|
fb56959c61 | ||
|
|
b9b9f4e37d | ||
|
|
c050d6d172 | ||
|
|
baf76a454b | ||
|
|
385d343262 | ||
|
|
1f5ad24d44 | ||
|
|
fefc0043cf |
@@ -2,7 +2,298 @@
|
||||
|
||||
All notable changes to this package will be documented in this file.
|
||||
|
||||
## [2.3.13] - 2025-07-23
|
||||
## [2.3.18] - 2025-12-04
|
||||
|
||||
### Fixed
|
||||
|
||||
- (#676) 修复了UniTask扩展包的编译报错。
|
||||
- (#684) 修复了资源配置窗口Group列表数量过多的时候,添加和删除按钮会变小的问题。
|
||||
- (#700) [**严重**] 修复了小游戏扩展库的下载器再失败后重试逻辑不起效的问题。
|
||||
|
||||
### Added
|
||||
|
||||
- (#683) 新增了内置文件系统类初始化参数:UNPACK_FILE_SYSTEM_ROOT
|
||||
|
||||
```csharp
|
||||
class FileSystemParametersDefine
|
||||
{
|
||||
// 指定解压文件的根目录
|
||||
public const string UNPACK_FILE_SYSTEM_ROOT = "UNPACK_FILE_SYSTEM_ROOT";
|
||||
}
|
||||
```
|
||||
|
||||
- (#682) 原生文件构建管线新增构建参数:IncludePathInHash
|
||||
|
||||
```csharp
|
||||
class RawFileBuildParameters : BuildParameters
|
||||
{
|
||||
/// <summary>
|
||||
/// 文件哈希值计算包含路径信息
|
||||
/// </summary>
|
||||
public bool IncludePathInHash = false;
|
||||
}
|
||||
```
|
||||
|
||||
- (#671) 新增扩展工具,可以生成空的包裹内置资源目录文件。
|
||||
|
||||
```csharp
|
||||
public class CreateEmptyCatalogWindow : EditorWindow
|
||||
```
|
||||
|
||||
- (#694) 新增资源清理方式:ClearBundleFilesByLocations
|
||||
|
||||
```csharp
|
||||
public enum EFileClearMode
|
||||
{
|
||||
/// <summary>
|
||||
/// 清理指定地址的文件
|
||||
/// 说明:需要指定参数,可选:string, string[], List<string>
|
||||
/// </summary>
|
||||
ClearBundleFilesByLocations,
|
||||
}
|
||||
```
|
||||
|
||||
## [2.3.17] - 2025-10-30
|
||||
|
||||
**非常重要**:修复了#627优化导致的资源清单CRC值为空的问题。
|
||||
|
||||
该问题会导致下载的损坏文件验证通过。
|
||||
|
||||
影响范围:v2.3.15版本,v2.3.16版本。
|
||||
|
||||
**非常重要**:(#661) 修复了Package销毁过程中,遇到正在加载的AssetBundle会导致无法卸载的问题。
|
||||
|
||||
该问题是偶现,引擎会提示AssetBundle已经加载,无法加载新的文件,导致资源对象加载失败!
|
||||
|
||||
影响范围:所有版本!
|
||||
|
||||
### Fixed
|
||||
|
||||
- (#645) 修复了着色器变种收集工具,在极端情况下变种收集不完整的问题。
|
||||
- (#646) 修复了EditorSimulateMode模式下开启模拟下载tag不生效的问题。
|
||||
- (#667) 修复了所有编辑器窗口针对中文IME的输入问题。
|
||||
- (#670) 修复了Catalog文件生成过程中白名单未考虑自定义清单前缀名。
|
||||
|
||||
### Improvements
|
||||
|
||||
- 重构并统一了资源清单的反序列化逻辑。
|
||||
- (#650) 解决互相依赖的资源包无法卸载的问题。需要开启宏定义:YOOASSET_EXPERIMENTAL
|
||||
- (#655) 优化了初始化的时候,缓存文件搜索效率。安卓平台性能提升1倍,IOS平台性能提升3倍。
|
||||
|
||||
### Added
|
||||
|
||||
- (#643) 新增构建参数,可以节省资源清单运行时内存
|
||||
|
||||
```csharp
|
||||
class ScriptableBuildParameters
|
||||
{
|
||||
/// <summary>
|
||||
/// 使用可寻址地址代替资源路径
|
||||
/// 说明:开启此项可以节省运行时清单占用的内存!
|
||||
/// </summary>
|
||||
public bool ReplaceAssetPathWithAddress = false;
|
||||
}
|
||||
```
|
||||
|
||||
- (#648) 新增初始化参数,可以自动释放引用计数为零的资源包
|
||||
|
||||
```csharp
|
||||
class InitializeParameters
|
||||
{
|
||||
/// <summary>
|
||||
/// 当资源引用计数为零的时候自动释放资源包
|
||||
/// </summary>
|
||||
public bool AutoUnloadBundleWhenUnused = false;
|
||||
}
|
||||
```
|
||||
|
||||
### Changed
|
||||
|
||||
- 程序集宏定义代码转移到扩展工程。参考MacroSupport文件夹。
|
||||
|
||||
## [2.3.16] - 2025-09-17
|
||||
|
||||
### Improvements
|
||||
|
||||
- (#638) 优化了Provider加载机制,引用计数为零时自动挂起!
|
||||
|
||||
### Fixed
|
||||
|
||||
- (#644) [**严重**] 修复了2.3.15版本,资产量巨大的情况下,编辑器下模拟模式初始化耗时很久的问题。
|
||||
|
||||
### Added
|
||||
|
||||
- (#639) 新增了文件系统参数:VIRTUAL_DOWNLOAD_MODE 和 VIRTUAL_DOWNLOAD_SPEED
|
||||
|
||||
编辑器下不需要构建AB,也可以模拟远端资源下载,等同真机运行环境。
|
||||
|
||||
```csharp
|
||||
class DefaultEditorFIleSystem
|
||||
{
|
||||
/// <summary>
|
||||
/// 模拟虚拟下载模式
|
||||
/// </summary>
|
||||
public bool VirtualDownloadMode { private set; get; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// 模拟虚拟下载的网速(单位:字节)
|
||||
/// </summary>
|
||||
public int VirtualDownloadSpeed { private set; get; } = 1024;
|
||||
}
|
||||
```
|
||||
|
||||
- (#640) 新增了文件系统参数:VIRTUAL_WEBGL_MODE
|
||||
|
||||
编辑器下不需要构建AB,也可以模拟小游戏开发环境,等同真机运行环境。
|
||||
|
||||
```csharp
|
||||
class DefaultEditorFIleSystem
|
||||
{
|
||||
/// <summary>
|
||||
/// 模拟WebGL平台模式
|
||||
/// </summary>
|
||||
public bool VirtualWebGLMode { private set; get; } = false;
|
||||
}
|
||||
```
|
||||
|
||||
- (#642) 新增了文件系统参数:DOWNLOAD_WATCH_DOG_TIME
|
||||
|
||||
监控时间范围内,如果没有接收到任何下载数据,那么直接终止任务!
|
||||
|
||||
```csharp
|
||||
class DefaultCacheFIleSystem
|
||||
{
|
||||
/// <summary>
|
||||
/// 自定义参数:下载任务的看门狗机制监控时间
|
||||
/// </summary>
|
||||
public int DownloadWatchDogTime { private set; get; } = int.MaxValue;
|
||||
}
|
||||
```
|
||||
|
||||
### Changed
|
||||
|
||||
- 下载器参数timeout移除。
|
||||
|
||||
可以使用文件系统的看门狗机制代替。
|
||||
|
||||
- (#632) IFilterRule接口变动。
|
||||
|
||||
收集器可以指定搜寻的资源类型,在收集目录资产量巨大的情况下,可以极大加快打包速度!
|
||||
|
||||
```csharp
|
||||
public interface IFilterRule
|
||||
{
|
||||
/// <summary>
|
||||
/// 搜寻的资源类型
|
||||
/// 说明:使用引擎方法搜索获取所有资源列表
|
||||
/// </summary>
|
||||
string FindAssetType { get; }
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
## [2.3.15] - 2025-09-09
|
||||
|
||||
**重要**:升级了资源清单版本,不兼容老版本。建议重新提审安装包。
|
||||
|
||||
### Improvements
|
||||
|
||||
- 重构了UniTask扩展库的目录结构和说明文档。
|
||||
- 重构了内置文件系统类的加载和拷贝逻辑,解决在一些特殊机型上遇到的偶发性拷贝失败问题。
|
||||
- 增加了生成内置清单文件的窗口工具,详情见扩展工程里CreateBuildinCatalog目录。
|
||||
- 优化了异步操作系统的繁忙检测机制。
|
||||
- (#621) 资源配置页面可以展示DependCollector和StaticCollector包含的文件列表内容。
|
||||
- (#627) 优化了资源清单部分字段类型,CRC字段从字符串类型调整为整形,可以降低清单尺寸。
|
||||
|
||||
### Fixed
|
||||
|
||||
- 修复了构建页面扩展类缺少指定属性报错的问题。
|
||||
- (#611) 修复了资源扫描器配置页面,修改备注信息后会丢失焦点的问题。
|
||||
- (#622) 修复了纯鸿蒙系统读取内置加密文件失败的问题。
|
||||
- (#620) 修复了LINUX系统URL地址转换失败的问题。
|
||||
- (#631) 修复了NET 4.x程序集库Math.Clamp导致的编译错误。
|
||||
|
||||
### Added
|
||||
|
||||
- 新增了支持支付宝小游戏的文件系统扩展类。
|
||||
|
||||
- 新增了支持Taptap小游戏的文件系统扩展类。
|
||||
|
||||
- 新增了资源系统初始化参数:UseWeakReferenceHandle
|
||||
|
||||
目前处于预览版,可以在引擎设置页面开启宏:YOOASSET_EXPERIMENTAL
|
||||
|
||||
```csharp
|
||||
/// <summary>
|
||||
/// 启用弱引用资源句柄
|
||||
/// </summary>
|
||||
public bool UseWeakReferenceHandle = false;
|
||||
```
|
||||
|
||||
- 内置文件系统和缓存文件系统新增初始化参数:FILE_VERIFY_MAX_CONCURRENCY
|
||||
|
||||
```csharp
|
||||
/// <summary>
|
||||
/// 自定义参数:初始化的时候缓存文件校验最大并发数
|
||||
/// </summary>
|
||||
public int FileVerifyMaxConcurrency { private set; get; }
|
||||
```
|
||||
|
||||
- (#623) 内置构建管线新增构建参数:StripUnityVersion
|
||||
|
||||
```csharp
|
||||
/// <summary>
|
||||
/// 从文件头里剥离Unity版本信息
|
||||
/// </summary>
|
||||
public bool StripUnityVersion = false;
|
||||
```
|
||||
|
||||
- 可编程构建管线新增构建参数:TrackSpriteAtlasDependencies
|
||||
|
||||
```csharp
|
||||
/// <summary>
|
||||
/// 自动建立资源对象对图集的依赖关系
|
||||
/// </summary>
|
||||
public bool TrackSpriteAtlasDependencies = false;
|
||||
```
|
||||
|
||||
- (#617) 新增资源收集配置参数:SupportExtensionless
|
||||
|
||||
在不需要模糊加载模式的前提下,关闭此选项,可以降低运行时内存大小。
|
||||
|
||||
该选项默认开启!
|
||||
|
||||
```csharp
|
||||
public class CollectCommand
|
||||
{
|
||||
/// <summary>
|
||||
/// 支持无后缀名的资源定位地址
|
||||
/// </summary>
|
||||
public bool SupportExtensionless { set; get; }
|
||||
}
|
||||
```
|
||||
|
||||
- (#625) 异步操作系统类新增监听方法。
|
||||
|
||||
```csharp
|
||||
class OperationSystem
|
||||
{
|
||||
/// <summary>
|
||||
/// 监听任务开始
|
||||
/// </summary>
|
||||
public static void RegisterStartCallback(Action<string, AsyncOperationBase> callback);
|
||||
|
||||
/// <summary>
|
||||
/// 监听任务结束
|
||||
/// </summary>
|
||||
public static void RegisterFinishCallback(Action<string, AsyncOperationBase> callback);
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
|
||||
## [2.3.14] - 2025-07-23
|
||||
|
||||
**重要**:**所有下载相关的超时参数(timeout)已更新判定逻辑**
|
||||
|
||||
|
||||
@@ -261,14 +261,14 @@ namespace YooAsset.Editor
|
||||
catch (System.Exception e)
|
||||
{
|
||||
_reportCombiner = null;
|
||||
_titleLabel.text = "导入报告失败!";
|
||||
_titleLabel.text = "Failed to import report!";
|
||||
_descLabel.text = e.Message;
|
||||
UnityEngine.Debug.LogError(e.StackTrace);
|
||||
}
|
||||
}
|
||||
private void FixAllBtn_clicked()
|
||||
{
|
||||
if (EditorUtility.DisplayDialog("提示", "修复全部资源(排除白名单和隐藏元素)", "Yes", "No"))
|
||||
if (EditorUtility.DisplayDialog("Info", "Fix all resources (excluding whitelist and hidden elements)", "Yes", "No"))
|
||||
{
|
||||
if (_reportCombiner != null)
|
||||
_reportCombiner.FixAll();
|
||||
@@ -276,7 +276,7 @@ namespace YooAsset.Editor
|
||||
}
|
||||
private void FixSelectBtn_clicked()
|
||||
{
|
||||
if (EditorUtility.DisplayDialog("提示", "修复勾选资源(包含白名单和隐藏元素)", "Yes", "No"))
|
||||
if (EditorUtility.DisplayDialog("Info", "Fix selected resources (including whitelist and hidden elements)", "Yes", "No"))
|
||||
{
|
||||
if (_reportCombiner != null)
|
||||
_reportCombiner.FixSelect();
|
||||
@@ -302,7 +302,7 @@ namespace YooAsset.Editor
|
||||
}
|
||||
private void ExportFilesBtn_clicked()
|
||||
{
|
||||
string selectFolderPath = EditorUtility.OpenFolderPanel("导入所有选中资源", EditorTools.GetProjectPath(), string.Empty);
|
||||
string selectFolderPath = EditorUtility.OpenFolderPanel("Export all selected resources", EditorTools.GetProjectPath(), string.Empty);
|
||||
if (string.IsNullOrEmpty(selectFolderPath) == false)
|
||||
{
|
||||
if (_reportCombiner != null)
|
||||
|
||||
@@ -32,21 +32,14 @@ namespace YooAsset.Editor
|
||||
|
||||
// 开始扫描工作
|
||||
ScanReport report = scanner.RunScanner();
|
||||
|
||||
// 检测报告合法性
|
||||
report.CheckError();
|
||||
|
||||
// 保存扫描结果
|
||||
string saveDirectory = scanner.SaveDirectory;
|
||||
if (string.IsNullOrEmpty(saveDirectory))
|
||||
saveDirectory = "Assets/";
|
||||
string filePath = $"{saveDirectory}/{scanner.ScannerName}_{scanner.ScannerDesc}.json";
|
||||
ScanReportConfig.ExportJsonConfig(filePath, report);
|
||||
return new ScannerResult(filePath, report);
|
||||
// 返回扫描结果
|
||||
return new ScannerResult(report);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return new ScannerResult(e.StackTrace);
|
||||
return new ScannerResult(e.Message, e.StackTrace);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -240,7 +240,7 @@ namespace YooAsset.Editor
|
||||
}
|
||||
private void ScanAllBtn_clicked()
|
||||
{
|
||||
if (EditorUtility.DisplayDialog("提示", $"开始全面扫描!", "Yes", "No"))
|
||||
if (EditorUtility.DisplayDialog("Info", $"Start full scan!", "Yes", "No"))
|
||||
{
|
||||
string searchKeyWord = _scannerSearchField.value;
|
||||
AssetArtScannerSettingData.ScanAll(searchKeyWord);
|
||||
@@ -248,7 +248,7 @@ namespace YooAsset.Editor
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning("全面扫描已经取消");
|
||||
Debug.LogWarning("Full scan has been canceled.");
|
||||
}
|
||||
}
|
||||
private void ScanBtn_clicked()
|
||||
@@ -294,6 +294,11 @@ namespace YooAsset.Editor
|
||||
_scannerListView.itemsSource = filterItems;
|
||||
_scannerListView.Rebuild();
|
||||
}
|
||||
|
||||
if (_lastModifyScannerIndex >= 0 && _lastModifyScannerIndex < _scannerListView.itemsSource.Count)
|
||||
{
|
||||
_scannerListView.selectedIndex = _lastModifyScannerIndex;
|
||||
}
|
||||
}
|
||||
private List<AssetArtScanner> FilterScanners()
|
||||
{
|
||||
|
||||
@@ -3,11 +3,6 @@ namespace YooAsset.Editor
|
||||
{
|
||||
public class ScannerResult
|
||||
{
|
||||
/// <summary>
|
||||
/// 生成的报告文件路径
|
||||
/// </summary>
|
||||
public string ReprotFilePath { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 报告对象
|
||||
/// </summary>
|
||||
@@ -18,6 +13,11 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
public string ErrorInfo { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 错误堆栈
|
||||
/// </summary>
|
||||
public string ErrorStack { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否成功
|
||||
/// </summary>
|
||||
@@ -33,15 +33,14 @@ namespace YooAsset.Editor
|
||||
}
|
||||
|
||||
|
||||
public ScannerResult(string error)
|
||||
public ScannerResult(string error, string stack)
|
||||
{
|
||||
ErrorInfo = error;
|
||||
ErrorStack = stack;
|
||||
}
|
||||
public ScannerResult(string filePath, ScanReport report)
|
||||
public ScannerResult(ScanReport report)
|
||||
{
|
||||
ReprotFilePath = filePath;
|
||||
Report = report;
|
||||
ErrorInfo = string.Empty;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -55,5 +54,19 @@ namespace YooAsset.Editor
|
||||
reproterWindow.ImportSingleReprotFile(Report);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 保存报告文件
|
||||
/// </summary>
|
||||
public void SaveReportFile(string saveDirectory)
|
||||
{
|
||||
if (Report == null)
|
||||
throw new System.Exception("Scan report is invalid !");
|
||||
|
||||
if (string.IsNullOrEmpty(saveDirectory))
|
||||
saveDirectory = "Assets/";
|
||||
string filePath = $"{saveDirectory}/{Report.ReportName}_{Report.ReportDesc}.json";
|
||||
ScanReportConfig.ExportJsonConfig(filePath, Report);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -77,6 +77,12 @@ namespace YooAsset.Editor
|
||||
foreach (var classType in viewerClassTypes)
|
||||
{
|
||||
var buildPipelineAttribute = EditorTools.GetAttribute<BuildPipelineAttribute>(classType);
|
||||
if (buildPipelineAttribute == null)
|
||||
{
|
||||
Debug.LogWarning($"The class {classType.FullName} need attribute {nameof(BuildPipelineAttribute)}");
|
||||
continue;
|
||||
}
|
||||
|
||||
string pipelineName = buildPipelineAttribute.PipelineName;
|
||||
if (_viewClassDic.ContainsKey(pipelineName))
|
||||
{
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace YooAsset.Editor
|
||||
/// <summary>
|
||||
/// 文件哈希值
|
||||
/// </summary>
|
||||
public string PackageFileCRC { set; get; }
|
||||
public uint PackageFileCRC { set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 文件哈希值
|
||||
@@ -106,7 +106,27 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
public string[] GetAllPackAssetPaths()
|
||||
{
|
||||
return AllPackAssets.Select(t => t.AssetInfo.AssetPath).ToArray();
|
||||
List<string> results = new List<string>(AllPackAssets.Count);
|
||||
for (int i = 0; i < AllPackAssets.Count; i++)
|
||||
{
|
||||
var packAsset = AllPackAssets[i];
|
||||
results.Add(packAsset.AssetInfo.AssetPath);
|
||||
}
|
||||
return results.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取构建的资源可寻址列表
|
||||
/// </summary>
|
||||
public string[] GetAllPackAssetAddress()
|
||||
{
|
||||
List<string> results = new List<string>(AllPackAssets.Count);
|
||||
for (int i = 0; i < AllPackAssets.Count; i++)
|
||||
{
|
||||
var packAsset = AllPackAssets[i];
|
||||
results.Add(packAsset.Address);
|
||||
}
|
||||
return results.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -153,13 +173,15 @@ namespace YooAsset.Editor
|
||||
/// <summary>
|
||||
/// 创建AssetBundleBuild类
|
||||
/// </summary>
|
||||
public UnityEditor.AssetBundleBuild CreatePipelineBuild()
|
||||
public UnityEditor.AssetBundleBuild CreatePipelineBuild(bool replaceAssetPathWithAddress)
|
||||
{
|
||||
// 注意:我们不再支持AssetBundle的变种机制
|
||||
AssetBundleBuild build = new AssetBundleBuild();
|
||||
build.assetBundleName = BundleName;
|
||||
build.assetBundleVariant = string.Empty;
|
||||
build.assetNames = GetAllPackAssetPaths();
|
||||
if (replaceAssetPathWithAddress)
|
||||
build.addressableNames = GetAllPackAssetAddress();
|
||||
return build;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,11 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
private readonly Dictionary<string, BuildBundleInfo> _bundleInfoDic = new Dictionary<string, BuildBundleInfo>(10000);
|
||||
|
||||
/// <summary>
|
||||
/// 图集资源集合
|
||||
/// </summary>
|
||||
public readonly List<BuildAssetInfo> SpriteAtlasAssetList = new List<BuildAssetInfo>(10000);
|
||||
|
||||
/// <summary>
|
||||
/// 未被依赖的资源列表
|
||||
/// </summary>
|
||||
@@ -60,6 +65,12 @@ namespace YooAsset.Editor
|
||||
newBundleInfo.PackAsset(assetInfo);
|
||||
_bundleInfoDic.Add(bundleName, newBundleInfo);
|
||||
}
|
||||
|
||||
// 统计所有的精灵图集
|
||||
if (assetInfo.AssetInfo.IsSpriteAtlas())
|
||||
{
|
||||
SpriteAtlasAssetList.Add(assetInfo);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -85,12 +96,12 @@ namespace YooAsset.Editor
|
||||
/// <summary>
|
||||
/// 获取构建管线里需要的数据
|
||||
/// </summary>
|
||||
public UnityEditor.AssetBundleBuild[] GetPipelineBuilds()
|
||||
public UnityEditor.AssetBundleBuild[] GetPipelineBuilds(bool replaceAssetPathWithAddres)
|
||||
{
|
||||
List<UnityEditor.AssetBundleBuild> builds = new List<UnityEditor.AssetBundleBuild>(_bundleInfoDic.Count);
|
||||
foreach (var bundleInfo in _bundleInfoDic.Values)
|
||||
{
|
||||
builds.Add(bundleInfo.CreatePipelineBuild());
|
||||
builds.Add(bundleInfo.CreatePipelineBuild(replaceAssetPathWithAddres));
|
||||
}
|
||||
return builds.ToArray();
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Linq;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
@@ -18,7 +19,7 @@ namespace YooAsset.Editor
|
||||
/// <summary>
|
||||
/// 创建补丁清单文件到输出目录
|
||||
/// </summary>
|
||||
protected void CreateManifestFile(bool processBundleDepends, bool processBundleTags, BuildContext context)
|
||||
protected void CreateManifestFile(bool processBundleDepends, bool processBundleTags, bool replaceAssetPathWithAddress, BuildContext context)
|
||||
{
|
||||
var buildMapContext = context.GetContextObject<BuildMapContext>();
|
||||
var buildParametersContext = context.GetContextObject<BuildParametersContext>();
|
||||
@@ -32,8 +33,10 @@ namespace YooAsset.Editor
|
||||
PackageManifest manifest = new PackageManifest();
|
||||
manifest.FileVersion = ManifestDefine.FileVersion;
|
||||
manifest.EnableAddressable = buildMapContext.Command.EnableAddressable;
|
||||
manifest.SupportExtensionless = buildMapContext.Command.SupportExtensionless;
|
||||
manifest.LocationToLower = buildMapContext.Command.LocationToLower;
|
||||
manifest.IncludeAssetGUID = buildMapContext.Command.IncludeAssetGUID;
|
||||
manifest.ReplaceAssetPathWithAddress = replaceAssetPathWithAddress;
|
||||
manifest.OutputNameStyle = (int)buildParameters.FileNameStyle;
|
||||
manifest.BuildBundleType = buildParameters.BuildBundleType;
|
||||
manifest.BuildPipeline = buildParameters.BuildPipeline;
|
||||
@@ -56,7 +59,13 @@ namespace YooAsset.Editor
|
||||
|
||||
// 4. 处理内置资源包
|
||||
if (processBundleDepends)
|
||||
{
|
||||
// 注意:初始化资源清单建立引用关系
|
||||
manifest.Initialize();
|
||||
|
||||
ProcessBuiltinBundleDependency(context, manifest);
|
||||
}
|
||||
|
||||
|
||||
// 创建资源清单文本文件
|
||||
{
|
||||
@@ -303,15 +312,34 @@ namespace YooAsset.Editor
|
||||
// 注意:如果是可编程构建管线,需要补充内置资源包
|
||||
// 注意:该步骤依赖前面的操作!
|
||||
var buildResultContext = context.TryGetContextObject<TaskBuilding_SBP.BuildResultContext>();
|
||||
|
||||
if (buildResultContext != null)
|
||||
{
|
||||
// 注意:初始化资源清单建立引用关系
|
||||
ManifestTools.InitManifest(manifest);
|
||||
ProcessBuiltinBundleReference(context, manifest, buildResultContext.BuiltinShadersBundleName);
|
||||
ProcessBuiltinBundleReference(context, manifest, buildResultContext.MonoScriptsBundleName);
|
||||
ProcessBuiltinBundleReference(manifest, buildResultContext.BuiltinShadersBundleName);
|
||||
ProcessBuiltinBundleReference(manifest, buildResultContext.MonoScriptsBundleName);
|
||||
|
||||
var buildParametersContext = context.TryGetContextObject<BuildParametersContext>();
|
||||
var buildParameters = buildParametersContext.Parameters;
|
||||
if (buildParameters is ScriptableBuildParameters scriptableBuildParameters)
|
||||
{
|
||||
if (scriptableBuildParameters.TrackSpriteAtlasDependencies)
|
||||
{
|
||||
// 注意:检测是否开启图集模式
|
||||
// 说明:需要记录主资源对象对图集的依赖关系!
|
||||
if (EditorSettings.spritePackerMode != SpritePackerMode.Disabled)
|
||||
{
|
||||
var buildMapContext = context.GetContextObject<BuildMapContext>();
|
||||
foreach (var spriteAtlasAsset in buildMapContext.SpriteAtlasAssetList)
|
||||
{
|
||||
string spriteAtlasBundleName = spriteAtlasAsset.BundleName;
|
||||
ProcessBuiltinBundleReference(manifest, spriteAtlasBundleName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private void ProcessBuiltinBundleReference(BuildContext context, PackageManifest manifest, string builtinBundleName)
|
||||
private void ProcessBuiltinBundleReference(PackageManifest manifest, string builtinBundleName)
|
||||
{
|
||||
if (string.IsNullOrEmpty(builtinBundleName))
|
||||
return;
|
||||
|
||||
@@ -32,6 +32,7 @@ namespace YooAsset.Editor
|
||||
// 收集器配置
|
||||
buildReport.Summary.UniqueBundleName = buildMapContext.Command.UniqueBundleName;
|
||||
buildReport.Summary.EnableAddressable = buildMapContext.Command.EnableAddressable;
|
||||
buildReport.Summary.SupportExtensionless = buildMapContext.Command.SupportExtensionless;
|
||||
buildReport.Summary.LocationToLower = buildMapContext.Command.LocationToLower;
|
||||
buildReport.Summary.IncludeAssetGUID = buildMapContext.Command.IncludeAssetGUID;
|
||||
buildReport.Summary.AutoCollectShaders = buildMapContext.Command.AutoCollectShaders;
|
||||
@@ -53,6 +54,7 @@ namespace YooAsset.Editor
|
||||
buildReport.Summary.CompressOption = builtinBuildParameters.CompressOption;
|
||||
buildReport.Summary.DisableWriteTypeTree = builtinBuildParameters.DisableWriteTypeTree;
|
||||
buildReport.Summary.IgnoreTypeTreeChanges = builtinBuildParameters.IgnoreTypeTreeChanges;
|
||||
buildReport.Summary.ReplaceAssetPathWithAddress = builtinBuildParameters.ReplaceAssetPathWithAddress;
|
||||
}
|
||||
else if (buildParameters is ScriptableBuildParameters)
|
||||
{
|
||||
@@ -60,6 +62,7 @@ namespace YooAsset.Editor
|
||||
buildReport.Summary.CompressOption = scriptableBuildParameters.CompressOption;
|
||||
buildReport.Summary.DisableWriteTypeTree = scriptableBuildParameters.DisableWriteTypeTree;
|
||||
buildReport.Summary.IgnoreTypeTreeChanges = scriptableBuildParameters.IgnoreTypeTreeChanges;
|
||||
buildReport.Summary.ReplaceAssetPathWithAddress = scriptableBuildParameters.ReplaceAssetPathWithAddress;
|
||||
buildReport.Summary.WriteLinkXML = scriptableBuildParameters.WriteLinkXML;
|
||||
buildReport.Summary.CacheServerHost = scriptableBuildParameters.CacheServerHost;
|
||||
buildReport.Summary.CacheServerPort = scriptableBuildParameters.CacheServerPort;
|
||||
|
||||
@@ -44,9 +44,9 @@ namespace YooAsset.Editor
|
||||
{
|
||||
bundleInfo.PackageUnityHash = GetUnityHash(bundleInfo, context);
|
||||
bundleInfo.PackageUnityCRC = GetUnityCRC(bundleInfo, context);
|
||||
bundleInfo.PackageFileHash = GetBundleFileHash(bundleInfo, buildParametersContext);
|
||||
bundleInfo.PackageFileCRC = GetBundleFileCRC(bundleInfo, buildParametersContext);
|
||||
bundleInfo.PackageFileSize = GetBundleFileSize(bundleInfo, buildParametersContext);
|
||||
bundleInfo.PackageFileHash = GetBundleFileHash(bundleInfo, context);
|
||||
bundleInfo.PackageFileCRC = GetBundleFileCRC(bundleInfo, context);
|
||||
bundleInfo.PackageFileSize = GetBundleFileSize(bundleInfo, context);
|
||||
}
|
||||
|
||||
// 4.更新补丁包输出的文件路径
|
||||
@@ -62,8 +62,8 @@ namespace YooAsset.Editor
|
||||
|
||||
protected abstract string GetUnityHash(BuildBundleInfo bundleInfo, BuildContext context);
|
||||
protected abstract uint GetUnityCRC(BuildBundleInfo bundleInfo, BuildContext context);
|
||||
protected abstract string GetBundleFileHash(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext);
|
||||
protected abstract string GetBundleFileCRC(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext);
|
||||
protected abstract long GetBundleFileSize(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext);
|
||||
protected abstract string GetBundleFileHash(BuildBundleInfo bundleInfo, BuildContext context);
|
||||
protected abstract uint GetBundleFileCRC(BuildBundleInfo bundleInfo, BuildContext context);
|
||||
protected abstract long GetBundleFileSize(BuildBundleInfo bundleInfo, BuildContext context);
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,8 @@ namespace YooAsset.Editor
|
||||
// 开始构建
|
||||
string pipelineOutputDirectory = buildParametersContext.GetPipelineOutputDirectory();
|
||||
BuildAssetBundleOptions buildOptions = builtinBuildParameters.GetBundleBuildOptions();
|
||||
AssetBundleManifest unityManifest = BuildPipeline.BuildAssetBundles(pipelineOutputDirectory, buildMapContext.GetPipelineBuilds(), buildOptions, buildParametersContext.Parameters.BuildTarget);
|
||||
var bundleBuilds = buildMapContext.GetPipelineBuilds(builtinBuildParameters.ReplaceAssetPathWithAddress);
|
||||
AssetBundleManifest unityManifest = BuildPipeline.BuildAssetBundles(pipelineOutputDirectory, bundleBuilds, buildOptions, buildParametersContext.Parameters.BuildTarget);
|
||||
if (unityManifest == null)
|
||||
{
|
||||
string message = BuildLogger.GetErrorMessage(ErrorCode.UnityEngineBuildFailed, "UnityEngine build failed !");
|
||||
|
||||
@@ -11,7 +11,10 @@ namespace YooAsset.Editor
|
||||
|
||||
void IBuildTask.Run(BuildContext context)
|
||||
{
|
||||
CreateManifestFile(true, true, context);
|
||||
var buildParametersContext = context.GetContextObject<BuildParametersContext>();
|
||||
var builtinBuildParameters = buildParametersContext.Parameters as BuiltinBuildParameters;
|
||||
bool replaceAssetPathWithAddress = builtinBuildParameters.ReplaceAssetPathWithAddress;
|
||||
CreateManifestFile(true, true, replaceAssetPathWithAddress, context);
|
||||
}
|
||||
|
||||
protected override string[] GetBundleDepends(BuildContext context, string bundleName)
|
||||
|
||||
@@ -40,17 +40,17 @@ namespace YooAsset.Editor
|
||||
throw new Exception(message);
|
||||
}
|
||||
}
|
||||
protected override string GetBundleFileHash(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext)
|
||||
protected override string GetBundleFileHash(BuildBundleInfo bundleInfo, BuildContext context)
|
||||
{
|
||||
string filePath = bundleInfo.PackageSourceFilePath;
|
||||
return HashUtility.FileMD5(filePath);
|
||||
}
|
||||
protected override string GetBundleFileCRC(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext)
|
||||
protected override uint GetBundleFileCRC(BuildBundleInfo bundleInfo, BuildContext context)
|
||||
{
|
||||
string filePath = bundleInfo.PackageSourceFilePath;
|
||||
return HashUtility.FileCRC32(filePath);
|
||||
return HashUtility.FileCRC32Value(filePath);
|
||||
}
|
||||
protected override long GetBundleFileSize(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext)
|
||||
protected override long GetBundleFileSize(BuildBundleInfo bundleInfo, BuildContext context)
|
||||
{
|
||||
string filePath = bundleInfo.PackageSourceFilePath;
|
||||
return FileUtility.GetFileSize(filePath);
|
||||
|
||||
@@ -12,6 +12,11 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
public ECompressOption CompressOption = ECompressOption.Uncompressed;
|
||||
|
||||
/// <summary>
|
||||
/// 从文件头里剥离Unity版本信息
|
||||
/// </summary>
|
||||
public bool StripUnityVersion = false;
|
||||
|
||||
/// <summary>
|
||||
/// 禁止写入类型树结构(可以降低包体和内存并提高加载效率)
|
||||
/// </summary>
|
||||
@@ -22,6 +27,12 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
public bool IgnoreTypeTreeChanges = true;
|
||||
|
||||
/// <summary>
|
||||
/// 使用可寻址地址代替资源路径
|
||||
/// 说明:开启此项可以节省运行时清单占用的内存!
|
||||
/// </summary>
|
||||
public bool ReplaceAssetPathWithAddress = false;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取内置构建管线的构建选项
|
||||
@@ -41,6 +52,8 @@ namespace YooAsset.Editor
|
||||
|
||||
if (ClearBuildCacheFiles)
|
||||
opt |= BuildAssetBundleOptions.ForceRebuildAssetBundle; //Force rebuild the asset bundles
|
||||
if (StripUnityVersion)
|
||||
opt |= BuildAssetBundleOptions.AssetBundleStripUnityVersion; //Removes the Unity Version number in the Archive File & Serialized File headers
|
||||
if (DisableWriteTypeTree)
|
||||
opt |= BuildAssetBundleOptions.DisableWriteTypeTree; //Do not include type information within the asset bundle (don't write type tree).
|
||||
if (IgnoreTypeTreeChanges)
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace YooAsset.Editor
|
||||
{
|
||||
void IBuildTask.Run(BuildContext context)
|
||||
{
|
||||
CreateManifestFile(false, false, context);
|
||||
CreateManifestFile(false, true, false, context);
|
||||
}
|
||||
|
||||
protected override string[] GetBundleDepends(BuildContext context, string bundleName)
|
||||
|
||||
@@ -19,16 +19,16 @@ namespace YooAsset.Editor
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
protected override string GetBundleFileHash(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext)
|
||||
protected override string GetBundleFileHash(BuildBundleInfo bundleInfo, BuildContext context)
|
||||
{
|
||||
string filePath = bundleInfo.PackageSourceFilePath;
|
||||
return GetFilePathTempHash(filePath);
|
||||
}
|
||||
protected override string GetBundleFileCRC(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext)
|
||||
protected override uint GetBundleFileCRC(BuildBundleInfo bundleInfo, BuildContext context)
|
||||
{
|
||||
return "00000000"; //8位
|
||||
return 0;
|
||||
}
|
||||
protected override long GetBundleFileSize(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext)
|
||||
protected override long GetBundleFileSize(BuildBundleInfo bundleInfo, BuildContext context)
|
||||
{
|
||||
return GetBundleTempSize(bundleInfo);
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace YooAsset.Editor
|
||||
{
|
||||
void IBuildTask.Run(BuildContext context)
|
||||
{
|
||||
CreateManifestFile(false, true, context);
|
||||
CreateManifestFile(false, true, false, context);
|
||||
}
|
||||
|
||||
protected override string[] GetBundleDepends(BuildContext context, string bundleName)
|
||||
|
||||
@@ -15,27 +15,55 @@ namespace YooAsset.Editor
|
||||
|
||||
protected override string GetUnityHash(BuildBundleInfo bundleInfo, BuildContext context)
|
||||
{
|
||||
string filePath = bundleInfo.PackageSourceFilePath;
|
||||
return HashUtility.FileMD5(filePath);
|
||||
var buildParametersContext = context.GetContextObject<BuildParametersContext>();
|
||||
var rawFileBuildParameters = buildParametersContext.Parameters as RawFileBuildParameters;
|
||||
if (rawFileBuildParameters.IncludePathInHash)
|
||||
{
|
||||
string filePath = bundleInfo.PackageSourceFilePath;
|
||||
return GetFileMD5IncludePath(filePath);
|
||||
}
|
||||
else
|
||||
{
|
||||
string filePath = bundleInfo.PackageSourceFilePath;
|
||||
return HashUtility.FileMD5(filePath);
|
||||
}
|
||||
}
|
||||
protected override uint GetUnityCRC(BuildBundleInfo bundleInfo, BuildContext context)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
protected override string GetBundleFileHash(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext)
|
||||
protected override string GetBundleFileHash(BuildBundleInfo bundleInfo, BuildContext context)
|
||||
{
|
||||
var buildParametersContext = context.GetContextObject<BuildParametersContext>();
|
||||
var rawFileBuildParameters = buildParametersContext.Parameters as RawFileBuildParameters;
|
||||
if (rawFileBuildParameters.IncludePathInHash)
|
||||
{
|
||||
string filePath = bundleInfo.PackageSourceFilePath;
|
||||
return GetFileMD5IncludePath(filePath);
|
||||
}
|
||||
else
|
||||
{
|
||||
string filePath = bundleInfo.PackageSourceFilePath;
|
||||
return HashUtility.FileMD5(filePath);
|
||||
}
|
||||
}
|
||||
protected override uint GetBundleFileCRC(BuildBundleInfo bundleInfo, BuildContext context)
|
||||
{
|
||||
string filePath = bundleInfo.PackageSourceFilePath;
|
||||
return HashUtility.FileMD5(filePath);
|
||||
return HashUtility.FileCRC32Value(filePath);
|
||||
}
|
||||
protected override string GetBundleFileCRC(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext)
|
||||
{
|
||||
string filePath = bundleInfo.PackageSourceFilePath;
|
||||
return HashUtility.FileCRC32(filePath);
|
||||
}
|
||||
protected override long GetBundleFileSize(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext)
|
||||
protected override long GetBundleFileSize(BuildBundleInfo bundleInfo, BuildContext context)
|
||||
{
|
||||
string filePath = bundleInfo.PackageSourceFilePath;
|
||||
return FileUtility.GetFileSize(filePath);
|
||||
}
|
||||
|
||||
private string GetFileMD5IncludePath(string filePath)
|
||||
{
|
||||
string pathHash = HashUtility.StringMD5(filePath.ToLowerInvariant());
|
||||
string contentHash = HashUtility.FileMD5(filePath);
|
||||
string combined = pathHash + contentHash;
|
||||
return HashUtility.StringMD5(combined);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,5 +6,9 @@ namespace YooAsset.Editor
|
||||
{
|
||||
public class RawFileBuildParameters : BuildParameters
|
||||
{
|
||||
/// <summary>
|
||||
/// 文件哈希值计算包含路径信息
|
||||
/// </summary>
|
||||
public bool IncludePathInHash = false;
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,8 @@ namespace YooAsset.Editor
|
||||
var scriptableBuildParameters = buildParametersContext.Parameters as ScriptableBuildParameters;
|
||||
|
||||
// 构建内容
|
||||
var buildContent = new BundleBuildContent(buildMapContext.GetPipelineBuilds());
|
||||
var bundleBuilds = buildMapContext.GetPipelineBuilds(scriptableBuildParameters.ReplaceAssetPathWithAddress);
|
||||
var buildContent = new BundleBuildContent(bundleBuilds);
|
||||
|
||||
// 开始构建
|
||||
IBundleBuildResults buildResults;
|
||||
|
||||
@@ -13,7 +13,10 @@ namespace YooAsset.Editor
|
||||
|
||||
void IBuildTask.Run(BuildContext context)
|
||||
{
|
||||
CreateManifestFile(true, true, context);
|
||||
var buildParametersContext = context.GetContextObject<BuildParametersContext>();
|
||||
var scriptableBuildParameters = buildParametersContext.Parameters as ScriptableBuildParameters;
|
||||
bool replaceAssetPathWithAddress = scriptableBuildParameters.ReplaceAssetPathWithAddress;
|
||||
CreateManifestFile(true, true, replaceAssetPathWithAddress, context);
|
||||
}
|
||||
|
||||
protected override string[] GetBundleDepends(BuildContext context, string bundleName)
|
||||
|
||||
@@ -40,17 +40,17 @@ namespace YooAsset.Editor
|
||||
throw new Exception(message);
|
||||
}
|
||||
}
|
||||
protected override string GetBundleFileHash(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext)
|
||||
protected override string GetBundleFileHash(BuildBundleInfo bundleInfo, BuildContext context)
|
||||
{
|
||||
string filePath = bundleInfo.PackageSourceFilePath;
|
||||
return HashUtility.FileMD5(filePath);
|
||||
}
|
||||
protected override string GetBundleFileCRC(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext)
|
||||
protected override uint GetBundleFileCRC(BuildBundleInfo bundleInfo, BuildContext context)
|
||||
{
|
||||
string filePath = bundleInfo.PackageSourceFilePath;
|
||||
return HashUtility.FileCRC32(filePath);
|
||||
return HashUtility.FileCRC32Value(filePath);
|
||||
}
|
||||
protected override long GetBundleFileSize(BuildBundleInfo bundleInfo, BuildParametersContext buildParametersContext)
|
||||
protected override long GetBundleFileSize(BuildBundleInfo bundleInfo, BuildContext context)
|
||||
{
|
||||
string filePath = bundleInfo.PackageSourceFilePath;
|
||||
return FileUtility.GetFileSize(filePath);
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace YooAsset.Editor
|
||||
public ECompressOption CompressOption = ECompressOption.Uncompressed;
|
||||
|
||||
/// <summary>
|
||||
/// 从AssetBundle文件头里剥离Unity版本信息
|
||||
/// 从文件头里剥离Unity版本信息
|
||||
/// </summary>
|
||||
public bool StripUnityVersion = false;
|
||||
|
||||
@@ -25,10 +25,21 @@ namespace YooAsset.Editor
|
||||
public bool DisableWriteTypeTree = false;
|
||||
|
||||
/// <summary>
|
||||
/// 忽略类型树变化
|
||||
/// 忽略类型树变化(无效参数)
|
||||
/// </summary>
|
||||
public bool IgnoreTypeTreeChanges = true;
|
||||
|
||||
/// <summary>
|
||||
/// 使用可寻址地址代替资源路径
|
||||
/// 说明:开启此项可以节省运行时清单占用的内存!
|
||||
/// </summary>
|
||||
public bool ReplaceAssetPathWithAddress = false;
|
||||
|
||||
/// <summary>
|
||||
/// 自动建立资源对象对图集的依赖关系
|
||||
/// </summary>
|
||||
public bool TrackSpriteAtlasDependencies = false;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 生成代码防裁剪配置
|
||||
@@ -76,10 +87,9 @@ namespace YooAsset.Editor
|
||||
throw new System.NotImplementedException(CompressOption.ToString());
|
||||
|
||||
if (StripUnityVersion)
|
||||
buildParams.ContentBuildFlags |= UnityEditor.Build.Content.ContentBuildFlags.StripUnityVersion;
|
||||
|
||||
buildParams.ContentBuildFlags |= UnityEditor.Build.Content.ContentBuildFlags.StripUnityVersion; // Build Flag to indicate the Unity Version should not be written to the serialized file.
|
||||
if (DisableWriteTypeTree)
|
||||
buildParams.ContentBuildFlags |= UnityEditor.Build.Content.ContentBuildFlags.DisableWriteTypeTree;
|
||||
buildParams.ContentBuildFlags |= UnityEditor.Build.Content.ContentBuildFlags.DisableWriteTypeTree; //Do not include type information within the built content.
|
||||
|
||||
buildParams.UseCache = true;
|
||||
buildParams.CacheServerHost = CacheServerHost;
|
||||
|
||||
@@ -21,6 +21,11 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
public string ErrorInfo;
|
||||
|
||||
/// <summary>
|
||||
/// 构建失败的堆栈
|
||||
/// </summary>
|
||||
public string ErrorStack;
|
||||
|
||||
/// <summary>
|
||||
/// 输出的补丁包目录
|
||||
/// </summary>
|
||||
|
||||
@@ -51,6 +51,7 @@ namespace YooAsset.Editor
|
||||
EditorTools.ClearProgressBar();
|
||||
buildResult.FailedTask = task.GetType().Name;
|
||||
buildResult.ErrorInfo = e.ToString();
|
||||
buildResult.ErrorStack = e.StackTrace;
|
||||
buildResult.Success = false;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -82,14 +82,14 @@ namespace YooAsset.Editor
|
||||
}
|
||||
private void BuildButton_clicked()
|
||||
{
|
||||
if (EditorUtility.DisplayDialog("提示", $"开始构建资源包[{PackageName}]!", "Yes", "No"))
|
||||
if (EditorUtility.DisplayDialog("Info", $"Start building resource package [{PackageName}]!", "Yes", "No"))
|
||||
{
|
||||
EditorTools.ClearUnityConsole();
|
||||
EditorApplication.delayCall += ExecuteBuild;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning("[Build] 打包已经取消");
|
||||
Debug.LogWarning("[Build] Packaging has been canceled.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -42,14 +42,14 @@ namespace YooAsset.Editor
|
||||
}
|
||||
private void BuildButton_clicked()
|
||||
{
|
||||
if (EditorUtility.DisplayDialog("提示", $"开始构建资源包[{PackageName}]!", "Yes", "No"))
|
||||
if (EditorUtility.DisplayDialog("Info", $"Start building resource package [{PackageName}]!", "Yes", "No"))
|
||||
{
|
||||
EditorTools.ClearUnityConsole();
|
||||
EditorApplication.delayCall += ExecuteBuild;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning("[Build] 打包已经取消");
|
||||
Debug.LogWarning("[Build] Packaging has been canceled.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -77,14 +77,14 @@ namespace YooAsset.Editor
|
||||
}
|
||||
private void BuildButton_clicked()
|
||||
{
|
||||
if (EditorUtility.DisplayDialog("提示", $"开始构建资源包[{PackageName}]!", "Yes", "No"))
|
||||
if (EditorUtility.DisplayDialog("Info", $"Start building resource package [{PackageName}]!", "Yes", "No"))
|
||||
{
|
||||
EditorTools.ClearUnityConsole();
|
||||
EditorApplication.delayCall += ExecuteBuild;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning("[Build] 打包已经取消");
|
||||
Debug.LogWarning("[Build] Packaging has been canceled.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -82,14 +82,14 @@ namespace YooAsset.Editor
|
||||
}
|
||||
private void BuildButton_clicked()
|
||||
{
|
||||
if (EditorUtility.DisplayDialog("提示", $"开始构建资源包[{PackageName}]!", "Yes", "No"))
|
||||
if (EditorUtility.DisplayDialog("Info", $"Start building resource package [{PackageName}]!", "Yes", "No"))
|
||||
{
|
||||
EditorTools.ClearUnityConsole();
|
||||
EditorApplication.delayCall += ExecuteBuild;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning("[Build] 打包已经取消");
|
||||
Debug.LogWarning("[Build] Packaging has been canceled.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,7 +104,6 @@ namespace YooAsset.Editor
|
||||
var compressOption = AssetBundleBuilderSetting.GetPackageCompressOption(PackageName, PipelineName);
|
||||
var clearBuildCache = AssetBundleBuilderSetting.GetPackageClearBuildCache(PackageName, PipelineName);
|
||||
var useAssetDependencyDB = AssetBundleBuilderSetting.GetPackageUseAssetDependencyDB(PackageName, PipelineName);
|
||||
var builtinShaderBundleName = GetBuiltinShaderBundleName();
|
||||
|
||||
ScriptableBuildParameters buildParameters = new ScriptableBuildParameters();
|
||||
buildParameters.BuildOutputRoot = AssetBundleBuilderHelper.GetDefaultBuildOutputRoot();
|
||||
@@ -122,10 +121,10 @@ namespace YooAsset.Editor
|
||||
buildParameters.CompressOption = compressOption;
|
||||
buildParameters.ClearBuildCacheFiles = clearBuildCache;
|
||||
buildParameters.UseAssetDependencyDB = useAssetDependencyDB;
|
||||
buildParameters.BuiltinShadersBundleName = builtinShaderBundleName;
|
||||
buildParameters.EncryptionServices = CreateEncryptionServicesInstance();
|
||||
buildParameters.ManifestProcessServices = CreateManifestProcessServicesInstance();
|
||||
buildParameters.ManifestRestoreServices = CreateManifestRestoreServicesInstance();
|
||||
buildParameters.BuiltinShadersBundleName = GetBuiltinShaderBundleName();
|
||||
|
||||
ScriptableBuildPipeline pipeline = new ScriptableBuildPipeline();
|
||||
var buildResult = pipeline.Run(buildParameters, true);
|
||||
@@ -143,6 +142,16 @@ namespace YooAsset.Editor
|
||||
var packRuleResult = DefaultPackRule.CreateShadersPackRuleResult();
|
||||
return packRuleResult.GetBundleName(PackageName, uniqueBundleName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Mono脚本的资源包名称
|
||||
/// </summary>
|
||||
protected string GetMonoScriptsBundleName()
|
||||
{
|
||||
var uniqueBundleName = AssetBundleCollectorSettingData.Setting.UniqueBundleName;
|
||||
var packRuleResult = DefaultPackRule.CreateMonosPackRuleResult();
|
||||
return packRuleResult.GetBundleName(PackageName, uniqueBundleName);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -139,10 +139,17 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
public List<CollectAssetInfo> GetAllCollectAssets(CollectCommand command, AssetBundleCollectorGroup group)
|
||||
{
|
||||
// 注意:模拟构建模式下只收集主资源
|
||||
if (command.SimulateBuild)
|
||||
bool ignoreStaticCollector = command.IsFlagSet(ECollectFlags.IgnoreStaticCollector);
|
||||
if (ignoreStaticCollector)
|
||||
{
|
||||
if (CollectorType != ECollectorType.MainAssetCollector)
|
||||
if (CollectorType == ECollectorType.StaticAssetCollector)
|
||||
return new List<CollectAssetInfo>();
|
||||
}
|
||||
|
||||
bool ignoreDependCollector = command.IsFlagSet(ECollectFlags.IgnoreDependCollector);
|
||||
if (ignoreDependCollector)
|
||||
{
|
||||
if (CollectorType == ECollectorType.DependAssetCollector)
|
||||
return new List<CollectAssetInfo>();
|
||||
}
|
||||
|
||||
@@ -152,8 +159,10 @@ namespace YooAsset.Editor
|
||||
List<string> findAssets = new List<string>();
|
||||
if (AssetDatabase.IsValidFolder(CollectPath))
|
||||
{
|
||||
string collectDirectory = CollectPath;
|
||||
string[] findResult = EditorTools.FindAssets(EAssetSearchType.All, collectDirectory);
|
||||
IFilterRule filterRuleInstance = AssetBundleCollectorSettingData.GetFilterRuleInstance(FilterRuleName);
|
||||
string findAssetType = filterRuleInstance.FindAssetType;
|
||||
string searchFolder = CollectPath;
|
||||
string[] findResult = EditorTools.FindAssets(findAssetType, searchFolder);
|
||||
findAssets.AddRange(findResult);
|
||||
}
|
||||
else
|
||||
@@ -269,8 +278,8 @@ namespace YooAsset.Editor
|
||||
}
|
||||
private List<AssetInfo> GetAllDependencies(CollectCommand command, string mainAssetPath)
|
||||
{
|
||||
// 注意:模拟构建模式下不需要收集依赖资源
|
||||
if (command.SimulateBuild)
|
||||
bool ignoreGetDependencies = command.IsFlagSet(ECollectFlags.IgnoreGetDependencies);
|
||||
if (ignoreGetDependencies)
|
||||
return new List<AssetInfo>();
|
||||
|
||||
string[] depends = command.AssetDependency.GetDependencies(mainAssetPath, true);
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace YooAsset.Editor
|
||||
{
|
||||
public class AssetBundleCollectorConfig
|
||||
{
|
||||
public const string ConfigVersion = "v2.1";
|
||||
public const string ConfigVersion = "v2025.8.28";
|
||||
|
||||
public const string XmlVersion = "Version";
|
||||
public const string XmlCommon = "Common";
|
||||
@@ -23,6 +23,7 @@ namespace YooAsset.Editor
|
||||
public const string XmlPackageName = "PackageName";
|
||||
public const string XmlPackageDesc = "PackageDesc";
|
||||
public const string XmlEnableAddressable = "AutoAddressable";
|
||||
public const string XmlSupportExtensionless = "SupportExtensionless";
|
||||
public const string XmlLocationToLower = "LocationToLower";
|
||||
public const string XmlIncludeAssetGUID = "IncludeAssetGUID";
|
||||
public const string XmlIgnoreRuleName = "IgnoreRuleName";
|
||||
@@ -99,6 +100,7 @@ namespace YooAsset.Editor
|
||||
package.PackageName = packageElement.GetAttribute(XmlPackageName);
|
||||
package.PackageDesc = packageElement.GetAttribute(XmlPackageDesc);
|
||||
package.EnableAddressable = packageElement.GetAttribute(XmlEnableAddressable) == "True" ? true : false;
|
||||
package.SupportExtensionless = packageElement.GetAttribute(XmlSupportExtensionless) == "True" ? true : false;
|
||||
package.LocationToLower = packageElement.GetAttribute(XmlLocationToLower) == "True" ? true : false;
|
||||
package.IncludeAssetGUID = packageElement.GetAttribute(XmlIncludeAssetGUID) == "True" ? true : false;
|
||||
package.IgnoreRuleName = packageElement.GetAttribute(XmlIgnoreRuleName);
|
||||
@@ -211,6 +213,7 @@ namespace YooAsset.Editor
|
||||
packageElement.SetAttribute(XmlPackageName, package.PackageName);
|
||||
packageElement.SetAttribute(XmlPackageDesc, package.PackageDesc);
|
||||
packageElement.SetAttribute(XmlEnableAddressable, package.EnableAddressable.ToString());
|
||||
packageElement.SetAttribute(XmlSupportExtensionless, package.SupportExtensionless.ToString());
|
||||
packageElement.SetAttribute(XmlLocationToLower, package.LocationToLower.ToString());
|
||||
packageElement.SetAttribute(XmlIncludeAssetGUID, package.IncludeAssetGUID.ToString());
|
||||
packageElement.SetAttribute(XmlIgnoreRuleName, package.IgnoreRuleName);
|
||||
@@ -275,6 +278,23 @@ namespace YooAsset.Editor
|
||||
return UpdateXmlConfig(xmlDoc);
|
||||
}
|
||||
|
||||
// v2.1 -> v2025.8.28
|
||||
if (configVersion == "v2.1")
|
||||
{
|
||||
// 读取包裹配置
|
||||
var packageNodeList = root.GetElementsByTagName(XmlPackage);
|
||||
foreach (var packageNode in packageNodeList)
|
||||
{
|
||||
XmlElement packageElement = packageNode as XmlElement;
|
||||
if (packageElement.HasAttribute(XmlSupportExtensionless) == false)
|
||||
packageElement.SetAttribute(XmlSupportExtensionless, "True");
|
||||
}
|
||||
|
||||
// 更新版本
|
||||
root.SetAttribute(XmlVersion, "v2025.8.28");
|
||||
return UpdateXmlConfig(xmlDoc);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,11 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
public bool EnableAddressable = false;
|
||||
|
||||
/// <summary>
|
||||
/// 支持无后缀名的资源定位地址
|
||||
/// </summary>
|
||||
public bool SupportExtensionless = true;
|
||||
|
||||
/// <summary>
|
||||
/// 资源定位地址大小写不敏感
|
||||
/// </summary>
|
||||
|
||||
@@ -111,6 +111,7 @@ namespace YooAsset.Editor
|
||||
command.UniqueBundleName = UniqueBundleName;
|
||||
command.UseAssetDependencyDB = useAssetDependencyDB;
|
||||
command.EnableAddressable = package.EnableAddressable;
|
||||
command.SupportExtensionless = package.SupportExtensionless;
|
||||
command.LocationToLower = package.LocationToLower;
|
||||
command.IncludeAssetGUID = package.IncludeAssetGUID;
|
||||
command.AutoCollectShaders = package.AutoCollectShaders;
|
||||
|
||||
@@ -38,6 +38,7 @@ namespace YooAsset.Editor
|
||||
|
||||
private VisualElement _setting2Container;
|
||||
private Toggle _enableAddressableToogle;
|
||||
private Toggle _supportExtensionlessToogle;
|
||||
private Toggle _locationToLowerToogle;
|
||||
private Toggle _includeAssetGUIDToogle;
|
||||
private Toggle _autoCollectShadersToogle;
|
||||
@@ -131,6 +132,17 @@ namespace YooAsset.Editor
|
||||
RefreshWindow();
|
||||
}
|
||||
});
|
||||
_supportExtensionlessToogle = root.Q<Toggle>("SupportExtensionless");
|
||||
_supportExtensionlessToogle.RegisterValueChangedCallback(evt =>
|
||||
{
|
||||
var selectPackage = _packageListView.selectedItem as AssetBundleCollectorPackage;
|
||||
if (selectPackage != null)
|
||||
{
|
||||
selectPackage.SupportExtensionless = evt.newValue;
|
||||
AssetBundleCollectorSettingData.ModifyPackage(selectPackage);
|
||||
RefreshWindow();
|
||||
}
|
||||
});
|
||||
_locationToLowerToogle = root.Q<Toggle>("LocationToLower");
|
||||
_locationToLowerToogle.RegisterValueChangedCallback(evt =>
|
||||
{
|
||||
@@ -224,6 +236,7 @@ namespace YooAsset.Editor
|
||||
|
||||
// 包裹名称
|
||||
_packageNameTxt = root.Q<TextField>("PackageName");
|
||||
_packageNameTxt.isDelayed = true;
|
||||
_packageNameTxt.RegisterValueChangedCallback(evt =>
|
||||
{
|
||||
var selectPackage = _packageListView.selectedItem as AssetBundleCollectorPackage;
|
||||
@@ -237,6 +250,7 @@ namespace YooAsset.Editor
|
||||
|
||||
// 包裹备注
|
||||
_packageDescTxt = root.Q<TextField>("PackageDesc");
|
||||
_packageDescTxt.isDelayed = true;
|
||||
_packageDescTxt.RegisterValueChangedCallback(evt =>
|
||||
{
|
||||
var selectPackage = _packageListView.selectedItem as AssetBundleCollectorPackage;
|
||||
@@ -274,6 +288,7 @@ namespace YooAsset.Editor
|
||||
|
||||
// 分组名称
|
||||
_groupNameTxt = root.Q<TextField>("GroupName");
|
||||
_groupNameTxt.isDelayed = true;
|
||||
_groupNameTxt.RegisterValueChangedCallback(evt =>
|
||||
{
|
||||
var selectPackage = _packageListView.selectedItem as AssetBundleCollectorPackage;
|
||||
@@ -288,6 +303,7 @@ namespace YooAsset.Editor
|
||||
|
||||
// 分组备注
|
||||
_groupDescTxt = root.Q<TextField>("GroupDesc");
|
||||
_groupDescTxt.isDelayed = true;
|
||||
_groupDescTxt.RegisterValueChangedCallback(evt =>
|
||||
{
|
||||
var selectPackage = _packageListView.selectedItem as AssetBundleCollectorPackage;
|
||||
@@ -302,6 +318,7 @@ namespace YooAsset.Editor
|
||||
|
||||
// 分组的资源标签
|
||||
_groupTagsTxt = root.Q<TextField>("GroupTags");
|
||||
_groupTagsTxt.isDelayed = true;
|
||||
_groupTagsTxt.RegisterValueChangedCallback(evt =>
|
||||
{
|
||||
var selectPackage = _packageListView.selectedItem as AssetBundleCollectorPackage;
|
||||
@@ -487,6 +504,7 @@ namespace YooAsset.Editor
|
||||
_packageSettingsButton.SetEnabled(true);
|
||||
_packageSettingsButton.text = $"{packageSettingName} ({selectPackage.PackageName})";
|
||||
_enableAddressableToogle.SetValueWithoutNotify(selectPackage.EnableAddressable);
|
||||
_supportExtensionlessToogle.SetValueWithoutNotify(selectPackage.SupportExtensionless);
|
||||
_locationToLowerToogle.SetValueWithoutNotify(selectPackage.LocationToLower);
|
||||
_includeAssetGUIDToogle.SetValueWithoutNotify(selectPackage.IncludeAssetGUID);
|
||||
_autoCollectShadersToogle.SetValueWithoutNotify(selectPackage.AutoCollectShaders);
|
||||
@@ -804,6 +822,7 @@ namespace YooAsset.Editor
|
||||
var textField = new TextField();
|
||||
textField.name = "TextField0";
|
||||
textField.label = "User Data";
|
||||
textField.isDelayed = true;
|
||||
textField.style.width = 200;
|
||||
elementBottom.Add(textField);
|
||||
var label = textField.Q<Label>();
|
||||
@@ -813,6 +832,7 @@ namespace YooAsset.Editor
|
||||
var textField = new TextField();
|
||||
textField.name = "TextField1";
|
||||
textField.label = "Asset Tags";
|
||||
textField.isDelayed = true;
|
||||
textField.style.width = 100;
|
||||
textField.style.marginLeft = 20;
|
||||
textField.style.flexGrow = 1;
|
||||
@@ -831,7 +851,7 @@ namespace YooAsset.Editor
|
||||
var foldout = new Foldout();
|
||||
foldout.name = "Foldout1";
|
||||
foldout.value = false;
|
||||
foldout.text = "Main Assets";
|
||||
foldout.text = "Assets";
|
||||
elementFoldout.Add(foldout);
|
||||
}
|
||||
|
||||
@@ -864,11 +884,9 @@ namespace YooAsset.Editor
|
||||
var foldout = element.Q<Foldout>("Foldout1");
|
||||
foldout.RegisterValueChangedCallback(evt =>
|
||||
{
|
||||
if (evt.newValue)
|
||||
RefreshFoldout(foldout, selectGroup, collector);
|
||||
else
|
||||
foldout.Clear();
|
||||
RefreshFoldoutContent(foldout, selectGroup, collector);
|
||||
});
|
||||
RefreshFoldoutName(foldout, collector.CollectorType);
|
||||
|
||||
// Remove Button
|
||||
var removeBtn = element.Q<Button>("Button1");
|
||||
@@ -885,10 +903,7 @@ namespace YooAsset.Editor
|
||||
collector.CollectPath = AssetDatabase.GetAssetPath(evt.newValue);
|
||||
collector.CollectorGUID = AssetDatabase.AssetPathToGUID(collector.CollectPath);
|
||||
AssetBundleCollectorSettingData.ModifyCollector(selectGroup, collector);
|
||||
if (foldout.value)
|
||||
{
|
||||
RefreshFoldout(foldout, selectGroup, collector);
|
||||
}
|
||||
RefreshFoldoutContent(foldout, selectGroup, collector);
|
||||
});
|
||||
UIElementsTools.RefreshObjectFieldShowPath(objectField1);
|
||||
|
||||
@@ -899,10 +914,7 @@ namespace YooAsset.Editor
|
||||
{
|
||||
collector.CollectorType = EditorTools.NameToEnum<ECollectorType>(evt.newValue);
|
||||
AssetBundleCollectorSettingData.ModifyCollector(selectGroup, collector);
|
||||
if (foldout.value)
|
||||
{
|
||||
RefreshFoldout(foldout, selectGroup, collector);
|
||||
}
|
||||
RefreshFoldoutContent(foldout, selectGroup, collector);
|
||||
|
||||
if (collector.CollectorType == ECollectorType.MainAssetCollector)
|
||||
textTags.SetEnabled(true);
|
||||
@@ -921,10 +933,7 @@ namespace YooAsset.Editor
|
||||
{
|
||||
collector.AddressRuleName = evt.newValue.ClassName;
|
||||
AssetBundleCollectorSettingData.ModifyCollector(selectGroup, collector);
|
||||
if (foldout.value)
|
||||
{
|
||||
RefreshFoldout(foldout, selectGroup, collector);
|
||||
}
|
||||
RefreshFoldoutContent(foldout, selectGroup, collector);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -937,10 +946,7 @@ namespace YooAsset.Editor
|
||||
{
|
||||
collector.PackRuleName = evt.newValue.ClassName;
|
||||
AssetBundleCollectorSettingData.ModifyCollector(selectGroup, collector);
|
||||
if (foldout.value)
|
||||
{
|
||||
RefreshFoldout(foldout, selectGroup, collector);
|
||||
}
|
||||
RefreshFoldoutContent(foldout, selectGroup, collector);
|
||||
});
|
||||
|
||||
// Filter Rule
|
||||
@@ -952,10 +958,7 @@ namespace YooAsset.Editor
|
||||
{
|
||||
collector.FilterRuleName = evt.newValue.ClassName;
|
||||
AssetBundleCollectorSettingData.ModifyCollector(selectGroup, collector);
|
||||
if (foldout.value)
|
||||
{
|
||||
RefreshFoldout(foldout, selectGroup, collector);
|
||||
}
|
||||
RefreshFoldoutContent(foldout, selectGroup, collector);
|
||||
});
|
||||
|
||||
// UserData
|
||||
@@ -976,61 +979,101 @@ namespace YooAsset.Editor
|
||||
AssetBundleCollectorSettingData.ModifyCollector(selectGroup, collector);
|
||||
});
|
||||
}
|
||||
private void RefreshFoldout(Foldout foldout, AssetBundleCollectorGroup group, AssetBundleCollector collector)
|
||||
private void RefreshFoldoutName(Foldout foldout, ECollectorType collectorType, int elementNumber = -1)
|
||||
{
|
||||
if (collectorType == ECollectorType.MainAssetCollector)
|
||||
{
|
||||
if (elementNumber >= 0)
|
||||
foldout.text = $"Main Assets ({elementNumber})";
|
||||
else
|
||||
foldout.text = $"Main Assets";
|
||||
}
|
||||
else if (collectorType == ECollectorType.StaticAssetCollector)
|
||||
{
|
||||
if (elementNumber >= 0)
|
||||
foldout.text = $"Static Assets ({elementNumber})";
|
||||
else
|
||||
foldout.text = $"Static Assets";
|
||||
}
|
||||
else if (collectorType == ECollectorType.DependAssetCollector)
|
||||
{
|
||||
if (elementNumber >= 0)
|
||||
foldout.text = $"Depend Assets ({elementNumber})";
|
||||
else
|
||||
foldout.text = $"Depend Assets";
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new System.NotImplementedException(collectorType.ToString());
|
||||
}
|
||||
}
|
||||
private void RefreshFoldoutContent(Foldout foldout, AssetBundleCollectorGroup group, AssetBundleCollector collector)
|
||||
{
|
||||
RefreshFoldoutName(foldout, collector.CollectorType);
|
||||
|
||||
// 折叠栏不可见
|
||||
if (foldout.value == false)
|
||||
{
|
||||
foldout.Clear();
|
||||
return;
|
||||
}
|
||||
|
||||
// 清空旧元素
|
||||
foldout.Clear();
|
||||
|
||||
// 检测配置是否有效
|
||||
if (collector.IsValid() == false)
|
||||
{
|
||||
collector.CheckConfigError();
|
||||
return;
|
||||
}
|
||||
|
||||
if (collector.CollectorType == ECollectorType.MainAssetCollector || collector.CollectorType == ECollectorType.StaticAssetCollector)
|
||||
List<CollectAssetInfo> collectAssetInfos = null;
|
||||
|
||||
try
|
||||
{
|
||||
List<CollectAssetInfo> collectAssetInfos = null;
|
||||
IIgnoreRule ignoreRule = AssetBundleCollectorSettingData.GetIgnoreRuleInstance(_ignoreRulePopupField.value.ClassName);
|
||||
string packageName = _packageNameTxt.value;
|
||||
var command = new CollectCommand(packageName, ignoreRule);
|
||||
command.SetFlag(ECollectFlags.IgnoreGetDependencies, true);
|
||||
command.UniqueBundleName = _uniqueBundleNameToogle.value;
|
||||
command.EnableAddressable = _enableAddressableToogle.value;
|
||||
command.SupportExtensionless = _supportExtensionlessToogle.value;
|
||||
command.LocationToLower = _locationToLowerToogle.value;
|
||||
command.IncludeAssetGUID = _includeAssetGUIDToogle.value;
|
||||
command.AutoCollectShaders = _autoCollectShadersToogle.value;
|
||||
|
||||
try
|
||||
collector.CheckConfigError();
|
||||
collectAssetInfos = collector.GetAllCollectAssets(command, group);
|
||||
}
|
||||
catch (System.Exception e)
|
||||
{
|
||||
Debug.LogError(e.ToString());
|
||||
}
|
||||
|
||||
if (collectAssetInfos != null)
|
||||
{
|
||||
bool showAdress = false;
|
||||
if (_enableAddressableToogle.value && collector.CollectorType == ECollectorType.MainAssetCollector)
|
||||
showAdress = true;
|
||||
|
||||
RefreshFoldoutName(foldout, collector.CollectorType, collectAssetInfos.Count);
|
||||
foreach (var collectAsset in collectAssetInfos)
|
||||
{
|
||||
IIgnoreRule ignoreRule = AssetBundleCollectorSettingData.GetIgnoreRuleInstance(_ignoreRulePopupField.value.ClassName);
|
||||
string packageName = _packageNameTxt.value;
|
||||
var command = new CollectCommand(packageName, ignoreRule);
|
||||
command.SimulateBuild = true;
|
||||
command.UniqueBundleName = _uniqueBundleNameToogle.value;
|
||||
command.UseAssetDependencyDB = true;
|
||||
command.EnableAddressable = _enableAddressableToogle.value;
|
||||
command.LocationToLower = _locationToLowerToogle.value;
|
||||
command.IncludeAssetGUID = _includeAssetGUIDToogle.value;
|
||||
command.AutoCollectShaders = _autoCollectShadersToogle.value;
|
||||
VisualElement elementRow = new VisualElement();
|
||||
elementRow.style.flexDirection = FlexDirection.Row;
|
||||
foldout.Add(elementRow);
|
||||
|
||||
collector.CheckConfigError();
|
||||
collectAssetInfos = collector.GetAllCollectAssets(command, group);
|
||||
}
|
||||
catch (System.Exception e)
|
||||
{
|
||||
Debug.LogError(e.ToString());
|
||||
}
|
||||
string showInfo = collectAsset.AssetInfo.AssetPath;
|
||||
if (showAdress)
|
||||
showInfo = $"[{collectAsset.Address}] {collectAsset.AssetInfo.AssetPath}";
|
||||
|
||||
if (collectAssetInfos != null)
|
||||
{
|
||||
foreach (var collectAsset in collectAssetInfos)
|
||||
{
|
||||
VisualElement elementRow = new VisualElement();
|
||||
elementRow.style.flexDirection = FlexDirection.Row;
|
||||
foldout.Add(elementRow);
|
||||
|
||||
string showInfo = collectAsset.AssetInfo.AssetPath;
|
||||
if (_enableAddressableToogle.value)
|
||||
showInfo = $"[{collectAsset.Address}] {collectAsset.AssetInfo.AssetPath}";
|
||||
|
||||
var label = new Label();
|
||||
label.text = showInfo;
|
||||
label.style.width = 300;
|
||||
label.style.marginLeft = 0;
|
||||
label.style.flexGrow = 1;
|
||||
elementRow.Add(label);
|
||||
}
|
||||
var label = new Label();
|
||||
label.text = showInfo;
|
||||
label.style.width = 300;
|
||||
label.style.marginLeft = 0;
|
||||
label.style.flexGrow = 1;
|
||||
elementRow.Add(label);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
<ui:Button text="Package Settings" display-tooltip-when-elided="true" name="PackageSettingsButton" />
|
||||
<ui:VisualElement name="PublicContainer2">
|
||||
<ui:Toggle label="Enable Addressable" name="EnableAddressable" style="width: 196px; -unity-text-align: middle-left;" />
|
||||
<ui:Toggle label="Support Extensionless" name="SupportExtensionless" style="width: 196px; -unity-text-align: middle-left;" />
|
||||
<ui:Toggle label="Location To Lower" name="LocationToLower" style="width: 196px; -unity-text-align: middle-left;" />
|
||||
<ui:Toggle label="Include Asset GUID" name="IncludeAssetGUID" style="width: 196px; -unity-text-align: middle-left;" />
|
||||
<ui:Toggle label="Auto Collect Shaders" name="AutoCollectShaders" value="true" style="width: 196px; -unity-text-align: middle-left;" />
|
||||
@@ -29,7 +30,7 @@
|
||||
<ui:VisualElement name="PackageContainer" style="width: 200px; flex-grow: 0; background-color: rgb(67, 67, 67); border-left-width: 5px; border-right-width: 5px; border-top-width: 5px; border-bottom-width: 5px;">
|
||||
<ui:Label text="Packages" display-tooltip-when-elided="true" name="PackageTitle" style="background-color: rgb(89, 89, 89); -unity-text-align: upper-center; -unity-font-style: bold; border-left-width: 5px; border-right-width: 5px; border-top-width: 5px; border-bottom-width: 5px; font-size: 12px;" />
|
||||
<ui:ListView focusable="true" name="PackageListView" item-height="20" virtualization-method="DynamicHeight" reorderable="true" reorder-mode="Animated" style="flex-grow: 1;" />
|
||||
<ui:VisualElement name="PackageAddContainer" style="height: 20px; flex-direction: row; justify-content: center;">
|
||||
<ui:VisualElement name="PackageAddContainer" style="height: 20px; flex-direction: row; justify-content: center; flex-shrink: 0;">
|
||||
<ui:Button text=" - " display-tooltip-when-elided="true" name="RemoveBtn" />
|
||||
<ui:Button text=" + " display-tooltip-when-elided="true" name="AddBtn" />
|
||||
</ui:VisualElement>
|
||||
@@ -39,7 +40,7 @@
|
||||
<ui:TextField picking-mode="Ignore" label="Package Name" name="PackageName" style="flex-direction: column;" />
|
||||
<ui:TextField picking-mode="Ignore" label="Package Desc" name="PackageDesc" style="flex-direction: column;" />
|
||||
<ui:ListView focusable="true" name="GroupListView" item-height="20" virtualization-method="DynamicHeight" reorderable="true" reorder-mode="Animated" style="flex-grow: 1;" />
|
||||
<ui:VisualElement name="GroupAddContainer" style="height: 20px; flex-direction: row; justify-content: center;">
|
||||
<ui:VisualElement name="GroupAddContainer" style="height: 20px; flex-direction: row; justify-content: center; flex-shrink: 0;">
|
||||
<ui:Button text=" - " display-tooltip-when-elided="true" name="RemoveBtn" />
|
||||
<ui:Button text=" + " display-tooltip-when-elided="true" name="AddBtn" />
|
||||
</ui:VisualElement>
|
||||
|
||||
@@ -88,8 +88,8 @@ namespace YooAsset.Editor
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ClearDatabase(true);
|
||||
Debug.LogError($"Failed to load cache database : {ex.Message}");
|
||||
ClearDatabase(true);
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -169,7 +169,8 @@ namespace YooAsset.Editor
|
||||
File.Delete(_databaseFilePath);
|
||||
}
|
||||
|
||||
_database.Clear();
|
||||
if (_database != null)
|
||||
_database.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,6 +1,26 @@
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
public enum ECollectFlags
|
||||
{
|
||||
None = 0,
|
||||
|
||||
/// <summary>
|
||||
/// 不收集依赖资源
|
||||
/// </summary>
|
||||
IgnoreGetDependencies = 1 << 0,
|
||||
|
||||
/// <summary>
|
||||
/// 忽略静态收集器
|
||||
/// </summary>
|
||||
IgnoreStaticCollector = 1 << 1,
|
||||
|
||||
/// <summary>
|
||||
/// 忽略依赖收集器
|
||||
/// </summary>
|
||||
IgnoreDependCollector = 1 << 2,
|
||||
}
|
||||
|
||||
public class CollectCommand
|
||||
{
|
||||
/// <summary>
|
||||
@@ -17,7 +37,20 @@ namespace YooAsset.Editor
|
||||
/// <summary>
|
||||
/// 模拟构建模式
|
||||
/// </summary>
|
||||
public bool SimulateBuild { set; get; }
|
||||
public bool SimulateBuild
|
||||
{
|
||||
set
|
||||
{
|
||||
SetFlag(ECollectFlags.IgnoreGetDependencies, value);
|
||||
SetFlag(ECollectFlags.IgnoreStaticCollector, value);
|
||||
SetFlag(ECollectFlags.IgnoreDependCollector, value);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 窗口收集模式
|
||||
/// </summary>
|
||||
public int CollectFlags { set; get; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 资源包名唯一化
|
||||
@@ -34,6 +67,11 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
public bool EnableAddressable { set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 支持无后缀名的资源定位地址
|
||||
/// </summary>
|
||||
public bool SupportExtensionless { set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 资源定位地址大小写不敏感
|
||||
/// </summary>
|
||||
@@ -65,5 +103,24 @@ namespace YooAsset.Editor
|
||||
PackageName = packageName;
|
||||
IgnoreRule = ignoreRule;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置标记位
|
||||
/// </summary>
|
||||
public void SetFlag(ECollectFlags flag, bool isOn)
|
||||
{
|
||||
if (isOn)
|
||||
CollectFlags |= (int)flag; // 开启指定标志位
|
||||
else
|
||||
CollectFlags &= ~(int)flag; // 关闭指定标志位
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询标记位
|
||||
/// </summary>
|
||||
public bool IsFlagSet(ECollectFlags flag)
|
||||
{
|
||||
return (CollectFlags & (int)flag) != 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,13 @@ namespace YooAsset.Editor
|
||||
public interface IFilterRule
|
||||
{
|
||||
/// <summary>
|
||||
/// 是否为收集资源
|
||||
/// 搜寻的资源类型
|
||||
/// 说明:使用引擎方法搜索获取所有资源列表
|
||||
/// </summary>
|
||||
string FindAssetType { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 验证搜寻的资源是否为收集资源
|
||||
/// </summary>
|
||||
/// <returns>如果收集该资源返回TRUE</returns>
|
||||
bool IsCollectAsset(FilterRuleData data);
|
||||
|
||||
@@ -9,6 +9,11 @@ namespace YooAsset.Editor
|
||||
[DisplayName("收集所有资源")]
|
||||
public class CollectAll : IFilterRule
|
||||
{
|
||||
public string FindAssetType
|
||||
{
|
||||
get { return EAssetSearchType.All.ToString(); }
|
||||
}
|
||||
|
||||
public bool IsCollectAsset(FilterRuleData data)
|
||||
{
|
||||
return true;
|
||||
@@ -18,6 +23,11 @@ namespace YooAsset.Editor
|
||||
[DisplayName("收集场景")]
|
||||
public class CollectScene : IFilterRule
|
||||
{
|
||||
public string FindAssetType
|
||||
{
|
||||
get { return EAssetSearchType.Scene.ToString(); }
|
||||
}
|
||||
|
||||
public bool IsCollectAsset(FilterRuleData data)
|
||||
{
|
||||
string extension = Path.GetExtension(data.AssetPath);
|
||||
@@ -28,6 +38,11 @@ namespace YooAsset.Editor
|
||||
[DisplayName("收集预制体")]
|
||||
public class CollectPrefab : IFilterRule
|
||||
{
|
||||
public string FindAssetType
|
||||
{
|
||||
get { return EAssetSearchType.Prefab.ToString(); }
|
||||
}
|
||||
|
||||
public bool IsCollectAsset(FilterRuleData data)
|
||||
{
|
||||
return Path.GetExtension(data.AssetPath) == ".prefab";
|
||||
@@ -37,6 +52,11 @@ namespace YooAsset.Editor
|
||||
[DisplayName("收集精灵类型的纹理")]
|
||||
public class CollectSprite : IFilterRule
|
||||
{
|
||||
public string FindAssetType
|
||||
{
|
||||
get { return EAssetSearchType.Sprite.ToString(); }
|
||||
}
|
||||
|
||||
public bool IsCollectAsset(FilterRuleData data)
|
||||
{
|
||||
var mainAssetType = AssetDatabase.GetMainAssetTypeAtPath(data.AssetPath);
|
||||
@@ -58,6 +78,11 @@ namespace YooAsset.Editor
|
||||
[DisplayName("收集着色器")]
|
||||
public class CollectShader : IFilterRule
|
||||
{
|
||||
public string FindAssetType
|
||||
{
|
||||
get { return EAssetSearchType.Shader.ToString(); }
|
||||
}
|
||||
|
||||
public bool IsCollectAsset(FilterRuleData data)
|
||||
{
|
||||
return Path.GetExtension(data.AssetPath) == ".shader";
|
||||
@@ -67,6 +92,11 @@ namespace YooAsset.Editor
|
||||
[DisplayName("收集着色器变种集合")]
|
||||
public class CollectShaderVariants : IFilterRule
|
||||
{
|
||||
public string FindAssetType
|
||||
{
|
||||
get { return EAssetSearchType.All.ToString(); }
|
||||
}
|
||||
|
||||
public bool IsCollectAsset(FilterRuleData data)
|
||||
{
|
||||
return Path.GetExtension(data.AssetPath) == ".shadervariants";
|
||||
|
||||
@@ -17,16 +17,25 @@ namespace YooAsset.Editor
|
||||
public const string RawFileExtension = "rawfile";
|
||||
|
||||
/// <summary>
|
||||
/// Unity着色器资源包名称
|
||||
/// 默认的Unity着色器资源包名称
|
||||
/// </summary>
|
||||
public const string ShadersBundleName = "unityshaders";
|
||||
|
||||
/// <summary>
|
||||
/// 默认的Unity脚本资源包名称
|
||||
/// </summary>
|
||||
public const string MonosBundleName = "unitymonos";
|
||||
|
||||
public static PackRuleResult CreateShadersPackRuleResult()
|
||||
{
|
||||
PackRuleResult result = new PackRuleResult(ShadersBundleName, AssetBundleFileExtension);
|
||||
return result;
|
||||
}
|
||||
public static PackRuleResult CreateMonosPackRuleResult()
|
||||
{
|
||||
PackRuleResult result = new PackRuleResult(MonosBundleName, AssetBundleFileExtension);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace YooAsset.Editor
|
||||
/// <summary>
|
||||
/// 文件校验码
|
||||
/// </summary>
|
||||
public string FileCRC;
|
||||
public uint FileCRC;
|
||||
|
||||
/// <summary>
|
||||
/// 文件大小(字节数)
|
||||
|
||||
@@ -61,6 +61,7 @@ namespace YooAsset.Editor
|
||||
// 收集器配置
|
||||
public bool UniqueBundleName;
|
||||
public bool EnableAddressable;
|
||||
public bool SupportExtensionless;
|
||||
public bool LocationToLower;
|
||||
public bool IncludeAssetGUID;
|
||||
public bool AutoCollectShaders;
|
||||
@@ -80,6 +81,7 @@ namespace YooAsset.Editor
|
||||
public ECompressOption CompressOption;
|
||||
public bool DisableWriteTypeTree;
|
||||
public bool IgnoreTypeTreeChanges;
|
||||
public bool ReplaceAssetPathWithAddress;
|
||||
public bool WriteLinkXML = true;
|
||||
public string CacheServerHost;
|
||||
public int CacheServerPort;
|
||||
|
||||
@@ -55,6 +55,7 @@ namespace YooAsset.Editor
|
||||
BindListViewHeader("Collect Settings");
|
||||
BindListViewItem("Unique Bundle Name", $"{buildReport.Summary.UniqueBundleName}");
|
||||
BindListViewItem("Enable Addressable", $"{buildReport.Summary.EnableAddressable}");
|
||||
BindListViewItem("Support Extensionless", $"{buildReport.Summary.SupportExtensionless}");
|
||||
BindListViewItem("Location To Lower", $"{buildReport.Summary.LocationToLower}");
|
||||
BindListViewItem("Include Asset GUID", $"{buildReport.Summary.IncludeAssetGUID}");
|
||||
BindListViewItem("Auto Collect Shaders", $"{buildReport.Summary.AutoCollectShaders}");
|
||||
@@ -73,6 +74,7 @@ namespace YooAsset.Editor
|
||||
BindListViewItem("CompressOption", $"{buildReport.Summary.CompressOption}");
|
||||
BindListViewItem("DisableWriteTypeTree", $"{buildReport.Summary.DisableWriteTypeTree}");
|
||||
BindListViewItem("IgnoreTypeTreeChanges", $"{buildReport.Summary.IgnoreTypeTreeChanges}");
|
||||
BindListViewItem("ReplaceAssetPathWithAddress", $"{buildReport.Summary.ReplaceAssetPathWithAddress}");
|
||||
BindListViewItem(string.Empty, string.Empty);
|
||||
|
||||
BindListViewHeader("Build Results");
|
||||
|
||||
@@ -62,6 +62,17 @@ namespace YooAsset.Editor
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否为图集资源
|
||||
/// </summary>
|
||||
public bool IsSpriteAtlas()
|
||||
{
|
||||
if (AssetType == typeof(UnityEngine.U2D.SpriteAtlas))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
public int CompareTo(AssetInfo other)
|
||||
{
|
||||
return this.AssetPath.CompareTo(other.AssetPath);
|
||||
|
||||
@@ -39,7 +39,10 @@ namespace YooAsset.Editor
|
||||
Shader,
|
||||
Sprite,
|
||||
Texture,
|
||||
RenderTexture,
|
||||
VideoClip,
|
||||
PlayableAsset,
|
||||
TimelineAsset
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -169,6 +169,28 @@ namespace YooAsset.Editor
|
||||
/// <param name="searchInFolders">指定搜索的文件夹列表</param>
|
||||
/// <returns>返回搜集到的资源路径列表</returns>
|
||||
public static string[] FindAssets(EAssetSearchType searchType, string[] searchInFolders)
|
||||
{
|
||||
return FindAssets(searchType.ToString(), searchInFolders);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 搜集资源
|
||||
/// </summary>
|
||||
/// <param name="searchType">搜集的资源类型</param>
|
||||
/// <param name="searchInFolder">指定搜索的文件夹</param>
|
||||
/// <returns>返回搜集到的资源路径列表</returns>
|
||||
public static string[] FindAssets(EAssetSearchType searchType, string searchInFolder)
|
||||
{
|
||||
return FindAssets(searchType.ToString(), new string[] { searchInFolder });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 搜集资源
|
||||
/// </summary>
|
||||
/// <param name="searchType">搜集的资源类型</param>
|
||||
/// <param name="searchInFolders">指定搜索的文件夹列表</param>
|
||||
/// <returns>返回搜集到的资源路径列表</returns>
|
||||
public static string[] FindAssets(string searchType, string[] searchInFolders)
|
||||
{
|
||||
// 注意:AssetDatabase.FindAssets()不支持末尾带分隔符的文件夹路径
|
||||
for (int i = 0; i < searchInFolders.Length; i++)
|
||||
@@ -179,7 +201,7 @@ namespace YooAsset.Editor
|
||||
|
||||
// 注意:获取指定目录下的所有资源对象(包括子文件夹)
|
||||
string[] guids;
|
||||
if (searchType == EAssetSearchType.All)
|
||||
if (string.IsNullOrEmpty(searchType) || searchType == EAssetSearchType.All.ToString())
|
||||
guids = AssetDatabase.FindAssets(string.Empty, searchInFolders);
|
||||
else
|
||||
guids = AssetDatabase.FindAssets($"t:{searchType}", searchInFolders);
|
||||
@@ -206,7 +228,7 @@ namespace YooAsset.Editor
|
||||
/// <param name="searchType">搜集的资源类型</param>
|
||||
/// <param name="searchInFolder">指定搜索的文件夹</param>
|
||||
/// <returns>返回搜集到的资源路径列表</returns>
|
||||
public static string[] FindAssets(EAssetSearchType searchType, string searchInFolder)
|
||||
public static string[] FindAssets(string searchType, string searchInFolder)
|
||||
{
|
||||
return FindAssets(searchType, new string[] { searchInFolder });
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 97923f5987c469a4898718033af09e99
|
||||
guid: bb70e2274ce5a5d419cfbd7212efdf4a
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
@@ -0,0 +1,110 @@
|
||||
using System;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
/// <summary>
|
||||
/// UnityWebRequest 下载后台
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 基于 Unity 内置 UnityWebRequest 实现的下载后台。
|
||||
/// 支持自定义 UnityWebRequest 创建方式,例如添加证书验证、代理设置等。
|
||||
/// </remarks>
|
||||
internal sealed class UnityWebRequestBackend : IDownloadBackend
|
||||
{
|
||||
private readonly UnityWebRequestDelegate _webRequestCreator;
|
||||
|
||||
/// <summary>
|
||||
/// 后端名称
|
||||
/// </summary>
|
||||
public string Name
|
||||
{
|
||||
get { return nameof(UnityWebRequestBackend); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建 UnityWebRequest 下载后端(使用默认创建方式)
|
||||
/// </summary>
|
||||
public UnityWebRequestBackend() : this(null)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建 UnityWebRequest 下载后端
|
||||
/// </summary>
|
||||
/// <param name="webRequestCreator">
|
||||
/// 自定义 UnityWebRequest 创建委托(可选)。
|
||||
/// 如果为 null,则使用默认的 UnityWebRequest 构造方式。
|
||||
/// </param>
|
||||
public UnityWebRequestBackend(UnityWebRequestDelegate webRequestCreator)
|
||||
{
|
||||
_webRequestCreator = webRequestCreator;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 驱动更新
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// UnityWebRequest 由 Unity 引擎自动驱动,无需额外更新。
|
||||
/// </remarks>
|
||||
public void Update()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 释放资源
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
// 无需释放资源
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建 HEAD 请求
|
||||
/// </summary>
|
||||
public IDownloadHeadRequest CreateHeadRequest(DownloadDataRequestArgs args)
|
||||
{
|
||||
return new UnityWebRequestHeadDownloader(args, _webRequestCreator);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建文件下载请求
|
||||
/// </summary>
|
||||
public IDownloadFileRequest CreateFileRequest(DownloadFileRequestArgs args)
|
||||
{
|
||||
return new UnityWebRequestFileDownloader(args, _webRequestCreator);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建字节下载请求
|
||||
/// </summary>
|
||||
public IDownloadBytesRequest CreateBytesRequest(DownloadDataRequestArgs args)
|
||||
{
|
||||
return new UnityWebRequestBytesDownloader(args, _webRequestCreator);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建文本下载请求
|
||||
/// </summary>
|
||||
public IDownloadTextRequest CreateTextRequest(DownloadDataRequestArgs args)
|
||||
{
|
||||
return new UnityWebRequestTextDownloader(args, _webRequestCreator);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建 AssetBundle 下载请求
|
||||
/// </summary>
|
||||
public IDownloadAssetBundleRequest CreateAssetBundleRequest(DownloadAssetBundleRequestArgs args)
|
||||
{
|
||||
return new UnityWebRequestAssetBundleDownloader(args, _webRequestCreator);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建模拟下载请求
|
||||
/// </summary>
|
||||
public IDownloadFileRequest CreateSimulateRequest(DownloadSimulateRequestArgs args)
|
||||
{
|
||||
return new VirtualFileDownloader(args);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 932e4c4574244dac8c27d9ddc156f8ff
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1d30af9086de4fb282c2cdd3d26244c0
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,92 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
/// <summary>
|
||||
/// UnityWebRequest AssetBundle 下载器
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 下载并加载 Unity AssetBundle 资源包。
|
||||
/// 支持 Unity 内置缓存机制和 CRC 校验。
|
||||
/// </remarks>
|
||||
internal sealed class UnityWebRequestAssetBundleDownloader : UnityWebRequestDownloaderBase, IDownloadAssetBundleRequest
|
||||
{
|
||||
private readonly DownloadAssetBundleRequestArgs _args;
|
||||
private DownloadHandlerAssetBundle _downloadHandler;
|
||||
|
||||
/// <summary>
|
||||
/// 下载结果(AssetBundle 对象)
|
||||
/// </summary>
|
||||
public AssetBundle Result { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 构造 AssetBundle 下载器
|
||||
/// </summary>
|
||||
/// <param name="args">AssetBundle 下载参数</param>
|
||||
/// <param name="webRequestCreator">UnityWebRequest 创建器(可选)</param>
|
||||
public UnityWebRequestAssetBundleDownloader(DownloadAssetBundleRequestArgs args, UnityWebRequestDelegate webRequestCreator)
|
||||
: base(args.URL, webRequestCreator)
|
||||
{
|
||||
_args = args;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建 UnityWebRequest
|
||||
/// </summary>
|
||||
protected override void CreateWebRequest()
|
||||
{
|
||||
_downloadHandler = CreateAssetBundleDownloadHandler();
|
||||
_webRequest = CreateUnityWebRequestGet(URL);
|
||||
_webRequest.downloadHandler = _downloadHandler;
|
||||
_webRequest.disposeDownloadHandlerOnDispose = true;
|
||||
ApplyRequestOptions(_args.Timeout, _args.WatchdogTime, _args.Headers);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 请求成功时的回调
|
||||
/// </summary>
|
||||
protected override void OnRequestSucceed()
|
||||
{
|
||||
AssetBundle assetBundle = _downloadHandler.assetBundle;
|
||||
if (assetBundle == null)
|
||||
{
|
||||
Status = EDownloadRequestStatus.Failed;
|
||||
Error = $"[{GetType().Name}] URL: {URL} - AssetBundle object is null";
|
||||
}
|
||||
else
|
||||
{
|
||||
Result = assetBundle;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建 AssetBundle 下载处理器
|
||||
/// </summary>
|
||||
private DownloadHandlerAssetBundle CreateAssetBundleDownloadHandler()
|
||||
{
|
||||
DownloadHandlerAssetBundle handler;
|
||||
|
||||
if (_args.DisableUnityWebCache)
|
||||
{
|
||||
// 禁用 Unity 缓存
|
||||
handler = new DownloadHandlerAssetBundle(URL, _args.UnityCRC);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 使用 Unity 缓存(需要 FileHash)
|
||||
// The file hash defining the version of the asset bundle.
|
||||
Hash128 fileHash = Hash128.Parse(_args.FileHash);
|
||||
handler = new DownloadHandlerAssetBundle(URL, fileHash, _args.UnityCRC);
|
||||
}
|
||||
|
||||
#if UNITY_2020_3_OR_NEWER
|
||||
// 禁用自动加载,允许手动控制加载时机
|
||||
handler.autoLoadAssetBundle = false;
|
||||
#endif
|
||||
|
||||
return handler;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e01cc308d7179a34281087fafe455b42
|
||||
guid: 6f635344c08e2b04295a108c2bcc6a40
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
/// <summary>
|
||||
/// UnityWebRequest 字节下载器
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 将下载内容保存到内存中的字节数组。
|
||||
/// </remarks>
|
||||
internal sealed class UnityWebRequestBytesDownloader : UnityWebRequestDownloaderBase, IDownloadBytesRequest
|
||||
{
|
||||
private readonly DownloadDataRequestArgs _args;
|
||||
|
||||
/// <summary>
|
||||
/// 下载结果(字节数组)
|
||||
/// </summary>
|
||||
public byte[] Result { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 构造字节数组下载器
|
||||
/// </summary>
|
||||
/// <param name="args">数据下载参数</param>
|
||||
/// <param name="webRequestCreator">UnityWebRequest 创建器(可选)</param>
|
||||
public UnityWebRequestBytesDownloader(DownloadDataRequestArgs args, UnityWebRequestDelegate webRequestCreator)
|
||||
: base(args.URL, webRequestCreator)
|
||||
{
|
||||
_args = args;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建 UnityWebRequest
|
||||
/// </summary>
|
||||
protected override void CreateWebRequest()
|
||||
{
|
||||
var handler = new DownloadHandlerBuffer();
|
||||
_webRequest = CreateUnityWebRequestGet(URL);
|
||||
_webRequest.downloadHandler = handler;
|
||||
_webRequest.disposeDownloadHandlerOnDispose = true;
|
||||
ApplyRequestOptions(_args.Timeout, _args.WatchdogTime, _args.Headers);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 请求成功时的回调
|
||||
/// </summary>
|
||||
protected override void OnRequestSucceed()
|
||||
{
|
||||
var fileData = _webRequest.downloadHandler.data;
|
||||
if (fileData == null || fileData.Length == 0)
|
||||
{
|
||||
Status = EDownloadRequestStatus.Failed;
|
||||
Error = $"[{GetType().Name}] URL: {URL} - Download bytes data is null or empty !";
|
||||
}
|
||||
else
|
||||
{
|
||||
Result = fileData;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6602c4be2ef295546b7bbb328de8fb0c
|
||||
guid: 38884a96e8c2df74082d4e059e2e73ed
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -0,0 +1,290 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
/// <summary>
|
||||
/// UnityWebRequest 下载器基类
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 封装 UnityWebRequest 的通用下载逻辑,包括状态管理、进度追踪等。
|
||||
/// 子类只需实现 CreateWebRequest 方法来创建特定类型的下载请求。
|
||||
/// </remarks>
|
||||
internal abstract class UnityWebRequestDownloaderBase : IDownloadRequest
|
||||
{
|
||||
private readonly UnityWebRequestDelegate _webRequestCreator;
|
||||
protected UnityWebRequest _webRequest;
|
||||
|
||||
// 看门狗相关
|
||||
private int _watchdogTime = 0;
|
||||
private bool _watchdogAborted = false;
|
||||
private long _lastDownloadBytes = -1;
|
||||
private double _lastGetDataTime;
|
||||
|
||||
#region 接口实现
|
||||
/// <summary>
|
||||
/// 请求地址
|
||||
/// </summary>
|
||||
public string URL { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否完成
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 每次调用都会主动轮询请求 PollingRequest
|
||||
/// </remarks>
|
||||
public bool IsDone
|
||||
{
|
||||
get
|
||||
{
|
||||
PollingRequest();
|
||||
return Status == EDownloadRequestStatus.Succeed
|
||||
|| Status == EDownloadRequestStatus.Failed
|
||||
|| Status == EDownloadRequestStatus.Aborted;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 请求状态
|
||||
/// </summary>
|
||||
public EDownloadRequestStatus Status { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// 当前下载进度(0f - 1f)
|
||||
/// </summary>
|
||||
public float DownloadProgress { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 当前请求已接收的字节数
|
||||
/// </summary>
|
||||
public long DownloadedBytes { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// HTTP 返回码
|
||||
/// </summary>
|
||||
public long HttpCode { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 错误信息
|
||||
/// </summary>
|
||||
public string Error { get; protected set; }
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// 构造下载器基类
|
||||
/// </summary>
|
||||
/// <param name="url">请求地址</param>
|
||||
/// <param name="webRequestCreator">UnityWebRequest 创建器(可选)</param>
|
||||
protected UnityWebRequestDownloaderBase(string url, UnityWebRequestDelegate webRequestCreator)
|
||||
{
|
||||
URL = url;
|
||||
_webRequestCreator = webRequestCreator;
|
||||
Status = EDownloadRequestStatus.None;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发起请求
|
||||
/// </summary>
|
||||
public void SendRequest()
|
||||
{
|
||||
if (Status == EDownloadRequestStatus.None)
|
||||
{
|
||||
Status = EDownloadRequestStatus.Running;
|
||||
|
||||
try
|
||||
{
|
||||
CreateWebRequest();
|
||||
|
||||
if (_webRequest == null)
|
||||
{
|
||||
Status = EDownloadRequestStatus.Failed;
|
||||
Error = $"[{GetType().Name}] Created web request is null.";
|
||||
}
|
||||
else
|
||||
{
|
||||
_webRequest.SendWebRequest();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Status = EDownloadRequestStatus.Failed;
|
||||
Error = $"[{GetType().Name}] Failed to create web request : {ex.Message}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 轮询请求
|
||||
/// </summary>
|
||||
public void PollingRequest()
|
||||
{
|
||||
if (Status != EDownloadRequestStatus.Running)
|
||||
return;
|
||||
|
||||
DownloadProgress = _webRequest.downloadProgress;
|
||||
DownloadedBytes = (long)_webRequest.downloadedBytes;
|
||||
|
||||
CheckWatchdog();
|
||||
if (_webRequest.isDone == false)
|
||||
return;
|
||||
|
||||
HttpCode = _webRequest.responseCode;
|
||||
#if UNITY_2020_3_OR_NEWER
|
||||
bool isSuccess = _webRequest.result == UnityWebRequest.Result.Success;
|
||||
#else
|
||||
bool isSuccess = !_webRequest.isNetworkError && !_webRequest.isHttpError;
|
||||
#endif
|
||||
|
||||
if (isSuccess)
|
||||
{
|
||||
Status = EDownloadRequestStatus.Succeed;
|
||||
OnRequestSucceed();
|
||||
}
|
||||
else
|
||||
{
|
||||
Status = EDownloadRequestStatus.Failed;
|
||||
Error = $"[{GetType().Name}] URL: {URL} - 错误: {_webRequest.error}";
|
||||
OnRequestFailed();
|
||||
}
|
||||
|
||||
// 完成后释放
|
||||
DisposeWebRequest();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 中止请求
|
||||
/// </summary>
|
||||
public void AbortRequest()
|
||||
{
|
||||
if (Status == EDownloadRequestStatus.None || Status == EDownloadRequestStatus.Running)
|
||||
{
|
||||
Status = EDownloadRequestStatus.Aborted;
|
||||
if (_webRequest != null)
|
||||
_webRequest.Abort();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 释放资源
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
DisposeWebRequest();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 创建 UnityWebRequest(子类实现)
|
||||
/// </summary>
|
||||
protected abstract void CreateWebRequest();
|
||||
|
||||
/// <summary>
|
||||
/// 请求成功时的回调(子类可重写)
|
||||
/// </summary>
|
||||
protected virtual void OnRequestSucceed()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 请求失败时的回调(子类可重写)
|
||||
/// </summary>
|
||||
protected virtual void OnRequestFailed()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 创建 UnityWebRequest GET 请求
|
||||
/// </summary>
|
||||
/// <param name="requestUrl">请求地址</param>
|
||||
/// <returns>UnityWebRequest 实例</returns>
|
||||
protected UnityWebRequest CreateUnityWebRequestGet(string requestUrl)
|
||||
{
|
||||
if (_webRequestCreator != null)
|
||||
return _webRequestCreator.Invoke(requestUrl);
|
||||
|
||||
return new UnityWebRequest(requestUrl, UnityWebRequest.kHttpVerbGET);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建 UnityWebRequest HEAD 请求
|
||||
/// </summary>
|
||||
/// <param name="requestUrl">请求地址</param>
|
||||
/// <returns>UnityWebRequest 实例</returns>
|
||||
protected UnityWebRequest CreateUnityWebRequestHead(string requestUrl)
|
||||
{
|
||||
return new UnityWebRequest(requestUrl, UnityWebRequest.kHttpVerbHEAD);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 应用通用请求参数
|
||||
/// </summary>
|
||||
protected void ApplyRequestOptions(int timeout, int watchdogTime, Dictionary<string, string> headers)
|
||||
{
|
||||
if (_webRequest == null)
|
||||
throw new YooInternalException("Web request is null !");
|
||||
|
||||
// 设置看门狗超时时间
|
||||
_watchdogTime = watchdogTime;
|
||||
|
||||
// 设置响应的超时时间
|
||||
if (timeout > 0)
|
||||
_webRequest.timeout = timeout;
|
||||
|
||||
// 设置响应头
|
||||
if (headers != null)
|
||||
{
|
||||
foreach (var header in headers)
|
||||
{
|
||||
_webRequest.SetRequestHeader(header.Key, header.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检测看门狗
|
||||
/// </summary>
|
||||
private void CheckWatchdog()
|
||||
{
|
||||
if (_watchdogTime == 0)
|
||||
return;
|
||||
if (_watchdogAborted)
|
||||
return;
|
||||
|
||||
#if UNITY_2020_3_OR_NEWER
|
||||
double realtimeSinceStartup = UnityEngine.Time.realtimeSinceStartupAsDouble;
|
||||
#else
|
||||
double realtimeSinceStartup = UnityEngine.Time.realtimeSinceStartup;
|
||||
#endif
|
||||
|
||||
if (DownloadedBytes != _lastDownloadBytes)
|
||||
{
|
||||
_lastDownloadBytes = DownloadedBytes;
|
||||
_lastGetDataTime = realtimeSinceStartup;
|
||||
}
|
||||
else
|
||||
{
|
||||
double deltaTime = realtimeSinceStartup - _lastGetDataTime;
|
||||
if (deltaTime > _watchdogTime)
|
||||
{
|
||||
_watchdogAborted = true;
|
||||
AbortRequest(); //看门狗终止网络请求
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 释放资源
|
||||
/// </summary>
|
||||
private void DisposeWebRequest()
|
||||
{
|
||||
if (_webRequest != null)
|
||||
{
|
||||
//注意:引擎底层会自动调用Abort方法
|
||||
_webRequest.Dispose();
|
||||
_webRequest = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 375d88bcf5b9a6146adaf98ceb5369f8
|
||||
guid: 76b0712524ed69542914db8e44fa64fd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
/// <summary>
|
||||
/// UnityWebRequest 文件下载器
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 将下载内容保存到本地文件,支持断点续传和追加写入。
|
||||
/// </remarks>
|
||||
internal sealed class UnityWebRequestFileDownloader : UnityWebRequestDownloaderBase, IDownloadFileRequest
|
||||
{
|
||||
private readonly DownloadFileRequestArgs _args;
|
||||
|
||||
/// <summary>
|
||||
/// 文件保存路径
|
||||
/// </summary>
|
||||
public string SavePath
|
||||
{
|
||||
get { return _args.SavePath; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 构造文件下载器
|
||||
/// </summary>
|
||||
/// <param name="args">文件下载参数</param>
|
||||
/// <param name="webRequestCreator">UnityWebRequest 创建器(可选)</param>
|
||||
public UnityWebRequestFileDownloader(DownloadFileRequestArgs args, UnityWebRequestDelegate webRequestCreator)
|
||||
: base(args.URL, webRequestCreator)
|
||||
{
|
||||
_args = args;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建 UnityWebRequest
|
||||
/// </summary>
|
||||
protected override void CreateWebRequest()
|
||||
{
|
||||
var handler = new DownloadHandlerFile(_args.SavePath, _args.AppendToFile);
|
||||
handler.removeFileOnAbort = _args.RemoveFileOnAbort;
|
||||
|
||||
_webRequest = CreateUnityWebRequestGet(URL);
|
||||
_webRequest.downloadHandler = handler;
|
||||
_webRequest.disposeDownloadHandlerOnDispose = true;
|
||||
|
||||
// 断点续传:设置 Range 请求头
|
||||
if (_args.ResumeFromBytes > 0)
|
||||
{
|
||||
_webRequest.SetRequestHeader("Range", $"bytes={_args.ResumeFromBytes}-");
|
||||
}
|
||||
|
||||
ApplyRequestOptions(_args.Timeout, _args.WatchdogTime, _args.Headers);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b7557eb146572de49a1ec9b3f3c0b706
|
||||
guid: 101a4be1bb0a85c4d84ecbf3e74f89e4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -0,0 +1,124 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
/// <summary>
|
||||
/// UnityWebRequest HEAD 请求下载器
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 仅获取响应头信息,不下载实际内容。
|
||||
/// 用于检查资源是否存在、获取资源大小、检查缓存有效性等场景。
|
||||
/// </remarks>
|
||||
internal sealed class UnityWebRequestHeadDownloader : UnityWebRequestDownloaderBase, IDownloadHeadRequest
|
||||
{
|
||||
// 注意:缓存响应头(因为 WebRequest 释放后无法获取)
|
||||
private Dictionary<string, string> _cachedResponseHeaders;
|
||||
private readonly DownloadDataRequestArgs _args;
|
||||
|
||||
/// <summary>
|
||||
/// 获取 ETag 响应头
|
||||
/// </summary>
|
||||
public string ETag
|
||||
{
|
||||
get { return GetResponseHeader("ETag"); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取 Last-Modified 响应头
|
||||
/// </summary>
|
||||
public string LastModified
|
||||
{
|
||||
get { return GetResponseHeader("Last-Modified"); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取 Content-Type 响应头
|
||||
/// </summary>
|
||||
public string ContentType
|
||||
{
|
||||
get { return GetResponseHeader("Content-Type"); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取 Content-Length 响应头
|
||||
/// 预期下载的总字节数
|
||||
/// </summary>
|
||||
public long ContentLength
|
||||
{
|
||||
get
|
||||
{
|
||||
string contentLengthStr = GetResponseHeader("Content-Length");
|
||||
if (string.IsNullOrEmpty(contentLengthStr))
|
||||
return -1;
|
||||
|
||||
if (long.TryParse(contentLengthStr, out long contentLength))
|
||||
{
|
||||
return contentLength;
|
||||
}
|
||||
else
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 构造 HEAD 请求下载器
|
||||
/// </summary>
|
||||
/// <param name="args">数据下载参数</param>
|
||||
/// <param name="webRequestCreator">UnityWebRequest 创建器(可选)</param>
|
||||
public UnityWebRequestHeadDownloader(DownloadDataRequestArgs args, UnityWebRequestDelegate webRequestCreator)
|
||||
: base(args.URL, webRequestCreator)
|
||||
{
|
||||
_args = args;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取响应头信息
|
||||
/// </summary>
|
||||
/// <param name="name">响应头名称(不区分大小写)</param>
|
||||
/// <returns>响应头的值,如果不存在或请求未完成则返回 null</returns>
|
||||
public string GetResponseHeader(string name)
|
||||
{
|
||||
if (_cachedResponseHeaders == null)
|
||||
return null;
|
||||
|
||||
// 注意:UnityWebRequest 的响应头 key 是小写的
|
||||
string lowerName = name.ToLowerInvariant();
|
||||
if (_cachedResponseHeaders.TryGetValue(lowerName, out string value))
|
||||
return value;
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建 UnityWebRequest
|
||||
/// </summary>
|
||||
protected override void CreateWebRequest()
|
||||
{
|
||||
_webRequest = CreateUnityWebRequestHead(URL);
|
||||
_webRequest.downloadHandler = null; // HEAD 请求不需要 DownloadHandler
|
||||
ApplyRequestOptions(_args.Timeout, _args.WatchdogTime, _args.Headers);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 请求成功时的回调
|
||||
/// </summary>
|
||||
protected override void OnRequestSucceed()
|
||||
{
|
||||
var headers = _webRequest.GetResponseHeaders();
|
||||
if (headers != null)
|
||||
{
|
||||
_cachedResponseHeaders = new Dictionary<string, string>(headers.Count, StringComparer.OrdinalIgnoreCase);
|
||||
foreach (var kvp in headers)
|
||||
{
|
||||
string name = kvp.Key.ToLowerInvariant();
|
||||
string value = kvp.Value;
|
||||
_cachedResponseHeaders[name] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8ed243d707130394aa85e20dee876d8e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using UnityEngine.Networking;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
/// <summary>
|
||||
/// UnityWebRequest 文本下载器
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 将下载内容解析为 UTF-8 文本字符串。
|
||||
/// </remarks>
|
||||
internal sealed class UnityWebRequestTextDownloader : UnityWebRequestDownloaderBase, IDownloadTextRequest
|
||||
{
|
||||
private readonly DownloadDataRequestArgs _args;
|
||||
|
||||
/// <summary>
|
||||
/// 下载结果(文本字符串)
|
||||
/// </summary>
|
||||
public string Result { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 构造文本下载器
|
||||
/// </summary>
|
||||
/// <param name="args">数据下载参数</param>
|
||||
/// <param name="webRequestCreator">UnityWebRequest 创建器(可选)</param>
|
||||
public UnityWebRequestTextDownloader(DownloadDataRequestArgs args, UnityWebRequestDelegate webRequestCreator)
|
||||
: base(args.URL, webRequestCreator)
|
||||
{
|
||||
_args = args;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建 UnityWebRequest
|
||||
/// </summary>
|
||||
protected override void CreateWebRequest()
|
||||
{
|
||||
var handler = new DownloadHandlerBuffer();
|
||||
_webRequest = CreateUnityWebRequestGet(URL);
|
||||
_webRequest.downloadHandler = handler;
|
||||
_webRequest.disposeDownloadHandlerOnDispose = true;
|
||||
ApplyRequestOptions(_args.Timeout, _args.WatchdogTime, _args.Headers);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 请求成功时的回调
|
||||
/// </summary>
|
||||
protected override void OnRequestSucceed()
|
||||
{
|
||||
var fileText = _webRequest.downloadHandler.text;
|
||||
if (string.IsNullOrEmpty(fileText))
|
||||
{
|
||||
Status = EDownloadRequestStatus.Failed;
|
||||
Error = $"[{GetType().Name}] URL: {URL} - Download text data is null or empty";
|
||||
}
|
||||
else
|
||||
{
|
||||
Result = fileText;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9b0bd3024ca5bae4dbdc05c7af7479df
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,149 @@
|
||||
using System;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
/// <summary>
|
||||
/// 模拟下载器
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 用于编辑器模式下模拟下载进度,不进行实际网络请求。
|
||||
/// 根据配置的下载速度模拟进度变化。
|
||||
/// </remarks>
|
||||
internal sealed class VirtualFileDownloader : IDownloadFileRequest
|
||||
{
|
||||
private readonly DownloadSimulateRequestArgs _args;
|
||||
private double _lastUpdateTime;
|
||||
|
||||
/// <summary>
|
||||
/// 文件保存路径(模拟下载不需要)
|
||||
/// </summary>
|
||||
public string SavePath
|
||||
{
|
||||
get { return null; }
|
||||
}
|
||||
|
||||
#region 接口实现
|
||||
/// <summary>
|
||||
/// 请求地址
|
||||
/// </summary>
|
||||
public string URL { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否完成
|
||||
/// </summary>
|
||||
public bool IsDone
|
||||
{
|
||||
get
|
||||
{
|
||||
PollingRequest();
|
||||
return Status == EDownloadRequestStatus.Succeed
|
||||
|| Status == EDownloadRequestStatus.Failed
|
||||
|| Status == EDownloadRequestStatus.Aborted;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 请求状态
|
||||
/// </summary>
|
||||
public EDownloadRequestStatus Status { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 当前下载进度(0f - 1f)
|
||||
/// </summary>
|
||||
public float DownloadProgress { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 当前请求已接收的字节数
|
||||
/// </summary>
|
||||
public long DownloadedBytes { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// HTTP 返回码(模拟固定返回 200)
|
||||
/// </summary>
|
||||
public long HttpCode { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 错误信息
|
||||
/// </summary>
|
||||
public string Error { get; private set; }
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// 构造模拟下载器
|
||||
/// </summary>
|
||||
/// <param name="args">模拟下载参数</param>
|
||||
public VirtualFileDownloader(DownloadSimulateRequestArgs args)
|
||||
{
|
||||
_args = args;
|
||||
Status = EDownloadRequestStatus.None;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发起请求
|
||||
/// </summary>
|
||||
public void SendRequest()
|
||||
{
|
||||
if (Status == EDownloadRequestStatus.None)
|
||||
{
|
||||
Status = EDownloadRequestStatus.Running;
|
||||
_lastUpdateTime = GetUnityEngineRealtime();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 轮询请求
|
||||
/// </summary>
|
||||
public void PollingRequest()
|
||||
{
|
||||
if (Status != EDownloadRequestStatus.Running)
|
||||
return;
|
||||
|
||||
double currentTime = GetUnityEngineRealtime();
|
||||
double deltaTime = currentTime - _lastUpdateTime;
|
||||
_lastUpdateTime = currentTime;
|
||||
|
||||
// 计算本帧下载的字节数
|
||||
long downloadBytes = (long)(_args.DownloadSpeed * deltaTime);
|
||||
DownloadedBytes += downloadBytes;
|
||||
|
||||
if (_args.FileSize > 0)
|
||||
DownloadProgress = (float)DownloadedBytes / _args.FileSize;
|
||||
|
||||
// 检查是否完成
|
||||
if (DownloadedBytes >= _args.FileSize)
|
||||
{
|
||||
HttpCode = 200;
|
||||
DownloadProgress = 1f;
|
||||
DownloadedBytes = _args.FileSize;
|
||||
Status = EDownloadRequestStatus.Succeed;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 中止请求
|
||||
/// </summary>
|
||||
public void AbortRequest()
|
||||
{
|
||||
if (Status == EDownloadRequestStatus.None || Status == EDownloadRequestStatus.Running)
|
||||
{
|
||||
Status = EDownloadRequestStatus.Aborted;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 释放资源
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
}
|
||||
|
||||
private double GetUnityEngineRealtime()
|
||||
{
|
||||
#if UNITY_2020_3_OR_NEWER
|
||||
return UnityEngine.Time.realtimeSinceStartupAsDouble;
|
||||
#else
|
||||
return = UnityEngine.Time.realtimeSinceStartup;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 84daeb1559aadff40b5b5aa5c81d7d64
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,118 +0,0 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
/// <summary>
|
||||
/// 下载器结束
|
||||
/// </summary>
|
||||
public struct DownloaderFinishData
|
||||
{
|
||||
/// <summary>
|
||||
/// 所属包裹名称
|
||||
/// </summary>
|
||||
public string PackageName;
|
||||
|
||||
/// <summary>
|
||||
/// 是否成功
|
||||
/// </summary>
|
||||
public bool Succeed;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 下载器相关的更新数据
|
||||
/// </summary>
|
||||
public struct DownloadUpdateData
|
||||
{
|
||||
/// <summary>
|
||||
/// 所属包裹名称
|
||||
/// </summary>
|
||||
public string PackageName;
|
||||
|
||||
/// <summary>
|
||||
/// 下载进度 (0-1f)
|
||||
/// </summary>
|
||||
public float Progress;
|
||||
|
||||
/// <summary>
|
||||
/// 下载文件总数
|
||||
/// </summary>
|
||||
public int TotalDownloadCount;
|
||||
|
||||
/// <summary>
|
||||
/// 当前完成的下载文件数量
|
||||
/// </summary>
|
||||
public int CurrentDownloadCount;
|
||||
|
||||
/// <summary>
|
||||
/// 下载数据总大小(单位:字节)
|
||||
/// </summary>
|
||||
public long TotalDownloadBytes;
|
||||
|
||||
/// <summary>
|
||||
/// 当前完成的下载数据大小(单位:字节)
|
||||
/// </summary>
|
||||
public long CurrentDownloadBytes;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 下载器相关的错误数据
|
||||
/// </summary>
|
||||
public struct DownloadErrorData
|
||||
{
|
||||
/// <summary>
|
||||
/// 所属包裹名称
|
||||
/// </summary>
|
||||
public string PackageName;
|
||||
|
||||
/// <summary>
|
||||
/// 下载失败的文件名称
|
||||
/// </summary>
|
||||
public string FileName;
|
||||
|
||||
/// <summary>
|
||||
/// 错误信息
|
||||
/// </summary>
|
||||
public string ErrorInfo;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 下载器相关的文件数据
|
||||
/// </summary>
|
||||
public struct DownloadFileData
|
||||
{
|
||||
/// <summary>
|
||||
/// 所属包裹名称
|
||||
/// </summary>
|
||||
public string PackageName;
|
||||
|
||||
/// <summary>
|
||||
/// 下载的文件名称
|
||||
/// </summary>
|
||||
public string FileName;
|
||||
|
||||
/// <summary>
|
||||
/// 下载的文件大小
|
||||
/// </summary>
|
||||
public long FileSize;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 导入文件的信息
|
||||
/// </summary>
|
||||
public struct ImportFileInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// 本地文件路径
|
||||
/// </summary>
|
||||
public string FilePath;
|
||||
|
||||
/// <summary>
|
||||
/// 资源包名称
|
||||
/// </summary>
|
||||
public string BundleName;
|
||||
|
||||
/// <summary>
|
||||
/// 资源包GUID
|
||||
/// </summary>
|
||||
public string BundleGUID;
|
||||
}
|
||||
}
|
||||
443
Assets/YooAsset/Runtime/DownloadSystem/DownloadSystemDefine.cs
Normal file
443
Assets/YooAsset/Runtime/DownloadSystem/DownloadSystemDefine.cs
Normal file
@@ -0,0 +1,443 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
/// <summary>
|
||||
/// 下载器结束
|
||||
/// </summary>
|
||||
public struct DownloaderFinishData
|
||||
{
|
||||
/// <summary>
|
||||
/// 所属包裹名称
|
||||
/// </summary>
|
||||
public string PackageName;
|
||||
|
||||
/// <summary>
|
||||
/// 是否成功
|
||||
/// </summary>
|
||||
public bool Succeed;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 下载器相关的更新数据
|
||||
/// </summary>
|
||||
public struct DownloadUpdateData
|
||||
{
|
||||
/// <summary>
|
||||
/// 所属包裹名称
|
||||
/// </summary>
|
||||
public string PackageName;
|
||||
|
||||
/// <summary>
|
||||
/// 下载进度 (0-1f)
|
||||
/// </summary>
|
||||
public float Progress;
|
||||
|
||||
/// <summary>
|
||||
/// 下载文件总数
|
||||
/// </summary>
|
||||
public int TotalDownloadCount;
|
||||
|
||||
/// <summary>
|
||||
/// 当前完成的下载文件数量
|
||||
/// </summary>
|
||||
public int CurrentDownloadCount;
|
||||
|
||||
/// <summary>
|
||||
/// 下载数据总大小(单位:字节)
|
||||
/// </summary>
|
||||
public long TotalDownloadBytes;
|
||||
|
||||
/// <summary>
|
||||
/// 当前完成的下载数据大小(单位:字节)
|
||||
/// </summary>
|
||||
public long CurrentDownloadBytes;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 下载器相关的错误数据
|
||||
/// </summary>
|
||||
public struct DownloadErrorData
|
||||
{
|
||||
/// <summary>
|
||||
/// 所属包裹名称
|
||||
/// </summary>
|
||||
public string PackageName;
|
||||
|
||||
/// <summary>
|
||||
/// 下载失败的文件名称
|
||||
/// </summary>
|
||||
public string FileName;
|
||||
|
||||
/// <summary>
|
||||
/// 错误信息
|
||||
/// </summary>
|
||||
public string ErrorInfo;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 下载器相关的文件数据
|
||||
/// </summary>
|
||||
public struct DownloadFileData
|
||||
{
|
||||
/// <summary>
|
||||
/// 所属包裹名称
|
||||
/// </summary>
|
||||
public string PackageName;
|
||||
|
||||
/// <summary>
|
||||
/// 下载的文件名称
|
||||
/// </summary>
|
||||
public string FileName;
|
||||
|
||||
/// <summary>
|
||||
/// 下载的文件大小
|
||||
/// </summary>
|
||||
public long FileSize;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 导入文件的信息
|
||||
/// </summary>
|
||||
public struct ImportFileInfo
|
||||
{
|
||||
/// <summary>
|
||||
/// 本地文件路径
|
||||
/// </summary>
|
||||
public string FilePath;
|
||||
|
||||
/// <summary>
|
||||
/// 资源包名称
|
||||
/// </summary>
|
||||
public string BundleName;
|
||||
|
||||
/// <summary>
|
||||
/// 资源包GUID
|
||||
/// </summary>
|
||||
public string BundleGUID;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 下载请求状态
|
||||
/// </summary>
|
||||
internal enum EDownloadRequestStatus
|
||||
{
|
||||
/// <summary>
|
||||
/// 未开始
|
||||
/// </summary>
|
||||
None,
|
||||
|
||||
/// <summary>
|
||||
/// 进行中
|
||||
/// </summary>
|
||||
Running,
|
||||
|
||||
/// <summary>
|
||||
/// 已成功
|
||||
/// </summary>
|
||||
Succeed,
|
||||
|
||||
/// <summary>
|
||||
/// 已失败
|
||||
/// </summary>
|
||||
Failed,
|
||||
|
||||
/// <summary>
|
||||
/// 已中止
|
||||
/// </summary>
|
||||
Aborted,
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 文件下载请求参数
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 用于将下载内容保存到本地文件的请求配置。
|
||||
/// 支持断点续传和追加写入模式。
|
||||
/// </remarks>
|
||||
internal struct DownloadFileRequestArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// 请求地址
|
||||
/// </summary>
|
||||
public readonly string URL;
|
||||
|
||||
/// <summary>
|
||||
/// 响应的超时时间(单位:秒)
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 当 Timeout 设置为 0 时,不应用超时。
|
||||
/// 设置的超时值可能应用于Android上的每个URL重定向,这可能会导致响应时间增加。
|
||||
/// </remarks>
|
||||
public readonly int Timeout;
|
||||
|
||||
/// <summary>
|
||||
/// 看门狗超时时间(单位:秒)
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 用于监控下载任务的数据接收情况。
|
||||
/// 规则说明:
|
||||
/// 1. 当设置值为 0 时,表示禁用看门狗监控。
|
||||
/// 2. 每次接收到下载数据时,看门狗计时器会重置。
|
||||
/// 3. 若在设定的时间范围内未收到任何数据,任务将被自动终止。
|
||||
/// </remarks>
|
||||
public readonly int WatchdogTime;
|
||||
|
||||
/// <summary>
|
||||
/// 文件保存路径
|
||||
/// </summary>
|
||||
public readonly string SavePath;
|
||||
|
||||
/// <summary>
|
||||
/// 是否追加写入文件
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 配合 ResumeFromBytes 使用,用于断点续传场景。
|
||||
/// </remarks>
|
||||
public readonly bool AppendToFile;
|
||||
|
||||
/// <summary>
|
||||
/// 中止请求时是否删除目标文件
|
||||
/// </summary>
|
||||
public readonly bool RemoveFileOnAbort;
|
||||
|
||||
/// <summary>
|
||||
/// 断点续传的起始字节(小于等于 0 表示不启用)
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 推荐由后端自动设置 Range 请求头:"bytes={ResumeFromBytes}-"。
|
||||
/// </remarks>
|
||||
public readonly long ResumeFromBytes;
|
||||
|
||||
/// <summary>
|
||||
/// 自定义请求头(可选)
|
||||
/// </summary>
|
||||
public Dictionary<string, string> Headers;
|
||||
|
||||
/// <summary>
|
||||
/// 构造文件下载请求参数
|
||||
/// </summary>
|
||||
public DownloadFileRequestArgs(
|
||||
string url,
|
||||
string savePath,
|
||||
int timeout,
|
||||
int watchdogTime,
|
||||
bool appendToFile = false,
|
||||
bool removeFileOnAbort = true,
|
||||
long resumeFromBytes = 0)
|
||||
{
|
||||
URL = url;
|
||||
SavePath = savePath;
|
||||
Timeout = timeout;
|
||||
WatchdogTime = watchdogTime;
|
||||
AppendToFile = appendToFile;
|
||||
RemoveFileOnAbort = removeFileOnAbort;
|
||||
ResumeFromBytes = resumeFromBytes;
|
||||
Headers = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加请求头数据
|
||||
/// </summary>
|
||||
public void AddRequestHeader(string name, string value)
|
||||
{
|
||||
if (Headers == null)
|
||||
Headers = new Dictionary<string, string>(10);
|
||||
Headers.Add(name, value);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 数据下载请求参数(通用)
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 用于下载到内存的请求配置。
|
||||
/// 可用于字节数组(bytes)或文本(text)下载。
|
||||
/// </remarks>
|
||||
internal struct DownloadDataRequestArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// 请求地址
|
||||
/// </summary>
|
||||
public readonly string URL;
|
||||
|
||||
/// <summary>
|
||||
/// 响应的超时时间(单位:秒)
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 当 Timeout 设置为 0 时,不应用超时。
|
||||
/// 设置的超时值可能应用于Android上的每个URL重定向,这可能会导致响应时间增加。
|
||||
/// </remarks>
|
||||
public readonly int Timeout;
|
||||
|
||||
/// <summary>
|
||||
/// 看门狗超时时间(单位:秒)
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 用于监控下载任务的数据接收情况。
|
||||
/// 规则说明:
|
||||
/// 1. 当设置值为 0 时,表示禁用看门狗监控。
|
||||
/// 2. 每次接收到下载数据时,看门狗计时器会重置。
|
||||
/// 3. 若在设定的时间范围内未收到任何数据,任务将被自动终止。
|
||||
/// </remarks>
|
||||
public readonly int WatchdogTime;
|
||||
|
||||
/// <summary>
|
||||
/// 自定义请求头(可选)
|
||||
/// </summary>
|
||||
public Dictionary<string, string> Headers;
|
||||
|
||||
/// <summary>
|
||||
/// 构造数据下载请求参数
|
||||
/// </summary>
|
||||
/// <param name="url">请求地址</param>
|
||||
/// <param name="options">通用请求参数</param>
|
||||
public DownloadDataRequestArgs(string url, int timeout, int watchdogTime)
|
||||
{
|
||||
URL = url;
|
||||
Timeout = timeout;
|
||||
WatchdogTime = watchdogTime;
|
||||
Headers = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加请求头数据
|
||||
/// </summary>
|
||||
public void AddRequestHeader(string name, string value)
|
||||
{
|
||||
if (Headers == null)
|
||||
Headers = new Dictionary<string, string>(10);
|
||||
Headers.Add(name, value);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// AssetBundle 下载请求参数
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 用于下载并加载 Unity AssetBundle 的请求配置。
|
||||
/// 支持 Unity 内置缓存机制和 CRC 校验。
|
||||
/// </remarks>
|
||||
internal struct DownloadAssetBundleRequestArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// 请求地址
|
||||
/// </summary>
|
||||
public readonly string URL;
|
||||
|
||||
/// <summary>
|
||||
/// 响应的超时时间(单位:秒)
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 当 Timeout 设置为 0 时,不应用超时。
|
||||
/// 设置的超时值可能应用于Android上的每个URL重定向,这可能会导致响应时间增加。
|
||||
/// </remarks>
|
||||
public readonly int Timeout;
|
||||
|
||||
/// <summary>
|
||||
/// 看门狗超时时间(单位:秒)
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 用于监控下载任务的数据接收情况。
|
||||
/// 规则说明:
|
||||
/// 1. 当设置值为 0 时,表示禁用看门狗监控。
|
||||
/// 2. 每次接收到下载数据时,看门狗计时器会重置。
|
||||
/// 3. 若在设定的时间范围内未收到任何数据,任务将被自动终止。
|
||||
/// </remarks>
|
||||
public readonly int WatchdogTime;
|
||||
|
||||
/// <summary>
|
||||
/// 禁用 Unity 的网络缓存
|
||||
/// </summary>
|
||||
public readonly bool DisableUnityWebCache;
|
||||
|
||||
/// <summary>
|
||||
/// AssetBundle 文件哈希(用于 UnityWebRequest 的缓存)
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 仅当 DisableUnityWebCache 为 false 时需要。
|
||||
/// </remarks>
|
||||
public readonly string FileHash;
|
||||
|
||||
/// <summary>
|
||||
/// Unity CRC 校验值
|
||||
/// </summary>
|
||||
public readonly uint UnityCRC;
|
||||
|
||||
/// <summary>
|
||||
/// 自定义请求头(可选)
|
||||
/// </summary>
|
||||
public Dictionary<string, string> Headers;
|
||||
|
||||
/// <summary>
|
||||
/// 构造 AssetBundle 下载请求参数
|
||||
/// </summary>
|
||||
public DownloadAssetBundleRequestArgs(
|
||||
string url,
|
||||
int timeout,
|
||||
int watchdogTime,
|
||||
bool disableUnityWebCache = true,
|
||||
string fileHash = null,
|
||||
uint unityCrc = 0)
|
||||
{
|
||||
URL = url;
|
||||
Timeout = timeout;
|
||||
WatchdogTime = watchdogTime;
|
||||
DisableUnityWebCache = disableUnityWebCache;
|
||||
FileHash = fileHash;
|
||||
UnityCRC = unityCrc;
|
||||
Headers = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加请求头数据
|
||||
/// </summary>
|
||||
public void AddRequestHeader(string name, string value)
|
||||
{
|
||||
if (Headers == null)
|
||||
Headers = new Dictionary<string, string>(10);
|
||||
Headers.Add(name, value);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 模拟下载请求参数
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 用于编辑器模式下模拟下载进度,不进行实际网络请求。
|
||||
/// </remarks>
|
||||
internal struct DownloadSimulateRequestArgs
|
||||
{
|
||||
/// <summary>
|
||||
/// 请求地址(仅用于标识)
|
||||
/// </summary>
|
||||
public readonly string URL;
|
||||
|
||||
/// <summary>
|
||||
/// 模拟的文件大小(字节)
|
||||
/// </summary>
|
||||
public readonly long FileSize;
|
||||
|
||||
/// <summary>
|
||||
/// 模拟的下载速度(字节/秒)
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 用于计算模拟的下载进度。
|
||||
/// </remarks>
|
||||
public readonly long DownloadSpeed;
|
||||
|
||||
/// <summary>
|
||||
/// 构造模拟下载请求参数
|
||||
/// </summary>
|
||||
/// <param name="url">请求地址(仅用于标识)</param>
|
||||
/// <param name="fileSize">模拟的文件大小(字节)</param>
|
||||
/// <param name="downloadSpeed">模拟的下载速度(字节/秒),默认 1MB/s</param>
|
||||
public DownloadSimulateRequestArgs(string url, long fileSize, long downloadSpeed = 1024 * 1024)
|
||||
{
|
||||
URL = url;
|
||||
FileSize = fileSize;
|
||||
DownloadSpeed = downloadSpeed > 0 ? downloadSpeed : 1024 * 1024;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eb0480e877454f7c944f66a01646b6d4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -37,13 +37,17 @@ namespace YooAsset
|
||||
string url;
|
||||
|
||||
// 获取对应平台的URL地址
|
||||
// 说明:苹果不同设备上操作系统不同。
|
||||
// 说明:iPhone和iPod对应的是iOS系统。
|
||||
// 说明:iPad对应的是iPadOS系统。
|
||||
// 说明:AppleTV对应的是tvOS系统。
|
||||
#if UNITY_EDITOR_OSX
|
||||
url = StringUtility.Format("file://{0}", path);
|
||||
#elif UNITY_EDITOR
|
||||
#elif UNITY_EDITOR_WIN
|
||||
url = StringUtility.Format("file:///{0}", path);
|
||||
#elif UNITY_WEBGL
|
||||
url = path;
|
||||
#elif UNITY_IPHONE
|
||||
#elif UNITY_IOS || UNITY_IPHONE
|
||||
url = StringUtility.Format("file://{0}", path);
|
||||
#elif UNITY_ANDROID
|
||||
if (path.StartsWith("jar:file://"))
|
||||
@@ -65,12 +69,17 @@ namespace YooAsset
|
||||
else
|
||||
url = StringUtility.Format("file://{0}", path);
|
||||
}
|
||||
#elif UNITY_STANDALONE_OSX
|
||||
url = new System.Uri(path).ToString();
|
||||
#elif UNITY_STANDALONE || UNITY_WSA
|
||||
|
||||
#elif UNITY_WSA
|
||||
url = StringUtility.Format("file:///{0}", path);
|
||||
#elif UNITY_TVOS
|
||||
url = StringUtility.Format("file:///{0}", path);
|
||||
#elif UNITY_STANDALONE_OSX
|
||||
url = new System.Uri(path).ToString();
|
||||
#elif UNITY_STANDALONE_WIN
|
||||
url = StringUtility.Format("file:///{0}", path);
|
||||
#elif UNITY_STANDALONE_LINUX
|
||||
url = StringUtility.Format("file:///root/{0}", path);
|
||||
#else
|
||||
throw new System.NotImplementedException();
|
||||
#endif
|
||||
@@ -85,8 +94,12 @@ namespace YooAsset
|
||||
public static bool IsRequestLocalFile(string url)
|
||||
{
|
||||
//TODO UNITY_STANDALONE_OSX平台目前无法确定
|
||||
|
||||
// 本地文件传输协议
|
||||
if (url.StartsWith("file:"))
|
||||
return true;
|
||||
|
||||
// JAR文件协议
|
||||
if (url.StartsWith("jar:file:"))
|
||||
return true;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4630dac2050606043bb146325fdce6ad
|
||||
guid: d724672f4d6f24b4db435d10eef6c40d
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
@@ -0,0 +1,78 @@
|
||||
using System;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
/// <summary>
|
||||
/// 下载后台接口
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 不同网络库(UnityWebRequest / BestHTTP / 自研)实现该接口,用于创建具体下载请求。
|
||||
/// 每个后台实例是独立的,不共享全局状态。
|
||||
/// </remarks>
|
||||
internal interface IDownloadBackend : IDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// 后台名称(用于日志与调试)
|
||||
/// </summary>
|
||||
string Name { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 驱动更新
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 部分第三方网络库需要在 Unity 主线程中周期性调用 Update 进行驱动。
|
||||
/// 不需要驱动的后台可实现为空方法。
|
||||
/// </remarks>
|
||||
void Update();
|
||||
|
||||
/// <summary>
|
||||
/// 创建 HEAD 请求
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 仅获取响应头信息,不下载实际内容。
|
||||
/// 用于检查资源是否存在、获取资源大小、检查缓存有效性等场景。
|
||||
/// </remarks>
|
||||
/// <param name="args">数据请求参数</param>
|
||||
/// <returns>HEAD 请求实例</returns>
|
||||
IDownloadHeadRequest CreateHeadRequest(DownloadDataRequestArgs args);
|
||||
|
||||
/// <summary>
|
||||
/// 创建文件下载请求
|
||||
/// </summary>
|
||||
/// <param name="args">文件下载参数</param>
|
||||
/// <returns>文件下载请求实例</returns>
|
||||
IDownloadFileRequest CreateFileRequest(DownloadFileRequestArgs args);
|
||||
|
||||
/// <summary>
|
||||
/// 创建内存下载请求(字节数组)
|
||||
/// </summary>
|
||||
/// <param name="args">数据下载参数</param>
|
||||
/// <returns>字节下载请求实例</returns>
|
||||
IDownloadBytesRequest CreateBytesRequest(DownloadDataRequestArgs args);
|
||||
|
||||
/// <summary>
|
||||
/// 创建文本下载请求
|
||||
/// </summary>
|
||||
/// <param name="args">数据下载参数</param>
|
||||
/// <returns>文本下载请求实例</returns>
|
||||
IDownloadTextRequest CreateTextRequest(DownloadDataRequestArgs args);
|
||||
|
||||
/// <summary>
|
||||
/// 创建 AssetBundle 下载请求
|
||||
/// </summary>
|
||||
/// <param name="args">AssetBundle 下载参数</param>
|
||||
/// <returns>AssetBundle 下载请求实例</returns>
|
||||
IDownloadAssetBundleRequest CreateAssetBundleRequest(DownloadAssetBundleRequestArgs args);
|
||||
|
||||
/// <summary>
|
||||
/// 创建模拟下载请求
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 用于编辑器模式下模拟下载进度,不进行实际网络请求。
|
||||
/// 可用于测试下载流程和 UI 展示。
|
||||
/// </remarks>
|
||||
/// <param name="args">模拟下载参数</param>
|
||||
/// <returns>模拟下载请求实例</returns>
|
||||
IDownloadFileRequest CreateSimulateRequest(DownloadSimulateRequestArgs args);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e88c026ebbfb40258aad52ad1c2feb70
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,194 @@
|
||||
using System;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
/// <summary>
|
||||
/// 可轮询的下载请求接口
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 上层通常会在每帧轮询 Status IsDone,并在完成后读取结果。
|
||||
/// </remarks>
|
||||
internal interface IDownloadRequest : IDisposable
|
||||
{
|
||||
/// <summary>
|
||||
/// 请求地址
|
||||
/// </summary>
|
||||
string URL { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 是否完成(成功/失败/中止)
|
||||
/// </summary>
|
||||
bool IsDone { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 请求状态
|
||||
/// </summary>
|
||||
EDownloadRequestStatus Status { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 当前下载进度(0f - 1f)
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 部分情况下无法准确获取总长度,可返回 0。
|
||||
/// </remarks>
|
||||
float DownloadProgress { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 当前请求已接收的字节数
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 断点续传场景下,该值仅表示"本次请求新增下载的字节数",不包含已存在的本地文件长度。
|
||||
/// </remarks>
|
||||
long DownloadedBytes { get; }
|
||||
|
||||
/// <summary>
|
||||
/// HTTP 返回码
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 非 HTTP 协议可返回 0。使用 long 类型以兼容各种协议的返回码。
|
||||
/// </remarks>
|
||||
long HttpCode { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 错误信息
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 失败时不为空。
|
||||
/// </remarks>
|
||||
string Error { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 发起请求
|
||||
/// </summary>
|
||||
void SendRequest();
|
||||
|
||||
/// <summary>
|
||||
/// 轮询请求
|
||||
/// </summary>
|
||||
void PollingRequest();
|
||||
|
||||
/// <summary>
|
||||
/// 中止请求
|
||||
/// </summary>
|
||||
void AbortRequest();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// HEAD 请求接口(仅获取响应头)
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 用于检查资源是否存在、获取资源大小、检查缓存有效性等场景。
|
||||
/// 不下载实际内容,仅获取响应头信息。
|
||||
/// </remarks>
|
||||
internal interface IDownloadHeadRequest : IDownloadRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取 ETag 响应头
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 用于缓存验证,如果服务器未返回则为 null。
|
||||
/// </remarks>
|
||||
string ETag { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取 Last-Modified 响应头
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 资源最后修改时间,如果服务器未返回则为 null。
|
||||
/// </remarks>
|
||||
string LastModified { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取 Content-Type 响应头
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 资源的 MIME 类型,如果服务器未返回则为 null。
|
||||
/// </remarks>
|
||||
string ContentType { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 预期下载的总字节数(Content-Length)
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 从响应头 Content-Length 获取。
|
||||
/// 如果服务器未返回或请求未完成,返回 -1。
|
||||
/// 用于更准确的进度计算。
|
||||
/// </remarks>
|
||||
long ContentLength { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取响应头信息
|
||||
/// </summary>
|
||||
/// <param name="name">响应头名称(不区分大小写)</param>
|
||||
/// <returns>响应头的值,如果不存在或请求未完成则返回 null</returns>
|
||||
/// <remarks>
|
||||
/// 常用响应头:Content-Length、Content-Type、ETag、Last-Modified 等。
|
||||
/// </remarks>
|
||||
string GetResponseHeader(string name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 文件下载请求接口
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 将下载内容保存到指定的本地文件路径。
|
||||
/// </remarks>
|
||||
internal interface IDownloadFileRequest : IDownloadRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// 文件保存路径
|
||||
/// </summary>
|
||||
string SavePath { get; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 内存下载请求接口(字节数组)
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 将下载内容保存到内存中的字节数组。
|
||||
/// </remarks>
|
||||
internal interface IDownloadBytesRequest : IDownloadRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// 下载结果(字节数组)
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 仅在请求成功时可用,失败时为 null。
|
||||
/// </remarks>
|
||||
byte[] Result { get; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 文本下载请求接口
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 将下载内容解析为 UTF-8 文本字符串。
|
||||
/// </remarks>
|
||||
internal interface IDownloadTextRequest : IDownloadRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// 下载结果(文本字符串)
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 仅在请求成功时可用,失败时为 null。
|
||||
/// </remarks>
|
||||
string Result { get; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// AssetBundle 下载请求接口
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 下载并加载 Unity AssetBundle 资源包。
|
||||
/// </remarks>
|
||||
internal interface IDownloadAssetBundleRequest : IDownloadRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// 下载结果(AssetBundle 对象)
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 仅在请求成功时可用,失败时为 null。
|
||||
/// </remarks>
|
||||
UnityEngine.AssetBundle Result { get; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2a2aafeb309243f4959394a97d66b19f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,113 +0,0 @@
|
||||
using UnityEngine.Networking;
|
||||
using UnityEngine;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class UnityAssetBundleRequestOperation : UnityWebRequestOperation
|
||||
{
|
||||
protected enum ESteps
|
||||
{
|
||||
None,
|
||||
CreateRequest,
|
||||
Download,
|
||||
Done,
|
||||
}
|
||||
|
||||
private UnityWebRequestAsyncOperation _requestOperation;
|
||||
private DownloadHandlerAssetBundle _downloadhandler;
|
||||
private readonly PackageBundle _packageBundle;
|
||||
private readonly bool _disableUnityWebCache;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
/// <summary>
|
||||
/// 请求结果
|
||||
/// </summary>
|
||||
public AssetBundle Result { private set; get; }
|
||||
|
||||
internal UnityAssetBundleRequestOperation(PackageBundle packageBundle, bool disableUnityWebCache, string url) : base(url)
|
||||
{
|
||||
_packageBundle = packageBundle;
|
||||
_disableUnityWebCache = disableUnityWebCache;
|
||||
}
|
||||
internal override void InternalStart()
|
||||
{
|
||||
_steps = ESteps.CreateRequest;
|
||||
}
|
||||
internal override void InternalUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.CreateRequest)
|
||||
{
|
||||
CreateWebRequest();
|
||||
_steps = ESteps.Download;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.Download)
|
||||
{
|
||||
DownloadProgress = _webRequest.downloadProgress;
|
||||
DownloadedBytes = (long)_webRequest.downloadedBytes;
|
||||
Progress = _requestOperation.progress;
|
||||
if (_requestOperation.isDone == false)
|
||||
return;
|
||||
|
||||
if (CheckRequestResult())
|
||||
{
|
||||
AssetBundle assetBundle = _downloadhandler.assetBundle;
|
||||
if (assetBundle == null)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"URL : {_requestURL} Download handler asset bundle object is null !";
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Result = assetBundle;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
}
|
||||
|
||||
// 注意:最终释放请求器
|
||||
DisposeRequest();
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateWebRequest()
|
||||
{
|
||||
_downloadhandler = CreateWebDownloadHandler();
|
||||
_webRequest = DownloadSystemHelper.NewUnityWebRequestGet(_requestURL);
|
||||
_webRequest.downloadHandler = _downloadhandler;
|
||||
_webRequest.disposeDownloadHandlerOnDispose = true;
|
||||
_requestOperation = _webRequest.SendWebRequest();
|
||||
}
|
||||
private DownloadHandlerAssetBundle CreateWebDownloadHandler()
|
||||
{
|
||||
if (_disableUnityWebCache)
|
||||
{
|
||||
var downloadhandler = new DownloadHandlerAssetBundle(_requestURL, _packageBundle.UnityCRC);
|
||||
#if UNITY_2020_3_OR_NEWER
|
||||
downloadhandler.autoLoadAssetBundle = false;
|
||||
#endif
|
||||
return downloadhandler;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 注意:优先从浏览器缓存里获取文件
|
||||
// The file hash defining the version of the asset bundle.
|
||||
Hash128 fileHash = Hash128.Parse(_packageBundle.FileHash);
|
||||
var downloadhandler = new DownloadHandlerAssetBundle(_requestURL, fileHash, _packageBundle.UnityCRC);
|
||||
#if UNITY_2020_3_OR_NEWER
|
||||
downloadhandler.autoLoadAssetBundle = false;
|
||||
#endif
|
||||
return downloadhandler;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,89 +0,0 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine.Networking;
|
||||
using UnityEngine;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class UnityWebCacheRequestOperation : UnityWebRequestOperation
|
||||
{
|
||||
protected enum ESteps
|
||||
{
|
||||
None,
|
||||
CreateRequest,
|
||||
Download,
|
||||
Done,
|
||||
}
|
||||
|
||||
private UnityWebRequestAsyncOperation _requestOperation;
|
||||
private readonly Dictionary<string, string> _headers = new Dictionary<string, string>();
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
|
||||
internal UnityWebCacheRequestOperation(string url) : base(url)
|
||||
{
|
||||
}
|
||||
internal override void InternalStart()
|
||||
{
|
||||
_steps = ESteps.CreateRequest;
|
||||
}
|
||||
internal override void InternalUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.CreateRequest)
|
||||
{
|
||||
CreateWebRequest();
|
||||
_steps = ESteps.Download;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.Download)
|
||||
{
|
||||
DownloadProgress = _webRequest.downloadProgress;
|
||||
DownloadedBytes = (long)_webRequest.downloadedBytes;
|
||||
Progress = _requestOperation.progress;
|
||||
if (_requestOperation.isDone == false)
|
||||
return;
|
||||
|
||||
if (CheckRequestResult())
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
}
|
||||
|
||||
// 注意:最终释放请求器
|
||||
DisposeRequest();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置请求头信息
|
||||
/// </summary>
|
||||
public void SetRequestHeader(string name, string value)
|
||||
{
|
||||
_headers.Add(name, value);
|
||||
}
|
||||
|
||||
private void CreateWebRequest()
|
||||
{
|
||||
_webRequest = DownloadSystemHelper.NewUnityWebRequestGet(_requestURL);
|
||||
_webRequest.disposeDownloadHandlerOnDispose = true;
|
||||
|
||||
// 设置消息头
|
||||
foreach (var keyValuePair in _headers)
|
||||
{
|
||||
string name = keyValuePair.Key;
|
||||
string value = keyValuePair.Value;
|
||||
_webRequest.SetRequestHeader(name, value);
|
||||
}
|
||||
|
||||
_requestOperation = _webRequest.SendWebRequest();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,83 +0,0 @@
|
||||
using UnityEngine.Networking;
|
||||
using UnityEngine;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class UnityWebFileRequestOperation : UnityWebRequestOperation
|
||||
{
|
||||
protected enum ESteps
|
||||
{
|
||||
None,
|
||||
CreateRequest,
|
||||
Download,
|
||||
Done,
|
||||
}
|
||||
|
||||
private UnityWebRequestAsyncOperation _requestOperation;
|
||||
private readonly string _fileSavePath;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
/// <summary>
|
||||
/// 响应的超时时间(单位:秒),在经过Timeout的秒数后尝试中止。
|
||||
/// 注意:当Timeout设置为0时,不会应用超时。
|
||||
/// 注意:设置的超时值可能应用于Android上的每个URL重定向,这可能会导致响应时间增加。
|
||||
/// </summary>
|
||||
private readonly int _timeout;
|
||||
|
||||
|
||||
internal UnityWebFileRequestOperation(string url, string fileSavePath, int timeout) : base(url)
|
||||
{
|
||||
_fileSavePath = fileSavePath;
|
||||
_timeout = timeout;
|
||||
}
|
||||
internal override void InternalStart()
|
||||
{
|
||||
_steps = ESteps.CreateRequest;
|
||||
}
|
||||
internal override void InternalUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.CreateRequest)
|
||||
{
|
||||
CreateWebRequest();
|
||||
_steps = ESteps.Download;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.Download)
|
||||
{
|
||||
DownloadProgress = _webRequest.downloadProgress;
|
||||
DownloadedBytes = (long)_webRequest.downloadedBytes;
|
||||
Progress = _requestOperation.progress;
|
||||
if (_requestOperation.isDone == false)
|
||||
return;
|
||||
|
||||
if (CheckRequestResult())
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
}
|
||||
|
||||
// 注意:最终释放请求器
|
||||
DisposeRequest();
|
||||
}
|
||||
}
|
||||
|
||||
private void CreateWebRequest()
|
||||
{
|
||||
DownloadHandlerFile handler = new DownloadHandlerFile(_fileSavePath);
|
||||
handler.removeFileOnAbort = true;
|
||||
_webRequest = DownloadSystemHelper.NewUnityWebRequestGet(_requestURL);
|
||||
_webRequest.timeout = _timeout;
|
||||
_webRequest.downloadHandler = handler;
|
||||
_webRequest.disposeDownloadHandlerOnDispose = true;
|
||||
_requestOperation = _webRequest.SendWebRequest();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2ab5f2486d06e2642ba7aa9c9623430e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,98 +0,0 @@
|
||||
using System;
|
||||
using UnityEngine.Networking;
|
||||
using UnityEngine;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal abstract class UnityWebRequestOperation : AsyncOperationBase
|
||||
{
|
||||
protected UnityWebRequest _webRequest;
|
||||
protected readonly string _requestURL;
|
||||
private bool _isAbort = false;
|
||||
|
||||
/// <summary>
|
||||
/// HTTP返回码
|
||||
/// </summary>
|
||||
public long HttpCode { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 当前下载的字节数
|
||||
/// </summary>
|
||||
public long DownloadedBytes { protected set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 当前下载进度(0f - 1f)
|
||||
/// </summary>
|
||||
public float DownloadProgress { protected set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 请求的URL地址
|
||||
/// </summary>
|
||||
public string URL
|
||||
{
|
||||
get { return _requestURL; }
|
||||
}
|
||||
|
||||
internal UnityWebRequestOperation(string url)
|
||||
{
|
||||
_requestURL = url;
|
||||
}
|
||||
internal override void InternalAbort()
|
||||
{
|
||||
//TODO
|
||||
// 1. 编辑器下停止运行游戏的时候主动终止下载任务
|
||||
// 2. 真机上销毁包裹的时候主动终止下载任务
|
||||
if (_isAbort == false)
|
||||
{
|
||||
if (_webRequest != null)
|
||||
{
|
||||
_webRequest.Abort();
|
||||
_isAbort = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 释放下载器
|
||||
/// </summary>
|
||||
protected void DisposeRequest()
|
||||
{
|
||||
if (_webRequest != null)
|
||||
{
|
||||
//注意:引擎底层会自动调用Abort方法
|
||||
_webRequest.Dispose();
|
||||
_webRequest = null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检测请求结果
|
||||
/// </summary>
|
||||
protected bool CheckRequestResult()
|
||||
{
|
||||
HttpCode = _webRequest.responseCode;
|
||||
|
||||
#if UNITY_2020_3_OR_NEWER
|
||||
if (_webRequest.result != UnityWebRequest.Result.Success)
|
||||
{
|
||||
Error = $"URL : {_requestURL} Error : {_webRequest.error}";
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
#else
|
||||
if (_webRequest.isNetworkError || _webRequest.isHttpError)
|
||||
{
|
||||
Error = $"URL : {_requestURL} Error : {_webRequest.error}";
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4e5c3c1a1655a8b41b585c6811201583
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a488de5dcd6f4c448a47c4b574d5c9bc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -63,14 +63,19 @@ namespace YooAsset
|
||||
{
|
||||
"link.xml",
|
||||
"buildlogtep.json",
|
||||
$"{packageName}.version",
|
||||
$"{packageName}_{packageVersion}.bytes",
|
||||
$"{packageName}_{packageVersion}.hash",
|
||||
$"{packageName}_{packageVersion}.json",
|
||||
$"{packageName}_{packageVersion}.report",
|
||||
DefaultBuildinFileSystemDefine.BuildinCatalogJsonFileName,
|
||||
DefaultBuildinFileSystemDefine.BuildinCatalogBinaryFileName
|
||||
};
|
||||
string packageVersionFileName = YooAssetSettingsData.GetPackageVersionFileName(packageName);
|
||||
string packageHashFileName = YooAssetSettingsData.GetPackageHashFileName(packageName, packageVersion);
|
||||
string manifestBinaryFIleName = YooAssetSettingsData.GetManifestBinaryFileName(packageName, packageVersion);
|
||||
string manifestJsonFIleName = YooAssetSettingsData.GetManifestJsonFileName(packageName, packageVersion);
|
||||
string reportFileName = YooAssetSettingsData.GetBuildReportFileName(packageName, packageVersion);
|
||||
whiteFileList.Add(packageVersionFileName);
|
||||
whiteFileList.Add(packageHashFileName);
|
||||
whiteFileList.Add(manifestBinaryFIleName);
|
||||
whiteFileList.Add(manifestJsonFIleName);
|
||||
whiteFileList.Add(reportFileName);
|
||||
|
||||
// 记录所有内置资源文件
|
||||
DirectoryInfo rootDirectory = new DirectoryInfo(packageDirectory);
|
||||
@@ -113,6 +118,34 @@ namespace YooAsset
|
||||
Debug.Log($"Succeed to save catalog file : {binaryFilePath}");
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 生成空的包裹内置资源目录文件
|
||||
/// </summary>
|
||||
public static bool CreateEmptyCatalogFile(string packageName, string packageVersion, string outputPath)
|
||||
{
|
||||
// 创建内置清单实例
|
||||
var buildinFileCatalog = new DefaultBuildinFileCatalog();
|
||||
buildinFileCatalog.FileVersion = CatalogDefine.FileVersion;
|
||||
buildinFileCatalog.PackageName = packageName;
|
||||
buildinFileCatalog.PackageVersion = packageVersion;
|
||||
|
||||
// 创建输出文件
|
||||
string jsonFilePath = $"{outputPath}/{DefaultBuildinFileSystemDefine.BuildinCatalogJsonFileName}";
|
||||
if (File.Exists(jsonFilePath))
|
||||
File.Delete(jsonFilePath);
|
||||
SerializeToJson(jsonFilePath, buildinFileCatalog);
|
||||
|
||||
// 创建输出文件
|
||||
string binaryFilePath = $"{outputPath}/{DefaultBuildinFileSystemDefine.BuildinCatalogBinaryFileName}";
|
||||
if (File.Exists(binaryFilePath))
|
||||
File.Delete(binaryFilePath);
|
||||
SerializeToBinary(binaryFilePath, buildinFileCatalog);
|
||||
|
||||
UnityEditor.AssetDatabase.Refresh();
|
||||
Debug.Log($"Succeed to save catalog file : {binaryFilePath}");
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -25,6 +25,11 @@ namespace YooAsset
|
||||
protected IFileSystem _unpackFileSystem;
|
||||
protected string _packageRoot;
|
||||
|
||||
/// <summary>
|
||||
/// 下载后台接口
|
||||
/// </summary>
|
||||
public IDownloadBackend DownloadBackend { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 包裹名称
|
||||
/// </summary>
|
||||
@@ -53,15 +58,20 @@ namespace YooAsset
|
||||
}
|
||||
|
||||
#region 自定义参数
|
||||
/// <summary>
|
||||
/// 自定义参数:覆盖安装缓存清理模式
|
||||
/// </summary>
|
||||
public EOverwriteInstallClearMode InstallClearMode { private set; get; } = EOverwriteInstallClearMode.ClearAllManifestFiles;
|
||||
|
||||
/// <summary>
|
||||
/// 自定义参数:初始化的时候缓存文件校验级别
|
||||
/// </summary>
|
||||
public EFileVerifyLevel FileVerifyLevel { private set; get; } = EFileVerifyLevel.Middle;
|
||||
|
||||
/// <summary>
|
||||
/// 自定义参数:覆盖安装缓存清理模式
|
||||
/// 自定义参数:初始化的时候缓存文件校验最大并发数
|
||||
/// </summary>
|
||||
public EOverwriteInstallClearMode InstallClearMode { private set; get; } = EOverwriteInstallClearMode.ClearAllManifestFiles;
|
||||
public int FileVerifyMaxConcurrency { private set; get; } = 32;
|
||||
|
||||
/// <summary>
|
||||
/// 自定义参数:数据文件追加文件格式
|
||||
@@ -85,7 +95,12 @@ namespace YooAsset
|
||||
public string CopyBuildinPackageManifestDestRoot { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 自定义参数:解密方法类
|
||||
/// 自定义参数:解压文件系统的根目录
|
||||
/// </summary>
|
||||
public string UnpackFileSystemRoot { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 自定义参数:解密服务接口的实例类
|
||||
/// </summary>
|
||||
public IDecryptionServices DecryptionServices { private set; get; }
|
||||
|
||||
@@ -95,7 +110,7 @@ namespace YooAsset
|
||||
public IManifestRestoreServices ManifestServices { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 自定义参数:拷贝内置文件服务类
|
||||
/// 自定义参数:拷贝内置文件接口的实例类
|
||||
/// </summary>
|
||||
public ICopyLocalFileServices CopyLocalFileServices { private set; get; }
|
||||
#endregion
|
||||
@@ -146,6 +161,13 @@ namespace YooAsset
|
||||
var operation = new DBFSLoadRawBundleOperation(this, bundle);
|
||||
return operation;
|
||||
}
|
||||
#if TUANJIE_1_7_OR_NEWER
|
||||
else if (bundle.BundleType == (int)EBuildBundleType.InstantBundle)
|
||||
{
|
||||
var operation = new DBFSLoadInstantBundleOperation(this, bundle);
|
||||
return operation;
|
||||
}
|
||||
#endif
|
||||
else
|
||||
{
|
||||
string error = $"{nameof(DefaultBuildinFileSystem)} not support load bundle type : {bundle.BundleType}";
|
||||
@@ -156,13 +178,18 @@ namespace YooAsset
|
||||
|
||||
public virtual void SetParameter(string name, object value)
|
||||
{
|
||||
if (name == FileSystemParametersDefine.FILE_VERIFY_LEVEL)
|
||||
if (name == FileSystemParametersDefine.INSTALL_CLEAR_MODE)
|
||||
{
|
||||
InstallClearMode = (EOverwriteInstallClearMode)value;
|
||||
}
|
||||
else if (name == FileSystemParametersDefine.FILE_VERIFY_LEVEL)
|
||||
{
|
||||
FileVerifyLevel = (EFileVerifyLevel)value;
|
||||
}
|
||||
else if (name == FileSystemParametersDefine.INSTALL_CLEAR_MODE)
|
||||
else if (name == FileSystemParametersDefine.FILE_VERIFY_MAX_CONCURRENCY)
|
||||
{
|
||||
InstallClearMode = (EOverwriteInstallClearMode)value;
|
||||
int convertValue = Convert.ToInt32(value);
|
||||
FileVerifyMaxConcurrency = Mathf.Clamp(convertValue, 1, int.MaxValue);
|
||||
}
|
||||
else if (name == FileSystemParametersDefine.APPEND_FILE_EXTENSION)
|
||||
{
|
||||
@@ -180,6 +207,10 @@ namespace YooAsset
|
||||
{
|
||||
CopyBuildinPackageManifestDestRoot = (string)value;
|
||||
}
|
||||
else if (name == FileSystemParametersDefine.UNPACK_FILE_SYSTEM_ROOT)
|
||||
{
|
||||
UnpackFileSystemRoot = (string)value;
|
||||
}
|
||||
else if (name == FileSystemParametersDefine.DECRYPTION_SERVICES)
|
||||
{
|
||||
DecryptionServices = (IDecryptionServices)value;
|
||||
@@ -206,16 +237,21 @@ namespace YooAsset
|
||||
else
|
||||
_packageRoot = packageRoot;
|
||||
|
||||
// 创建默认的下载后台接口
|
||||
if (DownloadBackend == null)
|
||||
DownloadBackend = new UnityWebRequestBackend(DownloadSystemHelper.UnityWebRequestCreater);
|
||||
|
||||
// 创建解压文件系统
|
||||
var remoteServices = new DefaultUnpackRemoteServices(_packageRoot);
|
||||
_unpackFileSystem = new DefaultUnpackFileSystem();
|
||||
_unpackFileSystem.SetParameter(FileSystemParametersDefine.REMOTE_SERVICES, remoteServices);
|
||||
_unpackFileSystem.SetParameter(FileSystemParametersDefine.FILE_VERIFY_LEVEL, FileVerifyLevel);
|
||||
_unpackFileSystem.SetParameter(FileSystemParametersDefine.INSTALL_CLEAR_MODE, InstallClearMode);
|
||||
_unpackFileSystem.SetParameter(FileSystemParametersDefine.FILE_VERIFY_LEVEL, FileVerifyLevel);
|
||||
_unpackFileSystem.SetParameter(FileSystemParametersDefine.FILE_VERIFY_MAX_CONCURRENCY, FileVerifyMaxConcurrency);
|
||||
_unpackFileSystem.SetParameter(FileSystemParametersDefine.APPEND_FILE_EXTENSION, AppendFileExtension);
|
||||
_unpackFileSystem.SetParameter(FileSystemParametersDefine.DECRYPTION_SERVICES, DecryptionServices);
|
||||
_unpackFileSystem.SetParameter(FileSystemParametersDefine.COPY_LOCAL_FILE_SERVICES, CopyLocalFileServices);
|
||||
_unpackFileSystem.OnCreate(packageName, null);
|
||||
_unpackFileSystem.OnCreate(packageName, UnpackFileSystemRoot);
|
||||
}
|
||||
public virtual void OnDestroy()
|
||||
{
|
||||
@@ -335,6 +371,27 @@ namespace YooAsset
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否属于解压资源包文件
|
||||
/// </summary>
|
||||
protected virtual bool IsUnpackBundleFile(PackageBundle bundle)
|
||||
{
|
||||
if (Belong(bundle) == false)
|
||||
return false;
|
||||
|
||||
#if UNITY_ANDROID || UNITY_OPENHARMONY
|
||||
if (bundle.Encrypted)
|
||||
return true;
|
||||
|
||||
if (bundle.BundleType == (int)EBuildBundleType.RawBundle)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
#region 内部方法
|
||||
protected string GetDefaultBuildinPackageRoot(string packageName)
|
||||
{
|
||||
@@ -370,27 +427,6 @@ namespace YooAsset
|
||||
return PathUtility.Combine(_packageRoot, DefaultBuildinFileSystemDefine.BuildinCatalogBinaryFileName);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否属于解压资源包文件
|
||||
/// </summary>
|
||||
protected bool IsUnpackBundleFile(PackageBundle bundle)
|
||||
{
|
||||
if (Belong(bundle) == false)
|
||||
return false;
|
||||
|
||||
#if UNITY_ANDROID
|
||||
if (bundle.Encrypted)
|
||||
return true;
|
||||
|
||||
if (bundle.BundleType == (int)EBuildBundleType.RawBundle)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
#else
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 记录文件信息
|
||||
/// </summary>
|
||||
|
||||
@@ -8,14 +8,18 @@ namespace YooAsset
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
CopyBuildinManifest,
|
||||
LoadBuildinPackageVersion,
|
||||
CopyBuildinPackageHash,
|
||||
CopyBuildinPackageManifest,
|
||||
InitUnpackFileSystem,
|
||||
LoadCatalogFile,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly DefaultBuildinFileSystem _fileSystem;
|
||||
private CopyBuildinPackageManifestOperation _copyBuildinPackageManifestOp;
|
||||
private RequestBuildinPackageVersionOperation _requestBuildinPackageVersionOp;
|
||||
private CopyBuildinFileOperation _copyBuildinHashFileOp;
|
||||
private CopyBuildinFileOperation _copyBuildinManifestFileOp;
|
||||
private FSInitializeFileSystemOperation _initUnpackFIleSystemOp;
|
||||
private LoadBuildinCatalogFileOperation _loadBuildinCatalogFileOp;
|
||||
private ESteps _steps = ESteps.None;
|
||||
@@ -32,7 +36,7 @@ namespace YooAsset
|
||||
Error = $"{nameof(DefaultBuildinFileSystem)} is not support WEBGL platform !";
|
||||
#else
|
||||
if (_fileSystem.CopyBuildinPackageManifest)
|
||||
_steps = ESteps.CopyBuildinManifest;
|
||||
_steps = ESteps.LoadBuildinPackageVersion;
|
||||
else
|
||||
_steps = ESteps.InitUnpackFileSystem;
|
||||
#endif
|
||||
@@ -42,20 +46,76 @@ namespace YooAsset
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.CopyBuildinManifest)
|
||||
if (_steps == ESteps.LoadBuildinPackageVersion)
|
||||
{
|
||||
if (_copyBuildinPackageManifestOp == null)
|
||||
if (_requestBuildinPackageVersionOp == null)
|
||||
{
|
||||
_copyBuildinPackageManifestOp = new CopyBuildinPackageManifestOperation(_fileSystem);
|
||||
_copyBuildinPackageManifestOp.StartOperation();
|
||||
AddChildOperation(_copyBuildinPackageManifestOp);
|
||||
_requestBuildinPackageVersionOp = new RequestBuildinPackageVersionOperation(_fileSystem);
|
||||
_requestBuildinPackageVersionOp.StartOperation();
|
||||
AddChildOperation(_requestBuildinPackageVersionOp);
|
||||
}
|
||||
|
||||
_copyBuildinPackageManifestOp.UpdateOperation();
|
||||
if (_copyBuildinPackageManifestOp.IsDone == false)
|
||||
_requestBuildinPackageVersionOp.UpdateOperation();
|
||||
if (_requestBuildinPackageVersionOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_copyBuildinPackageManifestOp.Status == EOperationStatus.Succeed)
|
||||
if (_requestBuildinPackageVersionOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
_steps = ESteps.CopyBuildinPackageHash;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _requestBuildinPackageVersionOp.Error;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.CopyBuildinPackageHash)
|
||||
{
|
||||
if (_copyBuildinHashFileOp == null)
|
||||
{
|
||||
string packageVersion = _requestBuildinPackageVersionOp.PackageVersion;
|
||||
string destFilePath = GetCopyPackageHashDestPath(packageVersion);
|
||||
string sourceFilePath = _fileSystem.GetBuildinPackageHashFilePath(packageVersion);
|
||||
_copyBuildinHashFileOp = new CopyBuildinFileOperation(_fileSystem, sourceFilePath, destFilePath);
|
||||
_copyBuildinHashFileOp.StartOperation();
|
||||
AddChildOperation(_copyBuildinHashFileOp);
|
||||
}
|
||||
|
||||
_copyBuildinHashFileOp.UpdateOperation();
|
||||
if (_copyBuildinHashFileOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_copyBuildinHashFileOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
_steps = ESteps.CopyBuildinPackageManifest;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _copyBuildinHashFileOp.Error;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.CopyBuildinPackageManifest)
|
||||
{
|
||||
if (_copyBuildinManifestFileOp == null)
|
||||
{
|
||||
string packageVersion = _requestBuildinPackageVersionOp.PackageVersion;
|
||||
string destFilePath = GetCopyPackageManifestDestPath(packageVersion);
|
||||
string sourceFilePath = _fileSystem.GetBuildinPackageManifestFilePath(packageVersion);
|
||||
_copyBuildinManifestFileOp = new CopyBuildinFileOperation(_fileSystem, sourceFilePath, destFilePath);
|
||||
_copyBuildinManifestFileOp.StartOperation();
|
||||
AddChildOperation(_copyBuildinManifestFileOp);
|
||||
}
|
||||
|
||||
_copyBuildinManifestFileOp.UpdateOperation();
|
||||
if (_copyBuildinManifestFileOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_copyBuildinManifestFileOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
_steps = ESteps.InitUnpackFileSystem;
|
||||
}
|
||||
@@ -63,7 +123,7 @@ namespace YooAsset
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _copyBuildinPackageManifestOp.Error;
|
||||
Error = _copyBuildinManifestFileOp.Error;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,6 +176,30 @@ namespace YooAsset
|
||||
|
||||
if (_loadBuildinCatalogFileOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
var catalog = _loadBuildinCatalogFileOp.Catalog;
|
||||
if (catalog == null)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = "Fatal error : catalog is null !";
|
||||
return;
|
||||
}
|
||||
|
||||
if (catalog.PackageName != _fileSystem.PackageName)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Catalog file package name {catalog.PackageName} cannot match the file system package name {_fileSystem.PackageName}";
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var wrapper in catalog.Wrappers)
|
||||
{
|
||||
var fileWrapper = new DefaultBuildinFileSystem.FileWrapper(wrapper.FileName);
|
||||
_fileSystem.RecordCatalogFile(wrapper.BundleGUID, fileWrapper);
|
||||
}
|
||||
|
||||
YooLogger.Log($"Package '{_fileSystem.PackageName}' buildin catalog files count : {catalog.Wrappers.Count}");
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
@@ -127,5 +211,28 @@ namespace YooAsset
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private string GetCopyManifestFileRoot()
|
||||
{
|
||||
string destRoot = _fileSystem.CopyBuildinPackageManifestDestRoot;
|
||||
if (string.IsNullOrEmpty(destRoot))
|
||||
{
|
||||
string defaultCacheRoot = YooAssetSettingsData.GetYooDefaultCacheRoot();
|
||||
destRoot = PathUtility.Combine(defaultCacheRoot, _fileSystem.PackageName, DefaultCacheFileSystemDefine.ManifestFilesFolderName);
|
||||
}
|
||||
return destRoot;
|
||||
}
|
||||
private string GetCopyPackageHashDestPath(string packageVersion)
|
||||
{
|
||||
string fileRoot = GetCopyManifestFileRoot();
|
||||
string fileName = YooAssetSettingsData.GetPackageHashFileName(_fileSystem.PackageName, packageVersion);
|
||||
return PathUtility.Combine(fileRoot, fileName);
|
||||
}
|
||||
private string GetCopyPackageManifestDestPath(string packageVersion)
|
||||
{
|
||||
string fileRoot = GetCopyManifestFileRoot();
|
||||
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(_fileSystem.PackageName, packageVersion);
|
||||
return PathUtility.Combine(fileRoot, fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class CopyBuildinFileOperation : AsyncOperationBase
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
CheckFileExist,
|
||||
TryCopyFile,
|
||||
UnpackFile,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly DefaultBuildinFileSystem _fileSystem;
|
||||
private readonly string _sourceFilePath;
|
||||
private readonly string _destFilePath;
|
||||
private IDownloadFileRequest _webFileRequestOp;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
public CopyBuildinFileOperation(DefaultBuildinFileSystem fileSystem, string sourceFilePath, string destFilePath)
|
||||
{
|
||||
_fileSystem = fileSystem;
|
||||
_sourceFilePath = sourceFilePath;
|
||||
_destFilePath = destFilePath;
|
||||
}
|
||||
internal override void InternalStart()
|
||||
{
|
||||
_steps = ESteps.CheckFileExist;
|
||||
}
|
||||
internal override void InternalUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.CheckFileExist)
|
||||
{
|
||||
if (File.Exists(_destFilePath))
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.TryCopyFile;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.TryCopyFile)
|
||||
{
|
||||
if (File.Exists(_sourceFilePath))
|
||||
{
|
||||
try
|
||||
{
|
||||
var directory = Path.GetDirectoryName(_destFilePath);
|
||||
if (Directory.Exists(directory) == false)
|
||||
Directory.CreateDirectory(directory);
|
||||
File.Copy(_sourceFilePath, _destFilePath, true);
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
YooLogger.Warning($"Failed copy buildin file : {ex.Message}");
|
||||
_steps = ESteps.UnpackFile;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.UnpackFile;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.UnpackFile)
|
||||
{
|
||||
if (_webFileRequestOp == null)
|
||||
{
|
||||
string url = DownloadSystemHelper.ConvertToWWWPath(_sourceFilePath);
|
||||
var args = new DownloadFileRequestArgs(url, _destFilePath, 60, 0);
|
||||
_webFileRequestOp = _fileSystem.DownloadBackend.CreateFileRequest(args);
|
||||
_webFileRequestOp.SendRequest();
|
||||
}
|
||||
|
||||
if (_webFileRequestOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_webFileRequestOp.Status == EDownloadRequestStatus.Succeed)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _webFileRequestOp.Error;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bf44368bc5c2bf1479c36d82e931c295
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,173 +0,0 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class CopyBuildinPackageManifestOperation : AsyncOperationBase
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
RequestPackageVersion,
|
||||
CheckHashFile,
|
||||
UnpackHashFile,
|
||||
CheckManifestFile,
|
||||
UnpackManifestFile,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly DefaultBuildinFileSystem _fileSystem;
|
||||
private RequestBuildinPackageVersionOperation _requestBuildinPackageVersionOp;
|
||||
private UnityWebFileRequestOperation _hashWebFileRequestOp;
|
||||
private UnityWebFileRequestOperation _manifestWebFileRequestOp;
|
||||
private string _buildinPackageVersion;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
public CopyBuildinPackageManifestOperation(DefaultBuildinFileSystem fileSystem)
|
||||
{
|
||||
_fileSystem = fileSystem;
|
||||
}
|
||||
internal override void InternalStart()
|
||||
{
|
||||
_steps = ESteps.RequestPackageVersion;
|
||||
}
|
||||
internal override void InternalUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.RequestPackageVersion)
|
||||
{
|
||||
if (_requestBuildinPackageVersionOp == null)
|
||||
{
|
||||
_requestBuildinPackageVersionOp = new RequestBuildinPackageVersionOperation(_fileSystem);
|
||||
_requestBuildinPackageVersionOp.StartOperation();
|
||||
AddChildOperation(_requestBuildinPackageVersionOp);
|
||||
}
|
||||
|
||||
_requestBuildinPackageVersionOp.UpdateOperation();
|
||||
if (_requestBuildinPackageVersionOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_requestBuildinPackageVersionOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
_steps = ESteps.CheckHashFile;
|
||||
_buildinPackageVersion = _requestBuildinPackageVersionOp.PackageVersion;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _requestBuildinPackageVersionOp.Error;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.CheckHashFile)
|
||||
{
|
||||
string hashFilePath = GetCopyPackageHashDestPath(_buildinPackageVersion);
|
||||
if (File.Exists(hashFilePath))
|
||||
{
|
||||
_steps = ESteps.CheckManifestFile;
|
||||
return;
|
||||
}
|
||||
|
||||
_steps = ESteps.UnpackHashFile;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.UnpackHashFile)
|
||||
{
|
||||
if (_hashWebFileRequestOp == null)
|
||||
{
|
||||
string sourcePath = _fileSystem.GetBuildinPackageHashFilePath(_buildinPackageVersion);
|
||||
string destPath = GetCopyPackageHashDestPath(_buildinPackageVersion);
|
||||
string url = DownloadSystemHelper.ConvertToWWWPath(sourcePath);
|
||||
_hashWebFileRequestOp = new UnityWebFileRequestOperation(url, destPath, 60);
|
||||
_hashWebFileRequestOp.StartOperation();
|
||||
AddChildOperation(_hashWebFileRequestOp);
|
||||
}
|
||||
|
||||
_hashWebFileRequestOp.UpdateOperation();
|
||||
if (_hashWebFileRequestOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_hashWebFileRequestOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
_steps = ESteps.CheckManifestFile;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _hashWebFileRequestOp.Error;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.CheckManifestFile)
|
||||
{
|
||||
string manifestFilePath = GetCopyPackageManifestDestPath(_buildinPackageVersion);
|
||||
if (File.Exists(manifestFilePath))
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
return;
|
||||
}
|
||||
|
||||
_steps = ESteps.UnpackManifestFile;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.UnpackManifestFile)
|
||||
{
|
||||
if (_manifestWebFileRequestOp == null)
|
||||
{
|
||||
string sourcePath = _fileSystem.GetBuildinPackageManifestFilePath(_buildinPackageVersion);
|
||||
string destPath = GetCopyPackageManifestDestPath(_buildinPackageVersion);
|
||||
string url = DownloadSystemHelper.ConvertToWWWPath(sourcePath);
|
||||
_manifestWebFileRequestOp = new UnityWebFileRequestOperation(url, destPath, 60);
|
||||
_manifestWebFileRequestOp.StartOperation();
|
||||
AddChildOperation(_manifestWebFileRequestOp);
|
||||
}
|
||||
|
||||
_manifestWebFileRequestOp.UpdateOperation();
|
||||
if (_manifestWebFileRequestOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_manifestWebFileRequestOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = _manifestWebFileRequestOp.Error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private string GetCopyManifestFileRoot()
|
||||
{
|
||||
string destRoot = _fileSystem.CopyBuildinPackageManifestDestRoot;
|
||||
if (string.IsNullOrEmpty(destRoot))
|
||||
{
|
||||
string defaultCacheRoot = YooAssetSettingsData.GetYooDefaultCacheRoot();
|
||||
destRoot = PathUtility.Combine(defaultCacheRoot, _fileSystem.PackageName, DefaultCacheFileSystemDefine.ManifestFilesFolderName);
|
||||
}
|
||||
return destRoot;
|
||||
}
|
||||
private string GetCopyPackageHashDestPath(string packageVersion)
|
||||
{
|
||||
string fileRoot = GetCopyManifestFileRoot();
|
||||
string fileName = YooAssetSettingsData.GetPackageHashFileName(_fileSystem.PackageName, packageVersion);
|
||||
return PathUtility.Combine(fileRoot, fileName);
|
||||
}
|
||||
private string GetCopyPackageManifestDestPath(string packageVersion)
|
||||
{
|
||||
string fileRoot = GetCopyManifestFileRoot();
|
||||
string fileName = YooAssetSettingsData.GetManifestBinaryFileName(_fileSystem.PackageName, packageVersion);
|
||||
return PathUtility.Combine(fileRoot, fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 69f62f6b4185d06498f96aa272e9b926
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
@@ -7,45 +8,66 @@ namespace YooAsset
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
RequestData,
|
||||
TryLoadFileData,
|
||||
RequestFileData,
|
||||
LoadCatalog,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly DefaultBuildinFileSystem _fileSystem;
|
||||
private UnityWebDataRequestOperation _webDataRequestOp;
|
||||
private IDownloadBytesRequest _webDataRequestOp;
|
||||
private byte[] _fileData;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
/// <summary>
|
||||
/// 内置资源目录
|
||||
/// </summary>
|
||||
public DefaultBuildinFileCatalog Catalog;
|
||||
|
||||
internal LoadBuildinCatalogFileOperation(DefaultBuildinFileSystem fileSystem)
|
||||
{
|
||||
_fileSystem = fileSystem;
|
||||
}
|
||||
internal override void InternalStart()
|
||||
{
|
||||
_steps = ESteps.RequestData;
|
||||
_steps = ESteps.TryLoadFileData;
|
||||
}
|
||||
internal override void InternalUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.RequestData)
|
||||
if (_steps == ESteps.TryLoadFileData)
|
||||
{
|
||||
string filePath = _fileSystem.GetCatalogBinaryFileLoadPath();
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
_fileData = File.ReadAllBytes(filePath);
|
||||
_steps = ESteps.LoadCatalog;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.RequestFileData;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.RequestFileData)
|
||||
{
|
||||
if (_webDataRequestOp == null)
|
||||
{
|
||||
string filePath = _fileSystem.GetCatalogBinaryFileLoadPath();
|
||||
string url = DownloadSystemHelper.ConvertToWWWPath(filePath);
|
||||
_webDataRequestOp = new UnityWebDataRequestOperation(url, 60);
|
||||
_webDataRequestOp.StartOperation();
|
||||
AddChildOperation(_webDataRequestOp);
|
||||
var args = new DownloadDataRequestArgs(url, 60, 0);
|
||||
_webDataRequestOp = _fileSystem.DownloadBackend.CreateBytesRequest(args);
|
||||
_webDataRequestOp.SendRequest();
|
||||
}
|
||||
|
||||
_webDataRequestOp.UpdateOperation();
|
||||
if (_webDataRequestOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_webDataRequestOp.Status == EOperationStatus.Succeed)
|
||||
if (_webDataRequestOp.Status == EDownloadRequestStatus.Succeed)
|
||||
{
|
||||
_fileData = _webDataRequestOp.Result;
|
||||
_steps = ESteps.LoadCatalog;
|
||||
}
|
||||
else
|
||||
@@ -60,30 +82,15 @@ namespace YooAsset
|
||||
{
|
||||
try
|
||||
{
|
||||
var catalog = CatalogTools.DeserializeFromBinary(_webDataRequestOp.Result);
|
||||
if (catalog.PackageName != _fileSystem.PackageName)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Catalog file package name {catalog.PackageName} cannot match the file system package name {_fileSystem.PackageName}";
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var wrapper in catalog.Wrappers)
|
||||
{
|
||||
var fileWrapper = new DefaultBuildinFileSystem.FileWrapper(wrapper.FileName);
|
||||
_fileSystem.RecordCatalogFile(wrapper.BundleGUID, fileWrapper);
|
||||
}
|
||||
|
||||
YooLogger.Log($"Package '{_fileSystem.PackageName}' buildin catalog files count : {catalog.Wrappers.Count}");
|
||||
Catalog = CatalogTools.DeserializeFromBinary(_fileData);
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
catch (Exception e)
|
||||
catch (Exception ex)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Failed to load catalog file : {e.Message}";
|
||||
Error = $"Failed to load catalog file : {ex.Message}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
|
||||
using System.IO;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class LoadBuildinPackageManifestOperation : AsyncOperationBase
|
||||
@@ -6,6 +7,7 @@ namespace YooAsset
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
TryLoadFileData,
|
||||
RequestFileData,
|
||||
VerifyFileData,
|
||||
LoadManifest,
|
||||
@@ -15,8 +17,9 @@ namespace YooAsset
|
||||
private readonly DefaultBuildinFileSystem _fileSystem;
|
||||
private readonly string _packageVersion;
|
||||
private readonly string _packageHash;
|
||||
private UnityWebDataRequestOperation _webDataRequestOp;
|
||||
private IDownloadBytesRequest _webDataRequestOp;
|
||||
private DeserializeManifestOperation _deserializer;
|
||||
private byte[] _fileData;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
/// <summary>
|
||||
@@ -33,30 +36,44 @@ namespace YooAsset
|
||||
}
|
||||
internal override void InternalStart()
|
||||
{
|
||||
_steps = ESteps.RequestFileData;
|
||||
_steps = ESteps.TryLoadFileData;
|
||||
}
|
||||
internal override void InternalUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.TryLoadFileData)
|
||||
{
|
||||
string filePath = _fileSystem.GetBuildinPackageManifestFilePath(_packageVersion);
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
_fileData = File.ReadAllBytes(filePath);
|
||||
_steps = ESteps.VerifyFileData;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.RequestFileData;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.RequestFileData)
|
||||
{
|
||||
if (_webDataRequestOp == null)
|
||||
{
|
||||
string filePath = _fileSystem.GetBuildinPackageManifestFilePath(_packageVersion);
|
||||
string url = DownloadSystemHelper.ConvertToWWWPath(filePath);
|
||||
_webDataRequestOp = new UnityWebDataRequestOperation(url, 60);
|
||||
_webDataRequestOp.StartOperation();
|
||||
AddChildOperation(_webDataRequestOp);
|
||||
var args = new DownloadDataRequestArgs(url, 60, 0);
|
||||
_webDataRequestOp = _fileSystem.DownloadBackend.CreateBytesRequest(args);
|
||||
_webDataRequestOp.SendRequest();
|
||||
}
|
||||
|
||||
_webDataRequestOp.UpdateOperation();
|
||||
if (_webDataRequestOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_webDataRequestOp.Status == EOperationStatus.Succeed)
|
||||
if (_webDataRequestOp.Status == EDownloadRequestStatus.Succeed)
|
||||
{
|
||||
_fileData = _webDataRequestOp.Result;
|
||||
_steps = ESteps.VerifyFileData;
|
||||
}
|
||||
else
|
||||
@@ -69,7 +86,7 @@ namespace YooAsset
|
||||
|
||||
if (_steps == ESteps.VerifyFileData)
|
||||
{
|
||||
if (ManifestTools.VerifyManifestData(_webDataRequestOp.Result, _packageHash))
|
||||
if (ManifestTools.VerifyManifestData(_fileData, _packageHash))
|
||||
{
|
||||
_steps = ESteps.LoadManifest;
|
||||
}
|
||||
@@ -85,7 +102,7 @@ namespace YooAsset
|
||||
{
|
||||
if (_deserializer == null)
|
||||
{
|
||||
_deserializer = new DeserializeManifestOperation(_fileSystem.ManifestServices, _webDataRequestOp.Result);
|
||||
_deserializer = new DeserializeManifestOperation(_fileSystem.ManifestServices, _fileData);
|
||||
_deserializer.StartOperation();
|
||||
AddChildOperation(_deserializer);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
|
||||
using System.IO;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class RequestBuildinPackageHashOperation : AsyncOperationBase
|
||||
@@ -6,13 +7,15 @@ namespace YooAsset
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
TryLoadPackageHash,
|
||||
RequestPackageHash,
|
||||
CheckResult,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly DefaultBuildinFileSystem _fileSystem;
|
||||
private readonly string _packageVersion;
|
||||
private UnityWebTextRequestOperation _webTextRequestOp;
|
||||
private IDownloadTextRequest _webTextRequestOp;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
/// <summary>
|
||||
@@ -28,42 +31,45 @@ namespace YooAsset
|
||||
}
|
||||
internal override void InternalStart()
|
||||
{
|
||||
_steps = ESteps.RequestPackageHash;
|
||||
_steps = ESteps.TryLoadPackageHash;
|
||||
}
|
||||
internal override void InternalUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.TryLoadPackageHash)
|
||||
{
|
||||
string filePath = _fileSystem.GetBuildinPackageHashFilePath(_packageVersion);
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
PackageHash = File.ReadAllText(filePath);
|
||||
_steps = ESteps.CheckResult;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.RequestPackageHash;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.RequestPackageHash)
|
||||
{
|
||||
if (_webTextRequestOp == null)
|
||||
{
|
||||
string filePath = _fileSystem.GetBuildinPackageHashFilePath(_packageVersion);
|
||||
string url = DownloadSystemHelper.ConvertToWWWPath(filePath);
|
||||
_webTextRequestOp = new UnityWebTextRequestOperation(url, 60);
|
||||
_webTextRequestOp.StartOperation();
|
||||
AddChildOperation(_webTextRequestOp);
|
||||
var args = new DownloadDataRequestArgs(url, 60, 0);
|
||||
_webTextRequestOp = _fileSystem.DownloadBackend.CreateTextRequest(args);
|
||||
_webTextRequestOp.SendRequest();
|
||||
}
|
||||
|
||||
_webTextRequestOp.UpdateOperation();
|
||||
if (_webTextRequestOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_webTextRequestOp.Status == EOperationStatus.Succeed)
|
||||
if (_webTextRequestOp.Status == EDownloadRequestStatus.Succeed)
|
||||
{
|
||||
PackageHash = _webTextRequestOp.Result;
|
||||
if (string.IsNullOrEmpty(PackageHash))
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Buildin package hash file content is empty !";
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
_steps = ESteps.CheckResult;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -72,6 +78,21 @@ namespace YooAsset
|
||||
Error = _webTextRequestOp.Error;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.CheckResult)
|
||||
{
|
||||
if (string.IsNullOrEmpty(PackageHash))
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Buildin package hash file content is empty !";
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
|
||||
using System.IO;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class RequestBuildinPackageVersionOperation : AsyncOperationBase
|
||||
@@ -6,12 +7,14 @@ namespace YooAsset
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
TryLoadPackageVersion,
|
||||
RequestPackageVersion,
|
||||
CheckResult,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly DefaultBuildinFileSystem _fileSystem;
|
||||
private UnityWebTextRequestOperation _webTextRequestOp;
|
||||
private IDownloadTextRequest _webTextRequestOp;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
/// <summary>
|
||||
@@ -26,42 +29,45 @@ namespace YooAsset
|
||||
}
|
||||
internal override void InternalStart()
|
||||
{
|
||||
_steps = ESteps.RequestPackageVersion;
|
||||
_steps = ESteps.TryLoadPackageVersion;
|
||||
}
|
||||
internal override void InternalUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.TryLoadPackageVersion)
|
||||
{
|
||||
string filePath = _fileSystem.GetBuildinPackageVersionFilePath();
|
||||
if (File.Exists(filePath))
|
||||
{
|
||||
PackageVersion = File.ReadAllText(filePath);
|
||||
_steps = ESteps.CheckResult;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.RequestPackageVersion;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.RequestPackageVersion)
|
||||
{
|
||||
if (_webTextRequestOp == null)
|
||||
{
|
||||
string filePath = _fileSystem.GetBuildinPackageVersionFilePath();
|
||||
string url = DownloadSystemHelper.ConvertToWWWPath(filePath);
|
||||
_webTextRequestOp = new UnityWebTextRequestOperation(url, 60);
|
||||
_webTextRequestOp.StartOperation();
|
||||
AddChildOperation(_webTextRequestOp);
|
||||
var args = new DownloadDataRequestArgs(url, 60, 0);
|
||||
_webTextRequestOp = _fileSystem.DownloadBackend.CreateTextRequest(args);
|
||||
_webTextRequestOp.SendRequest();
|
||||
}
|
||||
|
||||
_webTextRequestOp.UpdateOperation();
|
||||
if (_webTextRequestOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_webTextRequestOp.Status == EOperationStatus.Succeed)
|
||||
if (_webTextRequestOp.Status == EDownloadRequestStatus.Succeed)
|
||||
{
|
||||
PackageVersion = _webTextRequestOp.Result;
|
||||
if (string.IsNullOrEmpty(PackageVersion))
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Buildin package version file content is empty !";
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
_steps = ESteps.CheckResult;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -70,6 +76,21 @@ namespace YooAsset
|
||||
Error = _webTextRequestOp.Error;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.CheckResult)
|
||||
{
|
||||
if (string.IsNullOrEmpty(PackageVersion))
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Buildin package version file content is empty !";
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
@@ -22,10 +23,14 @@ namespace YooAsset
|
||||
protected string _cacheManifestFilesRoot;
|
||||
|
||||
/// <summary>
|
||||
/// 下载中心
|
||||
/// 说明:当异步操作任务终止的时候,所有下载子任务都会一同被终止!
|
||||
/// 下载调度器
|
||||
/// </summary>
|
||||
public DownloadCenterOperation DownloadCenter { set; get; }
|
||||
public DownloadSchedulerOperation DownloadScheduler { set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 下载后台接口
|
||||
/// </summary>
|
||||
public IDownloadBackend DownloadBackend { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 包裹名称
|
||||
@@ -56,19 +61,26 @@ namespace YooAsset
|
||||
|
||||
#region 自定义参数
|
||||
/// <summary>
|
||||
/// 自定义参数:远程服务接口
|
||||
/// 自定义参数:远程服务接口的实例类
|
||||
/// </summary>
|
||||
public IRemoteServices RemoteServices { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 自定义参数:覆盖安装缓存清理模式
|
||||
/// </summary>
|
||||
public EOverwriteInstallClearMode InstallClearMode { private set; get; } = EOverwriteInstallClearMode.ClearAllManifestFiles;
|
||||
|
||||
/// <summary>
|
||||
/// 自定义参数:初始化的时候缓存文件校验级别
|
||||
/// </summary>
|
||||
public EFileVerifyLevel FileVerifyLevel { private set; get; } = EFileVerifyLevel.Middle;
|
||||
|
||||
/// <summary>
|
||||
/// 自定义参数:覆盖安装缓存清理模式
|
||||
/// 自定义参数:初始化的时候缓存文件校验最大并发数
|
||||
/// 默认值:32(推荐范围 1-128)
|
||||
/// 说明:过大的值可能导致线程池任务过多,影响系统稳定性
|
||||
/// </summary>
|
||||
public EOverwriteInstallClearMode InstallClearMode { private set; get; } = EOverwriteInstallClearMode.ClearAllManifestFiles;
|
||||
public int FileVerifyMaxConcurrency { private set; get; } = 32;
|
||||
|
||||
/// <summary>
|
||||
/// 自定义参数:数据文件追加文件格式
|
||||
@@ -82,13 +94,22 @@ 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>
|
||||
/// 自定义参数:下载任务的看门狗机制监控时间
|
||||
/// </summary>
|
||||
public int DownloadWatchDogTime { private set; get; } = 0;
|
||||
|
||||
/// <summary>
|
||||
/// 自定义参数:启用断点续传的最小尺寸
|
||||
@@ -101,7 +122,7 @@ namespace YooAsset
|
||||
public List<long> ResumeDownloadResponseCodes { private set; get; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// 自定义参数:解密方法类
|
||||
/// 自定义参数:解密服务接口的实例类
|
||||
/// </summary>
|
||||
public IDecryptionServices DecryptionServices { private set; get; }
|
||||
|
||||
@@ -111,7 +132,7 @@ namespace YooAsset
|
||||
public IManifestRestoreServices ManifestServices { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
/// 自定义参数:拷贝内置文件服务类
|
||||
/// 自定义参数:拷贝内置文件接口的实例类
|
||||
/// </summary>
|
||||
public ICopyLocalFileServices CopyLocalFileServices { private set; get; }
|
||||
#endregion
|
||||
@@ -147,6 +168,11 @@ namespace YooAsset
|
||||
var operation = new ClearUnusedCacheBundleFilesOperation(this, manifest);
|
||||
return operation;
|
||||
}
|
||||
else if (options.ClearMode == EFileClearMode.ClearBundleFilesByLocations.ToString())
|
||||
{
|
||||
var operation = new ClearCacheBundleFilesByLocationsOperaiton(this, manifest, options.ClearParam);
|
||||
return operation;
|
||||
}
|
||||
else if (options.ClearMode == EFileClearMode.ClearBundleFilesByTags.ToString())
|
||||
{
|
||||
var operation = new ClearCacheBundleFilesByTagsOperaiton(this, manifest, options.ClearParam);
|
||||
@@ -215,13 +241,25 @@ namespace YooAsset
|
||||
{
|
||||
RemoteServices = (IRemoteServices)value;
|
||||
}
|
||||
else if (name == FileSystemParametersDefine.INSTALL_CLEAR_MODE)
|
||||
{
|
||||
InstallClearMode = (EOverwriteInstallClearMode)value;
|
||||
}
|
||||
else if (name == FileSystemParametersDefine.FILE_VERIFY_LEVEL)
|
||||
{
|
||||
FileVerifyLevel = (EFileVerifyLevel)value;
|
||||
}
|
||||
else if (name == FileSystemParametersDefine.INSTALL_CLEAR_MODE)
|
||||
else if (name == FileSystemParametersDefine.FILE_VERIFY_MAX_CONCURRENCY)
|
||||
{
|
||||
InstallClearMode = (EOverwriteInstallClearMode)value;
|
||||
int convertValue = Convert.ToInt32(value);
|
||||
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)
|
||||
{
|
||||
@@ -233,11 +271,28 @@ namespace YooAsset
|
||||
}
|
||||
else if (name == FileSystemParametersDefine.DOWNLOAD_MAX_CONCURRENCY)
|
||||
{
|
||||
DownloadMaxConcurrency = Convert.ToInt32(value);
|
||||
int convertValue = Convert.ToInt32(value);
|
||||
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)
|
||||
{
|
||||
DownloadMaxRequestPerFrame = Convert.ToInt32(value);
|
||||
int convertValue = Convert.ToInt32(value);
|
||||
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)
|
||||
{
|
||||
int convertValue = Convert.ToInt32(value);
|
||||
DownloadWatchDogTime = Mathf.Clamp(convertValue, 0, int.MaxValue);
|
||||
}
|
||||
else if (name == FileSystemParametersDefine.RESUME_DOWNLOAD_MINMUM_SIZE)
|
||||
{
|
||||
@@ -276,13 +331,17 @@ namespace YooAsset
|
||||
_cacheBundleFilesRoot = PathUtility.Combine(_packageRoot, DefaultCacheFileSystemDefine.BundleFilesFolderName);
|
||||
_cacheManifestFilesRoot = PathUtility.Combine(_packageRoot, DefaultCacheFileSystemDefine.ManifestFilesFolderName);
|
||||
_tempFilesRoot = PathUtility.Combine(_packageRoot, DefaultCacheFileSystemDefine.TempFilesFolderName);
|
||||
|
||||
// 创建默认的下载后台接口
|
||||
if (DownloadBackend == null)
|
||||
DownloadBackend = new UnityWebRequestBackend(DownloadSystemHelper.UnityWebRequestCreater);
|
||||
}
|
||||
public virtual void OnDestroy()
|
||||
{
|
||||
if (DownloadCenter != null)
|
||||
if (DownloadScheduler != null)
|
||||
{
|
||||
DownloadCenter.AbortOperation();
|
||||
DownloadCenter = null;
|
||||
DownloadScheduler.Dispose();
|
||||
DownloadScheduler = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -448,7 +507,7 @@ namespace YooAsset
|
||||
{
|
||||
if (_records.ContainsKey(bundle.BundleGUID))
|
||||
{
|
||||
throw new Exception("Should never get here !");
|
||||
throw new YooInternalException();
|
||||
}
|
||||
|
||||
string infoFilePath = GetBundleInfoFilePath(bundle);
|
||||
@@ -470,9 +529,9 @@ namespace YooAsset
|
||||
// 写入文件信息
|
||||
WriteBundleInfoFile(infoFilePath, bundle.FileCRC, bundle.FileSize);
|
||||
}
|
||||
catch (Exception e)
|
||||
catch (Exception ex)
|
||||
{
|
||||
YooLogger.Error($"Failed to write cache file ! {e.Message}");
|
||||
YooLogger.Error($"Failed to write cache file ! {ex.Message}");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -493,22 +552,22 @@ namespace YooAsset
|
||||
}
|
||||
|
||||
private readonly BufferWriter _sharedBuffer = new BufferWriter(1024);
|
||||
public void WriteBundleInfoFile(string filePath, string dataFileCRC, long dataFileSize)
|
||||
public void WriteBundleInfoFile(string filePath, uint dataFileCRC, long dataFileSize)
|
||||
{
|
||||
using (FileStream fs = new FileStream(filePath, FileMode.Create, FileAccess.Write, FileShare.Read))
|
||||
{
|
||||
_sharedBuffer.Clear();
|
||||
_sharedBuffer.WriteUTF8(dataFileCRC);
|
||||
_sharedBuffer.WriteUInt32(dataFileCRC);
|
||||
_sharedBuffer.WriteInt64(dataFileSize);
|
||||
_sharedBuffer.WriteToStream(fs);
|
||||
fs.Flush();
|
||||
}
|
||||
}
|
||||
public void ReadBundleInfoFile(string filePath, out string dataFileCRC, out long dataFileSize)
|
||||
public void ReadBundleInfoFile(string filePath, out uint dataFileCRC, out long dataFileSize)
|
||||
{
|
||||
byte[] binaryData = FileUtility.ReadAllBytes(filePath);
|
||||
BufferReader buffer = new BufferReader(binaryData);
|
||||
dataFileCRC = buffer.ReadUTF8();
|
||||
dataFileCRC = buffer.ReadUInt32();
|
||||
dataFileSize = buffer.ReadInt64();
|
||||
}
|
||||
#endregion
|
||||
|
||||
@@ -7,10 +7,10 @@ namespace YooAsset
|
||||
{
|
||||
public string InfoFilePath { private set; get; }
|
||||
public string DataFilePath { private set; get; }
|
||||
public string DataFileCRC { private set; get; }
|
||||
public uint DataFileCRC { private set; get; }
|
||||
public long DataFileSize { private set; get; }
|
||||
|
||||
public RecordFileElement(string infoFilePath, string dataFilePath, string dataFileCRC, long dataFileSize)
|
||||
public RecordFileElement(string infoFilePath, string dataFilePath, uint dataFileCRC, long dataFileSize)
|
||||
{
|
||||
InfoFilePath = infoFilePath;
|
||||
DataFilePath = dataFilePath;
|
||||
@@ -37,9 +37,9 @@ namespace YooAsset
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
catch (Exception ex)
|
||||
{
|
||||
YooLogger.Error($"Failed to delete cache file ! {e.Message}");
|
||||
YooLogger.Error($"Failed to delete cache file ! {ex.Message}");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ namespace YooAsset
|
||||
internal class TempFileElement
|
||||
{
|
||||
public string TempFilePath { private set; get; }
|
||||
public string TempFileCRC { private set; get; }
|
||||
public uint TempFileCRC { private set; get; }
|
||||
public long TempFileSize { private set; get; }
|
||||
|
||||
/// <summary>
|
||||
@@ -12,7 +12,7 @@ namespace YooAsset
|
||||
/// </summary>
|
||||
public volatile int Result = 0;
|
||||
|
||||
public TempFileElement(string filePath, string fileCRC, long fileSize)
|
||||
public TempFileElement(string filePath, uint fileCRC, long fileSize)
|
||||
{
|
||||
TempFilePath = filePath;
|
||||
TempFileCRC = fileCRC;
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace YooAsset
|
||||
public string DataFilePath { private set; get; }
|
||||
public string InfoFilePath { private set; get; }
|
||||
|
||||
public string DataFileCRC;
|
||||
public uint DataFileCRC;
|
||||
public long DataFileSize;
|
||||
|
||||
/// <summary>
|
||||
@@ -33,9 +33,9 @@ namespace YooAsset
|
||||
{
|
||||
Directory.Delete(FileRootPath, true);
|
||||
}
|
||||
catch (System.Exception e)
|
||||
catch (System.Exception ex)
|
||||
{
|
||||
YooLogger.Warning($"Failed to delete cache bundle folder : {e}");
|
||||
YooLogger.Warning($"Failed to delete cache bundle folder : {ex}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ namespace YooAsset
|
||||
CheckAppFootPrint,
|
||||
SearchCacheFiles,
|
||||
VerifyCacheFiles,
|
||||
CreateDownloadCenter,
|
||||
CreateDownloadScheduler,
|
||||
Done,
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ namespace YooAsset
|
||||
|
||||
if (_verifyCacheFilesOp.Status == EOperationStatus.Succeed)
|
||||
{
|
||||
_steps = ESteps.CreateDownloadCenter;
|
||||
_steps = ESteps.CreateDownloadScheduler;
|
||||
YooLogger.Log($"Package '{_fileSystem.PackageName}' '{_fileSystem.GetType().Name}' cached files count : {_fileSystem.FileCount}");
|
||||
}
|
||||
else
|
||||
@@ -121,13 +121,13 @@ namespace YooAsset
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.CreateDownloadCenter)
|
||||
if (_steps == ESteps.CreateDownloadScheduler)
|
||||
{
|
||||
// 注意:下载中心作为独立任务运行!
|
||||
if (_fileSystem.DownloadCenter == null)
|
||||
if (_fileSystem.DownloadScheduler == null)
|
||||
{
|
||||
_fileSystem.DownloadCenter = new DownloadCenterOperation(_fileSystem);
|
||||
OperationSystem.StartOperation(_fileSystem.PackageName, _fileSystem.DownloadCenter);
|
||||
_fileSystem.DownloadScheduler = new DownloadSchedulerOperation(_fileSystem);
|
||||
OperationSystem.StartOperation(_fileSystem.PackageName, _fileSystem.DownloadScheduler);
|
||||
}
|
||||
|
||||
_steps = ESteps.Done;
|
||||
|
||||
@@ -11,6 +11,7 @@ namespace YooAsset
|
||||
None,
|
||||
CheckExist,
|
||||
DownloadFile,
|
||||
AbortDownload,
|
||||
LoadAssetBundle,
|
||||
CheckResult,
|
||||
Done,
|
||||
@@ -63,6 +64,17 @@ namespace YooAsset
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.DownloadFile)
|
||||
{
|
||||
// 中断下载
|
||||
if (AbortDownloadFile)
|
||||
{
|
||||
if (_downloadFileOp != null)
|
||||
_downloadFileOp.AbortOperation();
|
||||
_steps = ESteps.AbortDownload;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.DownloadFile)
|
||||
{
|
||||
if (_downloadFileOp == null)
|
||||
@@ -94,6 +106,23 @@ namespace YooAsset
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.AbortDownload)
|
||||
{
|
||||
if (_downloadFileOp != null)
|
||||
{
|
||||
if (IsWaitForAsyncComplete)
|
||||
_downloadFileOp.WaitForAsyncComplete();
|
||||
|
||||
_downloadFileOp.UpdateOperation();
|
||||
if (_downloadFileOp.IsDone == false)
|
||||
return;
|
||||
}
|
||||
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = "Abort download file !";
|
||||
}
|
||||
|
||||
if (_steps == ESteps.LoadAssetBundle)
|
||||
{
|
||||
if (_bundle.Encrypted)
|
||||
@@ -251,6 +280,7 @@ namespace YooAsset
|
||||
None,
|
||||
CheckExist,
|
||||
DownloadFile,
|
||||
AbortDownload,
|
||||
LoadCacheRawBundle,
|
||||
Done,
|
||||
}
|
||||
@@ -290,11 +320,11 @@ namespace YooAsset
|
||||
File.Move(recordFileElement.DataFilePath, filePath);
|
||||
_steps = ESteps.LoadCacheRawBundle;
|
||||
}
|
||||
catch (Exception e)
|
||||
catch (Exception ex)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Faild rename raw data file : {e.Message}";
|
||||
Error = $"Faild rename raw data file : {ex.Message}";
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -310,6 +340,17 @@ namespace YooAsset
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.DownloadFile)
|
||||
{
|
||||
// 中断下载
|
||||
if (AbortDownloadFile)
|
||||
{
|
||||
if (_downloadFileOp != null)
|
||||
_downloadFileOp.AbortOperation();
|
||||
_steps = ESteps.AbortDownload;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.DownloadFile)
|
||||
{
|
||||
if (_downloadFileOp == null)
|
||||
@@ -341,6 +382,23 @@ namespace YooAsset
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.AbortDownload)
|
||||
{
|
||||
if (_downloadFileOp != null)
|
||||
{
|
||||
if (IsWaitForAsyncComplete)
|
||||
_downloadFileOp.WaitForAsyncComplete();
|
||||
|
||||
_downloadFileOp.UpdateOperation();
|
||||
if (_downloadFileOp.IsDone == false)
|
||||
return;
|
||||
}
|
||||
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = "Abort download file !";
|
||||
}
|
||||
|
||||
if (_steps == ESteps.LoadCacheRawBundle)
|
||||
{
|
||||
string filePath = _fileSystem.GetCacheBundleFileLoadPath(_bundle);
|
||||
|
||||
@@ -0,0 +1,142 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
internal class ClearCacheBundleFilesByLocationsOperaiton : FSClearCacheFilesOperation
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
CheckManifest,
|
||||
CheckArgs,
|
||||
GetClearCacheFiles,
|
||||
ClearFilterCacheFiles,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly DefaultCacheFileSystem _fileSystem;
|
||||
private readonly PackageManifest _manifest;
|
||||
private readonly object _clearParam;
|
||||
private string[] _locations;
|
||||
private List<string> _clearBundleGUIDs;
|
||||
private int _clearFileTotalCount = 0;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
internal ClearCacheBundleFilesByLocationsOperaiton(DefaultCacheFileSystem fileSystem, PackageManifest manifest, object clearParam)
|
||||
{
|
||||
_fileSystem = fileSystem;
|
||||
_manifest = manifest;
|
||||
_clearParam = clearParam;
|
||||
}
|
||||
|
||||
internal override void InternalStart()
|
||||
{
|
||||
_steps = ESteps.CheckManifest;
|
||||
}
|
||||
|
||||
internal override void InternalUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.CheckManifest)
|
||||
{
|
||||
if (_manifest == null)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = "Can not found active package manifest !";
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.CheckArgs;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.CheckArgs)
|
||||
{
|
||||
if (_clearParam == null)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = "Clear param is null !";
|
||||
return;
|
||||
}
|
||||
|
||||
if (_clearParam is string)
|
||||
{
|
||||
_locations = new string[] { _clearParam as string };
|
||||
}
|
||||
else if (_clearParam is List<string>)
|
||||
{
|
||||
var tempList = _clearParam as List<string>;
|
||||
_locations = tempList.ToArray();
|
||||
}
|
||||
else if (_clearParam is string[])
|
||||
{
|
||||
_locations = _clearParam as string[];
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Failed;
|
||||
Error = $"Invalid clear param : {_clearParam.GetType().FullName}";
|
||||
return;
|
||||
}
|
||||
|
||||
_steps = ESteps.GetClearCacheFiles;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.GetClearCacheFiles)
|
||||
{
|
||||
_clearBundleGUIDs = GetBundleGUIDsByLocation();
|
||||
_clearFileTotalCount = _clearBundleGUIDs.Count;
|
||||
_steps = ESteps.ClearFilterCacheFiles;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.ClearFilterCacheFiles)
|
||||
{
|
||||
for (int i = _clearBundleGUIDs.Count - 1; i >= 0; i--)
|
||||
{
|
||||
string bundleGUID = _clearBundleGUIDs[i];
|
||||
_fileSystem.DeleteCacheBundleFile(bundleGUID);
|
||||
_clearBundleGUIDs.RemoveAt(i);
|
||||
if (OperationSystem.IsBusy)
|
||||
break;
|
||||
}
|
||||
|
||||
if (_clearFileTotalCount == 0)
|
||||
Progress = 1.0f;
|
||||
else
|
||||
Progress = 1.0f - (_clearBundleGUIDs.Count / _clearFileTotalCount);
|
||||
|
||||
if (_clearBundleGUIDs.Count == 0)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
Status = EOperationStatus.Succeed;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private List<string> GetBundleGUIDsByLocation()
|
||||
{
|
||||
List<string> result = new List<string>(_locations.Length);
|
||||
|
||||
foreach (var location in _locations)
|
||||
{
|
||||
string assetPath = _manifest.TryMappingToAssetPath(location);
|
||||
if (_manifest.TryGetPackageAsset(assetPath, out PackageAsset packageAsset))
|
||||
{
|
||||
PackageBundle bundle = _manifest.GetMainPackageBundle(packageAsset.BundleID);
|
||||
|
||||
if (bundle != null)
|
||||
{
|
||||
result.Add(bundle.BundleGUID);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0be6ffd570645bf4a95126958a8e8a86
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user