mirror of
https://github.com/tuyoogame/YooAsset.git
synced 2026-05-26 18:50:10 +00:00
Compare commits
2 Commits
yoo3
...
1294d1bab2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1294d1bab2 | ||
|
|
67745c899a |
@@ -2,57 +2,6 @@
|
||||
|
||||
All notable changes to this package will be documented in this file.
|
||||
|
||||
## [3.0.1-beta] - 2026-05-19
|
||||
|
||||
### Added
|
||||
|
||||
- 新增归档文件构建管线 `ArchiveFileBuildPipeline`
|
||||
|
||||
支持将同一资源包内的多个原始文件合并为 `ArchiveBundle`,并提供构建参数、构建任务、编辑器构建界面和运行时加载支持。
|
||||
|
||||
- 新增 `EnsureBundleFileOperation` 操作
|
||||
|
||||
用于确保资源包文件已就绪,并通过 `EnsureBundleFileOperation.Detail` 获取资源包名称、本地文件路径、资源包类型和加密状态。
|
||||
|
||||
**代码示例**
|
||||
|
||||
```csharp
|
||||
var package = YooAssets.GetPackage("DefaultPackage");
|
||||
|
||||
// 确保资源所在的资源包文件已经就绪。
|
||||
// 如果资源包未缓存,会自动触发下载或解压流程。
|
||||
var operation = package.EnsureBundleFileAsync(new EnsureBundleFileOptions("asset_location"));
|
||||
yield return operation;
|
||||
|
||||
if (operation.Status == EOperationStatus.Succeeded)
|
||||
{
|
||||
var detail = operation.Detail;
|
||||
string bundleName = detail.BundleName;
|
||||
string bundleFilePath = detail.BundleFilePath;
|
||||
int bundleType = detail.BundleType;
|
||||
bool isEncrypted = detail.IsEncrypted;
|
||||
|
||||
UnityEngine.Debug.Log($"BundleName: {bundleName}");
|
||||
UnityEngine.Debug.Log($"BundleFilePath: {bundleFilePath}");
|
||||
UnityEngine.Debug.Log($"BundleType: {bundleType}");
|
||||
UnityEngine.Debug.Log($"IsEncrypted: {isEncrypted}");
|
||||
}
|
||||
else
|
||||
{
|
||||
UnityEngine.Debug.LogError(operation.Error);
|
||||
}
|
||||
```
|
||||
|
||||
- 新增编辑器模拟模式下的 Bundle Cache 标记文件机制
|
||||
|
||||
通过记录缓存状态,提升虚拟下载模式下缓存扫描、恢复和清理的可靠性。
|
||||
|
||||
### Changed
|
||||
|
||||
- `LoadRawFile` API 重命名为 `LoadBundleFile`
|
||||
|
||||
对应句柄由 `RawFileHandle` 重命名为 `BundleFileHandle`,语义从“原生文件”调整为“资源包文件”。
|
||||
|
||||
## [3.0.0-beta] - 2026-05-09
|
||||
## [3.0.0] - 2026-05-01
|
||||
|
||||
beta released.
|
||||
|
||||
@@ -1,112 +0,0 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// 归档文件构建辅助工具类
|
||||
/// </summary>
|
||||
internal static class ArchiveFileBuildHelper
|
||||
{
|
||||
private const int StreamCopyBufferSize = 81920;
|
||||
|
||||
/// <summary>
|
||||
/// 收集构建资源的归档条目列表,并按 FilePath 字典序排序
|
||||
/// </summary>
|
||||
public static List<ArchiveFileEntry> CollectEntries(IReadOnlyList<BuildAssetInfo> allAssets)
|
||||
{
|
||||
var entries = new List<ArchiveFileEntry>(allAssets.Count);
|
||||
foreach (var asset in allAssets)
|
||||
{
|
||||
string assetPath = asset.AssetInfo.AssetPath;
|
||||
long dataLength = new FileInfo(assetPath).Length;
|
||||
uint crc = HashUtility.ComputeFileCrc32AsUInt(assetPath);
|
||||
entries.Add(new ArchiveFileEntry(assetPath, dataLength, crc));
|
||||
}
|
||||
|
||||
entries.Sort((a, b) => string.Compare(a.AssetPath, b.AssetPath, StringComparison.Ordinal));
|
||||
return entries;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 计算每个条目的绝对偏移,并写入归档文件
|
||||
/// </summary>
|
||||
/// <param name="outputPath">输出文件路径</param>
|
||||
/// <param name="entries">归档条目列表</param>
|
||||
/// <param name="fileAlignment">文件数据对齐字节数(0 表示不对齐)</param>
|
||||
public static void BuildArchiveFile(string outputPath, List<ArchiveFileEntry> entries, int fileAlignment)
|
||||
{
|
||||
int fileCount = entries.Count;
|
||||
if (fileCount > ArchiveBundleConsts.MaxChildFileCount)
|
||||
throw new InvalidOperationException($"Archive child file count {fileCount} exceeds maximum ({ArchiveBundleConsts.MaxChildFileCount}).");
|
||||
|
||||
// 1. 计算 header 总大小
|
||||
int headerSize = 4 + 4 + 4; // Magic + Version + FileCount
|
||||
foreach (var entry in entries)
|
||||
{
|
||||
byte[] pathBytes = entry.GetPathBytes();
|
||||
// FilePathLen(4) + FilePath(变长) + DataOffset(8) + DataLength(8) + FileCRC(4)
|
||||
headerSize += 4 + pathBytes.Length + 8 + 8 + 4;
|
||||
}
|
||||
|
||||
// 2. 计算每个文件的绝对偏移
|
||||
long currentOffset = headerSize;
|
||||
foreach (var entry in entries)
|
||||
{
|
||||
if (fileAlignment > 0)
|
||||
currentOffset = AlignOffset(currentOffset, fileAlignment);
|
||||
entry.DataOffset = currentOffset;
|
||||
currentOffset += entry.DataLength;
|
||||
}
|
||||
|
||||
// 3. 写入归档文件
|
||||
EditorFileUtility.CreateFileDirectory(outputPath);
|
||||
using (var fs = new FileStream(outputPath, FileMode.Create, FileAccess.Write))
|
||||
using (var writer = new BinaryWriter(fs))
|
||||
{
|
||||
// Header
|
||||
writer.Write(ArchiveBundleConsts.FileMagic);
|
||||
writer.Write(ArchiveBundleConsts.FileVersion);
|
||||
writer.Write(fileCount);
|
||||
|
||||
foreach (var entry in entries)
|
||||
{
|
||||
byte[] pathBytes = entry.GetPathBytes();
|
||||
writer.Write(pathBytes.Length);
|
||||
writer.Write(pathBytes);
|
||||
writer.Write(entry.DataOffset);
|
||||
writer.Write(entry.DataLength);
|
||||
writer.Write(entry.FileCRC);
|
||||
}
|
||||
|
||||
// Data: 按排序后的顺序写入,使用流式拷贝避免大文件 OOM
|
||||
byte[] buffer = new byte[StreamCopyBufferSize];
|
||||
foreach (var entry in entries)
|
||||
{
|
||||
// 填充对齐字节
|
||||
long paddingSize = entry.DataOffset - fs.Position;
|
||||
if (paddingSize > 0)
|
||||
writer.Write(new byte[paddingSize]);
|
||||
|
||||
using (var sourceStream = new FileStream(entry.AssetPath, FileMode.Open, FileAccess.Read))
|
||||
{
|
||||
int bytesRead;
|
||||
while ((bytesRead = sourceStream.Read(buffer, 0, buffer.Length)) > 0)
|
||||
{
|
||||
writer.Write(buffer, 0, bytesRead);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将偏移值向上对齐到指定字节边界
|
||||
/// </summary>
|
||||
private static long AlignOffset(long offset, int alignment)
|
||||
{
|
||||
return (offset + alignment - 1) / alignment * alignment;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3f8daa3aacb5da8458fc073431da1891
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,46 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// 归档文件构建管线的构建参数
|
||||
/// </summary>
|
||||
public class ArchiveFileBuildParameters : BuildParameters
|
||||
{
|
||||
private const int MaxFileAlignment = 4096;
|
||||
|
||||
/// <summary>
|
||||
/// 文件哈希值计算包含路径信息
|
||||
/// </summary>
|
||||
public bool IncludePathInHash { get; set; } = false;
|
||||
|
||||
/// <summary>
|
||||
/// 归档文件内数据对齐字节数(0 表示不对齐)
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 对齐后每个子文件的数据偏移会向上取整到该值的整数倍,文件间以零字节填充。
|
||||
/// 推荐值:4(通用对齐)、512(磁盘扇区对齐)、4096(内存页对齐)。
|
||||
/// </remarks>
|
||||
public int FileAlignment { get; set; } = 0;
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void CheckBuildParametersCore()
|
||||
{
|
||||
// ArchiveBundle 不支持资源包加密
|
||||
if (BundleEncryptor != null)
|
||||
{
|
||||
string message = BuildLogger.GetErrorMessage(ErrorCode.BundleEncryptionNotSupported,
|
||||
$"ArchiveFileBuildPipeline does not support bundle encryption. Please remove the BundleEncryptor configuration.");
|
||||
throw new NotSupportedException(message);
|
||||
}
|
||||
|
||||
// 校验文件对齐参数范围
|
||||
if (FileAlignment < 0 || FileAlignment > MaxFileAlignment)
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(FileAlignment),
|
||||
$"FileAlignment must be between 0 and {MaxFileAlignment}. Current value: {FileAlignment}.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,48 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// 归档文件构建管线,将同一 BundleName 下的多个原始文件合并写入一个归档文件
|
||||
/// </summary>
|
||||
public class ArchiveFileBuildPipeline : IBuildPipeline
|
||||
{
|
||||
/// <summary>
|
||||
/// 执行构建流程
|
||||
/// </summary>
|
||||
public BuildResult Run(BuildParameters buildParameters, bool enableLog)
|
||||
{
|
||||
if (buildParameters is ArchiveFileBuildParameters)
|
||||
{
|
||||
BundleBuilder builder = new BundleBuilder();
|
||||
return builder.Run(buildParameters, GetDefaultBuildPipeline(), enableLog);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ArgumentException($"Invalid build parameter type: '{buildParameters.GetType().Name}'.", nameof(buildParameters));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取默认的构建流程
|
||||
/// </summary>
|
||||
private List<IBuildTask> GetDefaultBuildPipeline()
|
||||
{
|
||||
List<IBuildTask> pipeline = new List<IBuildTask>
|
||||
{
|
||||
new TaskPrepare_AFBP(),
|
||||
new TaskGetBuildMap_AFBP(),
|
||||
new TaskBuilding_AFBP(),
|
||||
new TaskEncryption_AFBP(),
|
||||
new TaskUpdateBundleInfo_AFBP(),
|
||||
new TaskCreateManifest_AFBP(),
|
||||
new TaskCreateReport_AFBP(),
|
||||
new TaskCreatePackage_AFBP(),
|
||||
new TaskCopyBundledFiles_AFBP(),
|
||||
new TaskCreateCatalog_AFBP()
|
||||
};
|
||||
return pipeline;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 19ef6fc50bd422c4db6fa53cbf0fe226
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,61 +0,0 @@
|
||||
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// 归档文件条目信息(构建期临时数据结构)
|
||||
/// </summary>
|
||||
internal class ArchiveFileEntry
|
||||
{
|
||||
private byte[] _pathBytes;
|
||||
|
||||
/// <summary>
|
||||
/// 文件路径
|
||||
/// </summary>
|
||||
public readonly string AssetPath;
|
||||
|
||||
/// <summary>
|
||||
/// 文件数据长度
|
||||
/// </summary>
|
||||
public readonly long DataLength;
|
||||
|
||||
/// <summary>
|
||||
/// 文件 CRC32
|
||||
/// </summary>
|
||||
public readonly uint FileCRC;
|
||||
|
||||
/// <summary>
|
||||
/// 数据在归档文件中的绝对偏移
|
||||
/// </summary>
|
||||
public long DataOffset;
|
||||
|
||||
/// <summary>
|
||||
/// 构造归档文件条目
|
||||
/// </summary>
|
||||
public ArchiveFileEntry(string assetPath, long dataLength, uint fileCRC)
|
||||
{
|
||||
if (string.IsNullOrEmpty(assetPath))
|
||||
throw new ArgumentException("Asset path is null or empty.", nameof(assetPath));
|
||||
if (dataLength < 0)
|
||||
throw new ArgumentException($"Invalid data length {dataLength} for '{assetPath}'.", nameof(dataLength));
|
||||
if (dataLength > ArchiveBundleConsts.MaxChildFileSize)
|
||||
throw new ArgumentException($"Child file exceeds maximum size ({ArchiveBundleConsts.MaxChildFileSize} bytes): '{assetPath}' ({dataLength} bytes).", nameof(dataLength));
|
||||
|
||||
AssetPath = assetPath;
|
||||
DataLength = dataLength;
|
||||
FileCRC = fileCRC;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取文件路径的 UTF8 字节缓存
|
||||
/// </summary>
|
||||
public byte[] GetPathBytes()
|
||||
{
|
||||
if (_pathBytes == null)
|
||||
_pathBytes = Encoding.UTF8.GetBytes(AssetPath);
|
||||
return _pathBytes;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b9dccc7a4589001469444e571235890a
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,29 +0,0 @@
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// 归档文件构建管线的核心构建任务
|
||||
/// </summary>
|
||||
public class TaskBuilding_AFBP : IBuildTask
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
void IBuildTask.Run(BuildContext context)
|
||||
{
|
||||
var buildMapContext = context.GetContextObject<BuildMapContext>();
|
||||
var buildParametersContext = context.GetContextObject<BuildParametersContext>();
|
||||
var buildParameters = buildParametersContext.Parameters as ArchiveFileBuildParameters;
|
||||
string pipelineOutputDirectory = buildParametersContext.GetPipelineOutputDirectory();
|
||||
|
||||
int progressValue = 0;
|
||||
int fileTotalCount = buildMapContext.Collection.Count;
|
||||
foreach (var bundleInfo in buildMapContext.Collection)
|
||||
{
|
||||
string archiveFilePath = $"{pipelineOutputDirectory}/{bundleInfo.BundleName}";
|
||||
var entries = ArchiveFileBuildHelper.CollectEntries(bundleInfo.AllPackAssets);
|
||||
ArchiveFileBuildHelper.BuildArchiveFile(archiveFilePath, entries, buildParameters.FileAlignment);
|
||||
EditorDialogUtility.DisplayProgressBar("Build archive files", ++progressValue, fileTotalCount);
|
||||
}
|
||||
EditorDialogUtility.ClearProgressBar();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 289e760820002e34b9054a81098d5fa4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,23 +0,0 @@
|
||||
using System;
|
||||
using UnityEditor;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// 归档文件构建管线的首包资源拷贝任务
|
||||
/// </summary>
|
||||
public class TaskCopyBundledFiles_AFBP : TaskCopyBundledFiles, IBuildTask
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
void IBuildTask.Run(BuildContext context)
|
||||
{
|
||||
var buildParametersContext = context.GetContextObject<BuildParametersContext>();
|
||||
var buildParameters = buildParametersContext.Parameters;
|
||||
var manifestContext = context.GetContextObject<ManifestContext>();
|
||||
if (buildParameters.BundledCopyOption != EBundledCopyOption.None)
|
||||
{
|
||||
CopyBundledFilesToStreaming(buildParametersContext, manifestContext.Manifest);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e4fb32a77b3e799448cf4eae2a97a49e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,21 +0,0 @@
|
||||
using System;
|
||||
using UnityEditor;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// 归档文件构建管线的资源目录创建任务
|
||||
/// </summary>
|
||||
public class TaskCreateCatalog_AFBP : TaskCreateCatalog, IBuildTask
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
void IBuildTask.Run(BuildContext context)
|
||||
{
|
||||
var buildParametersContext = context.GetContextObject<BuildParametersContext>();
|
||||
if (buildParametersContext.Parameters.BundledCopyOption != EBundledCopyOption.None)
|
||||
{
|
||||
CreateCatalogFile(buildParametersContext);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 813f7821d87b6f8498ddc4d675512413
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,21 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// 归档文件构建管线的清单创建任务
|
||||
/// </summary>
|
||||
public class TaskCreateManifest_AFBP : TaskCreateManifest, IBuildTask
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
void IBuildTask.Run(BuildContext context)
|
||||
{
|
||||
CreateManifestFile(false, true, false, context);
|
||||
}
|
||||
|
||||
protected override string[] GetBundleDepends(BuildContext context, string bundleName)
|
||||
{
|
||||
return Array.Empty<string>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 21e10b308293d2e45972a9b4ba143a74
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,23 +0,0 @@
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// 归档文件构建管线的补丁包创建任务
|
||||
/// </summary>
|
||||
public class TaskCreatePackage_AFBP : TaskCreatePackage, IBuildTask
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
void IBuildTask.Run(BuildContext context)
|
||||
{
|
||||
var buildParametersContext = context.GetContextObject<BuildParametersContext>();
|
||||
var buildMapContext = context.GetContextObject<BuildMapContext>();
|
||||
CreatePackagePatch(buildParametersContext, buildMapContext);
|
||||
}
|
||||
|
||||
private void CreatePackagePatch(BuildParametersContext buildParametersContext, BuildMapContext buildMapContext)
|
||||
{
|
||||
string packageOutputDirectory = buildParametersContext.GetPackageOutputDirectory();
|
||||
BuildLogger.Log($"Start making patch package: '{packageOutputDirectory}'.");
|
||||
CopyPackageBundles(buildMapContext);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 721f0030551d41c40a2c6d3206c3897a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,23 +0,0 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// 归档文件构建管线的构建报告创建任务
|
||||
/// </summary>
|
||||
public class TaskCreateReport_AFBP : TaskCreateReport, IBuildTask
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
void IBuildTask.Run(BuildContext context)
|
||||
{
|
||||
var buildParameters = context.GetContextObject<BuildParametersContext>();
|
||||
var buildMapContext = context.GetContextObject<BuildMapContext>();
|
||||
var manifestContext = context.GetContextObject<ManifestContext>();
|
||||
CreateReportFile(buildParameters, buildMapContext, manifestContext);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3e12187230b544940aeae7cb3c556299
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,17 +0,0 @@
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// 归档文件构建管线的加密任务
|
||||
/// </summary>
|
||||
public class TaskEncryption_AFBP : TaskEncryption, IBuildTask
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
void IBuildTask.Run(BuildContext context)
|
||||
{
|
||||
var buildParameters = context.GetContextObject<BuildParametersContext>();
|
||||
var buildMapContext = context.GetContextObject<BuildMapContext>();
|
||||
EncryptingBundleFiles(buildParameters, buildMapContext);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 16ff5758e3a98b64193c61ca68e94ddd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,17 +0,0 @@
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// 归档文件构建管线的构建映射生成任务
|
||||
/// </summary>
|
||||
public class TaskGetBuildMap_AFBP : TaskGetBuildMap, IBuildTask
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
void IBuildTask.Run(BuildContext context)
|
||||
{
|
||||
var buildParametersContext = context.GetContextObject<BuildParametersContext>();
|
||||
var buildMapContext = CreateBuildMap(true, buildParametersContext.Parameters);
|
||||
context.SetContextObject(buildMapContext);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 409de066b34f4b64fa9eaee790045492
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,31 +0,0 @@
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// 归档文件构建管线的准备任务
|
||||
/// </summary>
|
||||
public class TaskPrepare_AFBP : TaskPrepare, IBuildTask
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
void IBuildTask.Run(BuildContext context)
|
||||
{
|
||||
var buildParametersContext = context.GetContextObject<BuildParametersContext>();
|
||||
var buildParameters = buildParametersContext.Parameters;
|
||||
|
||||
// 检测构建参数
|
||||
buildParametersContext.CheckBuildParameters();
|
||||
|
||||
// 检测未保存场景
|
||||
CheckDirtyScenes();
|
||||
|
||||
// 删除历史缓存
|
||||
if (buildParameters.ClearBuildCacheFiles)
|
||||
{
|
||||
DeletePackageRootDirectory(buildParameters);
|
||||
}
|
||||
|
||||
// 准备输出目录
|
||||
PrepareOutputDirectory(buildParameters);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f463d370e0512bb4c8d79e22fe149500
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,51 +0,0 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// 归档文件构建管线的资源包信息更新任务
|
||||
/// </summary>
|
||||
public class TaskUpdateBundleInfo_AFBP : TaskUpdateBundleInfo, IBuildTask
|
||||
{
|
||||
/// <inheritdoc/>
|
||||
void IBuildTask.Run(BuildContext context)
|
||||
{
|
||||
UpdateBundleInfo(context);
|
||||
}
|
||||
|
||||
protected override string GetUnityHash(BuildBundleInfo bundleInfo, BuildContext context)
|
||||
{
|
||||
return ComputeFileHash(bundleInfo, context);
|
||||
}
|
||||
protected override uint GetUnityCRC(BuildBundleInfo bundleInfo, BuildContext context)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
protected override string GetBundleFileHash(BuildBundleInfo bundleInfo, BuildContext context)
|
||||
{
|
||||
return ComputeFileHash(bundleInfo, context);
|
||||
}
|
||||
protected override uint GetBundleFileCRC(BuildBundleInfo bundleInfo, BuildContext context)
|
||||
{
|
||||
string filePath = bundleInfo.PackageSourceFilePath;
|
||||
return HashUtility.ComputeFileCrc32AsUInt(filePath);
|
||||
}
|
||||
protected override long GetBundleFileSize(BuildBundleInfo bundleInfo, BuildContext context)
|
||||
{
|
||||
string filePath = bundleInfo.PackageSourceFilePath;
|
||||
return FileUtility.GetFileSize(filePath);
|
||||
}
|
||||
|
||||
private string ComputeFileHash(BuildBundleInfo bundleInfo, BuildContext context)
|
||||
{
|
||||
var buildParametersContext = context.GetContextObject<BuildParametersContext>();
|
||||
var parameters = buildParametersContext.Parameters as ArchiveFileBuildParameters;
|
||||
string filePath = bundleInfo.PackageSourceFilePath;
|
||||
if (parameters.IncludePathInHash)
|
||||
return GetFileMD5IncludePath(filePath);
|
||||
else
|
||||
return HashUtility.ComputeFileMD5(filePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6263649b351967840836e9ca443c5574
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -270,27 +270,5 @@ namespace YooAsset.Editor
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检测归档资源包内每个子文件是否超过最大允许大小
|
||||
/// </summary>
|
||||
/// <param name="buildMapContext">构建映射上下文</param>
|
||||
protected void CheckArchiveBundleMapContent(BuildMapContext buildMapContext)
|
||||
{
|
||||
foreach (var bundleInfo in buildMapContext.Collection)
|
||||
{
|
||||
foreach (var asset in bundleInfo.AllPackAssets)
|
||||
{
|
||||
string assetPath = asset.AssetInfo.AssetPath;
|
||||
long fileSize = EditorFileUtility.GetFileSize(assetPath);
|
||||
if (fileSize > ArchiveBundleConsts.MaxChildFileSize)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
$"Archive child file exceeds maximum size ({ArchiveBundleConsts.MaxChildFileSize} bytes): " +
|
||||
$"'{assetPath}' ({fileSize} bytes) in bundle '{bundleInfo.BundleName}'.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -106,16 +106,5 @@ namespace YooAsset.Editor
|
||||
/// <param name="context">构建上下文</param>
|
||||
/// <returns>文件大小</returns>
|
||||
protected abstract long GetBundleFileSize(BuildBundleInfo bundleInfo, BuildContext context);
|
||||
|
||||
/// <summary>
|
||||
/// 计算包含路径信息的文件 MD5
|
||||
/// </summary>
|
||||
protected string GetFileMD5IncludePath(string filePath)
|
||||
{
|
||||
string pathHash = HashUtility.ComputeMD5(filePath.ToLowerInvariant());
|
||||
string contentHash = HashUtility.ComputeFileMD5(filePath);
|
||||
string combined = pathHash + contentHash;
|
||||
return HashUtility.ComputeMD5(combined);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
namespace YooAsset.Editor
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// 编辑器模拟构建管线的构建映射生成任务
|
||||
@@ -12,17 +13,10 @@
|
||||
var buildMapContext = CreateBuildMap(true, buildParametersContext.Parameters);
|
||||
context.SetContextObject(buildMapContext);
|
||||
|
||||
// 注意:检查每个原生文件资源包只能包含一个原生文件
|
||||
if (buildParametersContext.Parameters.BuildBundleType == (int)EBundleType.VirtualRawBundle)
|
||||
if (buildParametersContext.Parameters.BuildBundleType == (int)EBundleType.RawBundle)
|
||||
{
|
||||
CheckRawBundleMapContent(buildMapContext);
|
||||
}
|
||||
|
||||
// 检查归档资源包内每个子文件大小不超过上限
|
||||
if (buildParametersContext.Parameters.BuildBundleType == (int)EBundleType.VirtualArchiveBundle)
|
||||
{
|
||||
CheckArchiveBundleMapContent(buildMapContext);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
using System;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
@@ -7,18 +6,5 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
public class EditorSimulateBuildParameters : BuildParameters
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void CheckBuildParametersCore()
|
||||
{
|
||||
// EditorSimulateBuildPipeline 只允许 VirtualBundle 类型
|
||||
if (BuildBundleType != (int)EBundleType.VirtualAssetBundle &&
|
||||
BuildBundleType != (int)EBundleType.VirtualRawBundle &&
|
||||
BuildBundleType != (int)EBundleType.VirtualArchiveBundle)
|
||||
{
|
||||
string message = BuildLogger.GetErrorMessage(ErrorCode.BuildBundleTypeNotSupported,
|
||||
$"{nameof(EditorSimulateBuildPipeline)} only supports VirtualBundle types. Received: {(EBundleType)BuildBundleType}.");
|
||||
throw new InvalidOperationException(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
|
||||
@@ -36,6 +36,7 @@ namespace YooAsset.Editor
|
||||
/// <remarks>开启此项可以节省运行时清单占用的内存</remarks>
|
||||
public bool ReplaceAssetPathWithAddress = false;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取旧版构建管线的构建选项
|
||||
/// </summary>
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
|
||||
@@ -20,6 +20,8 @@ namespace YooAsset.Editor
|
||||
{
|
||||
string packageOutputDirectory = buildParametersContext.GetPackageOutputDirectory();
|
||||
BuildLogger.Log($"Start making patch package: '{packageOutputDirectory}'.");
|
||||
|
||||
// 拷贝所有补丁文件
|
||||
CopyPackageBundles(buildMapContext);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
@@ -15,9 +16,6 @@ namespace YooAsset.Editor
|
||||
// 检测构建参数
|
||||
buildParametersContext.CheckBuildParameters();
|
||||
|
||||
// 检测未保存场景
|
||||
CheckDirtyScenes();
|
||||
|
||||
// 删除历史缓存
|
||||
if (buildParameters.ClearBuildCacheFiles)
|
||||
{
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
@@ -16,7 +19,18 @@ namespace YooAsset.Editor
|
||||
|
||||
protected override string GetUnityHash(BuildBundleInfo bundleInfo, BuildContext context)
|
||||
{
|
||||
return ComputeFileHash(bundleInfo, 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.ComputeFileMD5(filePath);
|
||||
}
|
||||
}
|
||||
protected override uint GetUnityCRC(BuildBundleInfo bundleInfo, BuildContext context)
|
||||
{
|
||||
@@ -24,7 +38,18 @@ namespace YooAsset.Editor
|
||||
}
|
||||
protected override string GetBundleFileHash(BuildBundleInfo bundleInfo, BuildContext context)
|
||||
{
|
||||
return ComputeFileHash(bundleInfo, 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.ComputeFileMD5(filePath);
|
||||
}
|
||||
}
|
||||
protected override uint GetBundleFileCRC(BuildBundleInfo bundleInfo, BuildContext context)
|
||||
{
|
||||
@@ -37,15 +62,12 @@ namespace YooAsset.Editor
|
||||
return FileUtility.GetFileSize(filePath);
|
||||
}
|
||||
|
||||
private string ComputeFileHash(BuildBundleInfo bundleInfo, BuildContext context)
|
||||
private string GetFileMD5IncludePath(string filePath)
|
||||
{
|
||||
var buildParametersContext = context.GetContextObject<BuildParametersContext>();
|
||||
var parameters = buildParametersContext.Parameters as RawFileBuildParameters;
|
||||
string filePath = bundleInfo.PackageSourceFilePath;
|
||||
if (parameters.IncludePathInHash)
|
||||
return GetFileMD5IncludePath(filePath);
|
||||
else
|
||||
return HashUtility.ComputeFileMD5(filePath);
|
||||
string pathHash = HashUtility.ComputeMD5(filePath.ToLowerInvariant());
|
||||
string contentHash = HashUtility.ComputeFileMD5(filePath);
|
||||
string combined = pathHash + contentHash;
|
||||
return HashUtility.ComputeMD5(combined);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,6 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
@@ -10,7 +11,7 @@ namespace YooAsset.Editor
|
||||
void IBuildTask.Run(BuildContext context)
|
||||
{
|
||||
var buildParametersContext = context.GetContextObject<BuildParametersContext>();
|
||||
var buildParameters = buildParametersContext.Parameters;
|
||||
var buildParameters = buildParametersContext.Parameters as ScriptableBuildParameters;
|
||||
|
||||
// 检测构建参数
|
||||
buildParametersContext.CheckBuildParameters();
|
||||
@@ -28,6 +29,13 @@ namespace YooAsset.Editor
|
||||
|
||||
// 准备输出目录
|
||||
PrepareOutputDirectory(buildParameters);
|
||||
|
||||
// 检测内置着色器资源包名称
|
||||
if (string.IsNullOrEmpty(buildParameters.BuiltinShadersBundleName))
|
||||
{
|
||||
string warning = BuildLogger.GetErrorMessage(ErrorCode.BuiltinShadersBundleNameIsNull, "Builtin shaders bundle name is null. It will cause resource redundancy.");
|
||||
BuildLogger.Warning(warning);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,17 +72,6 @@ namespace YooAsset.Editor
|
||||
public string MonoScriptsBundleName;
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void CheckBuildParametersCore()
|
||||
{
|
||||
// 检测内置着色器资源包名称
|
||||
if (string.IsNullOrEmpty(BuiltinShadersBundleName))
|
||||
{
|
||||
string warning = BuildLogger.GetErrorMessage(ErrorCode.BuiltinShadersBundleNameIsNull, "Builtin shaders bundle name is null. It will cause resource redundancy.");
|
||||
BuildLogger.Warning(warning);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取可编程构建管线的构建参数
|
||||
/// </summary>
|
||||
|
||||
@@ -58,16 +58,6 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
BuildBundleTypeIsUnknown = 117,
|
||||
|
||||
/// <summary>
|
||||
/// 构建管线不支持指定的资源包类型
|
||||
/// </summary>
|
||||
BuildBundleTypeNotSupported = 118,
|
||||
|
||||
/// <summary>
|
||||
/// 构建管线不支持资源包加密
|
||||
/// </summary>
|
||||
BundleEncryptionNotSupported = 119,
|
||||
|
||||
/// <summary>
|
||||
/// 建议使用 SBP 构建管线
|
||||
/// </summary>
|
||||
|
||||
@@ -16,7 +16,9 @@ namespace YooAsset.Editor
|
||||
/// <returns>包裹构建结果</returns>
|
||||
public static PackageBuildResult SimulateBuild(PackageBuildParameters buildParam)
|
||||
{
|
||||
string packageName = buildParam.PackageName;
|
||||
string buildPipelineName = buildParam.BuildPipelineName;
|
||||
|
||||
if (buildPipelineName == EBuildPipeline.EditorSimulateBuildPipeline.ToString())
|
||||
{
|
||||
var buildParameters = new EditorSimulateBuildParameters();
|
||||
@@ -25,7 +27,7 @@ namespace YooAsset.Editor
|
||||
buildParameters.BuildPipeline = EBuildPipeline.EditorSimulateBuildPipeline.ToString();
|
||||
buildParameters.BuildBundleType = buildParam.BuildBundleType;
|
||||
buildParameters.BuildTarget = EditorUserBuildSettings.activeBuildTarget;
|
||||
buildParameters.PackageName = buildParam.PackageName;
|
||||
buildParameters.PackageName = packageName;
|
||||
buildParameters.PackageVersion = "Simulate";
|
||||
buildParameters.FileNameStyle = EFileNameStyle.HashName;
|
||||
buildParameters.BundledCopyOption = EBundledCopyOption.None;
|
||||
|
||||
@@ -30,10 +30,5 @@ namespace YooAsset.Editor
|
||||
/// 团结引擎 InstantAsset 构建管线 (IABP)
|
||||
/// </summary>
|
||||
InstantAssetBuildPipeline,
|
||||
|
||||
/// <summary>
|
||||
/// 归档文件构建管线 (AFBP)
|
||||
/// </summary>
|
||||
ArchiveFileBuildPipeline,
|
||||
}
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 17a0d1dece605b74fb10ceb9761147e9
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,166 +0,0 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using UnityEditor.UIElements;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// 归档文件构建管线(ArchiveFileBuildPipeline)的构建参数查看器
|
||||
/// </summary>
|
||||
[BuildPipelineAttribute(nameof(EBuildPipeline.ArchiveFileBuildPipeline))]
|
||||
internal class ArchiveFileBuildPipelineViewer : BuildPipelineViewerBase
|
||||
{
|
||||
/// <summary>
|
||||
/// 根布局容器(UXML 克隆实例)
|
||||
/// </summary>
|
||||
protected TemplateContainer Root;
|
||||
|
||||
/// <summary>
|
||||
/// 构建输出目录文本框
|
||||
/// </summary>
|
||||
protected TextField _buildOutputField;
|
||||
|
||||
/// <summary>
|
||||
/// 构建版本文本框
|
||||
/// </summary>
|
||||
protected TextField _buildVersionField;
|
||||
|
||||
/// <summary>
|
||||
/// 资源清单加密器下拉框
|
||||
/// </summary>
|
||||
protected PopupField<Type> _manifestEncryptorField;
|
||||
|
||||
/// <summary>
|
||||
/// 资源清单解密器下拉框
|
||||
/// </summary>
|
||||
protected PopupField<Type> _manifestDecryptorField;
|
||||
|
||||
/// <summary>
|
||||
/// 输出文件名称样式枚举字段
|
||||
/// </summary>
|
||||
protected EnumField _outputNameStyleField;
|
||||
|
||||
/// <summary>
|
||||
/// 首包资源拷贝选项枚举字段
|
||||
/// </summary>
|
||||
protected EnumField _bundledCopyOptionField;
|
||||
|
||||
/// <summary>
|
||||
/// 首包资源拷贝标签参数文本框
|
||||
/// </summary>
|
||||
protected TextField _bundledCopyParamField;
|
||||
|
||||
/// <summary>
|
||||
/// 是否清理构建缓存开关
|
||||
/// </summary>
|
||||
protected Toggle _clearBuildCacheToggle;
|
||||
|
||||
/// <summary>
|
||||
/// 是否使用资源依赖数据库开关
|
||||
/// </summary>
|
||||
protected Toggle _useAssetDependencyDBToggle;
|
||||
|
||||
|
||||
public override void CreateView(VisualElement parent)
|
||||
{
|
||||
// 加载布局文件
|
||||
var visualAsset = UxmlLoader.LoadWindowUxml<ArchiveFileBuildPipelineViewer>();
|
||||
if (visualAsset == null)
|
||||
return;
|
||||
|
||||
Root = visualAsset.CloneTree();
|
||||
Root.style.flexGrow = 1f;
|
||||
parent.Add(Root);
|
||||
|
||||
// 输出目录
|
||||
_buildOutputField = Root.Q<TextField>("BuildOutput");
|
||||
SetBuildOutputField(_buildOutputField);
|
||||
|
||||
// 构建版本
|
||||
_buildVersionField = Root.Q<TextField>("BuildVersion");
|
||||
SetBuildVersionField(_buildVersionField);
|
||||
|
||||
// 清单服务
|
||||
var popupContainer = Root.Q("PopupContainer");
|
||||
_manifestEncryptorField = CreateManifestEncryptorField(popupContainer);
|
||||
_manifestDecryptorField = CreateManifestDecryptorField(popupContainer);
|
||||
|
||||
// 输出文件名称样式
|
||||
_outputNameStyleField = Root.Q<EnumField>("FileNameStyle");
|
||||
SetOutputNameStyleField(_outputNameStyleField);
|
||||
|
||||
// 首包资源拷贝参数
|
||||
_bundledCopyParamField = Root.Q<TextField>("BundledCopyParam");
|
||||
SetBundledCopyParamField(_bundledCopyParamField);
|
||||
SetBundledCopyParamVisible(_bundledCopyParamField);
|
||||
|
||||
// 首包资源拷贝选项
|
||||
_bundledCopyOptionField = Root.Q<EnumField>("BundledCopyOption");
|
||||
SetBundledCopyOptionField(_bundledCopyOptionField, _bundledCopyParamField);
|
||||
|
||||
// 清理构建缓存
|
||||
_clearBuildCacheToggle = Root.Q<Toggle>("ClearBuildCache");
|
||||
SetClearBuildCacheToggle(_clearBuildCacheToggle);
|
||||
|
||||
// 使用资源依赖数据库
|
||||
_useAssetDependencyDBToggle = Root.Q<Toggle>("UseAssetDependency");
|
||||
SetUseAssetDependencyDBToggle(_useAssetDependencyDBToggle);
|
||||
|
||||
// 构建按钮
|
||||
var buildButton = Root.Q<Button>("Build");
|
||||
buildButton.clicked += BuildButton_clicked;
|
||||
}
|
||||
|
||||
private void BuildButton_clicked()
|
||||
{
|
||||
if (EditorUtility.DisplayDialog("Info", $"Start building resource package '{PackageName}'.", "Yes", "No"))
|
||||
{
|
||||
EditorWindowUtility.ClearUnityConsole();
|
||||
EditorApplication.delayCall += ExecuteBuild;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogWarning("Packaging has been canceled.");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 执行构建
|
||||
/// </summary>
|
||||
protected virtual void ExecuteBuild()
|
||||
{
|
||||
var fileNameStyle = BundleBuilderSetting.GetPackageFileNameStyle(PackageName, PipelineName);
|
||||
var bundledCopyOption = BundleBuilderSetting.GetPackageBundledCopyOption(PackageName, PipelineName);
|
||||
var bundledCopyParams = BundleBuilderSetting.GetPackageBundledCopyParams(PackageName, PipelineName);
|
||||
var clearBuildCache = BundleBuilderSetting.GetPackageClearBuildCache(PackageName, PipelineName);
|
||||
var useAssetDependencyDB = BundleBuilderSetting.GetPackageUseAssetDependencyDB(PackageName, PipelineName);
|
||||
|
||||
ArchiveFileBuildParameters buildParameters = new ArchiveFileBuildParameters();
|
||||
buildParameters.BuildOutputRoot = BundleBuilderHelper.GetDefaultBuildOutputRoot();
|
||||
buildParameters.BundledFileRoot = BundleBuilderHelper.GetStreamingAssetsRoot();
|
||||
buildParameters.BuildPipeline = PipelineName.ToString();
|
||||
buildParameters.BuildBundleType = (int)EBundleType.ArchiveBundle;
|
||||
buildParameters.BuildTarget = BuildTarget;
|
||||
buildParameters.PackageName = PackageName;
|
||||
buildParameters.PackageVersion = _buildVersionField.value;
|
||||
buildParameters.VerifyBuildingResult = true;
|
||||
buildParameters.FileNameStyle = fileNameStyle;
|
||||
buildParameters.BundledCopyOption = bundledCopyOption;
|
||||
buildParameters.BundledCopyParams = bundledCopyParams;
|
||||
buildParameters.ClearBuildCacheFiles = clearBuildCache;
|
||||
buildParameters.UseAssetDependencyDB = useAssetDependencyDB;
|
||||
buildParameters.ManifestEncryptor = CreateManifestEncryptorInstance();
|
||||
buildParameters.ManifestDecryptor = CreateManifestDecryptorInstance();
|
||||
|
||||
ArchiveFileBuildPipeline pipeline = new ArchiveFileBuildPipeline();
|
||||
var buildResult = pipeline.Run(buildParameters, true);
|
||||
if (buildResult.Success)
|
||||
EditorUtility.RevealInFinder(buildResult.OutputPackageDirectory);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 31e95ed362aa6fb43ad104edf5599b89
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,14 +0,0 @@
|
||||
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../../UIElementsSchema/UIElements.xsd" editor-extension-mode="True">
|
||||
<ui:VisualElement name="BuildContainer">
|
||||
<ui:TextField picking-mode="Ignore" label="Build Output" name="BuildOutput" />
|
||||
<ui:TextField picking-mode="Ignore" label="Build Version" name="BuildVersion" />
|
||||
<ui:Toggle label="Clear Build Cache" name="ClearBuildCache" />
|
||||
<ui:Toggle label="Use Asset Depend DB" name="UseAssetDependency" />
|
||||
<ui:VisualElement name="PopupContainer" style="flex-grow: 1;" />
|
||||
<uie:EnumField label="File Name Style" value="Center" name="FileNameStyle" />
|
||||
<uie:EnumField label="Bundled Copy Option" value="Center" name="BundledCopyOption" />
|
||||
<ui:TextField picking-mode="Ignore" label="Bundled Copy Param" name="BundledCopyParam" />
|
||||
<ui:VisualElement name="ExtensionContainer" />
|
||||
<ui:Button text="Click Build" display-tooltip-when-elided="true" name="Build" style="height: 50px; background-color: rgb(40, 106, 42); margin-top: 10px;" />
|
||||
</ui:VisualElement>
|
||||
</ui:UXML>
|
||||
@@ -1,10 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3a043220a198ef14c8656a51c520ccd3
|
||||
ScriptedImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
script: {fileID: 13804, guid: 0000000000000000e000000000000000, type: 0}
|
||||
@@ -30,11 +30,6 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
protected TextField _buildVersionField;
|
||||
|
||||
/// <summary>
|
||||
/// 构建资源包类型下拉框
|
||||
/// </summary>
|
||||
protected PopupField<string> _buildBundleTypeField;
|
||||
|
||||
|
||||
public override void CreateView(VisualElement parent)
|
||||
{
|
||||
@@ -55,10 +50,6 @@ namespace YooAsset.Editor
|
||||
_buildVersionField = Root.Q<TextField>("BuildVersion");
|
||||
SetBuildVersionField(_buildVersionField);
|
||||
|
||||
// 构建资源包类型
|
||||
var buildBundleTypeContainer = Root.Q<VisualElement>("BuildBundleType");
|
||||
_buildBundleTypeField = CreateBuildBundleTypeField(buildBundleTypeContainer);
|
||||
|
||||
// 构建按钮
|
||||
var buildButton = Root.Q<Button>("Build");
|
||||
buildButton.clicked += BuildButton_clicked;
|
||||
@@ -89,7 +80,7 @@ namespace YooAsset.Editor
|
||||
buildParameters.BuildOutputRoot = BundleBuilderHelper.GetDefaultBuildOutputRoot();
|
||||
buildParameters.BundledFileRoot = BundleBuilderHelper.GetStreamingAssetsRoot();
|
||||
buildParameters.BuildPipeline = PipelineName.ToString();
|
||||
buildParameters.BuildBundleType = (int)Enum.Parse(typeof(EBundleType), _buildBundleTypeField.value);
|
||||
buildParameters.BuildBundleType = (int)EBundleType.VirtualBundle;
|
||||
buildParameters.BuildTarget = BuildTarget;
|
||||
buildParameters.PackageName = PackageName;
|
||||
buildParameters.PackageVersion = _buildVersionField.value;
|
||||
@@ -103,26 +94,5 @@ namespace YooAsset.Editor
|
||||
if (buildResult.Success)
|
||||
EditorUtility.RevealInFinder(buildResult.OutputPackageDirectory);
|
||||
}
|
||||
|
||||
private PopupField<string> CreateBuildBundleTypeField(VisualElement container)
|
||||
{
|
||||
var bundleTypes = Enum.GetValues(typeof(EBundleType))
|
||||
.Cast<EBundleType>()
|
||||
.Where(type => type.ToString().StartsWith("Virtual"))
|
||||
.Select(type => type.ToString())
|
||||
.ToList();
|
||||
|
||||
int defaultIndex = bundleTypes.IndexOf(EBundleType.VirtualAssetBundle.ToString());
|
||||
if (defaultIndex < 0)
|
||||
defaultIndex = 0;
|
||||
|
||||
var popupField = new PopupField<string>(bundleTypes, defaultIndex);
|
||||
popupField.label = "Build Bundle Type";
|
||||
popupField.style.width = StyleWidth;
|
||||
|
||||
container.Add(popupField);
|
||||
UIElementsTools.SetElementLabelMinWidth(popupField, LabelMinWidth);
|
||||
return popupField;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@
|
||||
<ui:VisualElement name="BuildContainer">
|
||||
<ui:TextField picking-mode="Ignore" label="Build Output" name="BuildOutput" />
|
||||
<ui:TextField picking-mode="Ignore" label="Build Version" name="BuildVersion" />
|
||||
<ui:VisualElement name="BuildBundleType" />
|
||||
<ui:VisualElement name="ExtensionContainer" />
|
||||
<ui:Button text="Click Build" display-tooltip-when-elided="true" name="Build" style="height: 50px; background-color: rgb(40, 106, 42); margin-top: 10px;" />
|
||||
</ui:VisualElement>
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 07c436f0dfa2bcf43b12628aed2aa91c
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,52 +0,0 @@
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// 收集资源搜索结果
|
||||
/// </summary>
|
||||
public class CollectAssetSearchResult
|
||||
{
|
||||
/// <summary>
|
||||
/// 命中的收集器分组
|
||||
/// </summary>
|
||||
public BundleCollectorGroup Group { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 命中的收集器分组索引
|
||||
/// </summary>
|
||||
public int GroupIndex { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 命中的收集器
|
||||
/// </summary>
|
||||
public BundleCollector Collector { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 命中的收集器索引
|
||||
/// </summary>
|
||||
public int CollectorIndex { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 命中的资源路径
|
||||
/// </summary>
|
||||
public string AssetPath { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 构建收集资源搜索结果
|
||||
/// </summary>
|
||||
/// <param name="group">命中的收集器分组</param>
|
||||
/// <param name="groupIndex">命中的收集器分组索引</param>
|
||||
/// <param name="collector">命中的收集器</param>
|
||||
/// <param name="collectorIndex">命中的收集器索引</param>
|
||||
/// <param name="assetPath">命中的资源路径</param>
|
||||
public CollectAssetSearchResult(BundleCollectorGroup group, int groupIndex,
|
||||
BundleCollector collector, int collectorIndex, string assetPath)
|
||||
{
|
||||
Group = group;
|
||||
GroupIndex = groupIndex;
|
||||
Collector = collector;
|
||||
CollectorIndex = collectorIndex;
|
||||
AssetPath = assetPath;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ff1a09e6aca8b104c9b256885b06130f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,148 +0,0 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEditor;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// 收集资源搜索工具类
|
||||
/// </summary>
|
||||
public static class CollectAssetSearchUtility
|
||||
{
|
||||
/// <summary>
|
||||
/// 验证搜索路径
|
||||
/// </summary>
|
||||
/// <param name="input">搜索路径</param>
|
||||
/// <returns>搜索路径错误类型</returns>
|
||||
public static ECollectAssetSearchError ValidateSearchPath(string input)
|
||||
{
|
||||
if (string.IsNullOrEmpty(input))
|
||||
return ECollectAssetSearchError.InputPathEmpty;
|
||||
|
||||
if (input.StartsWith("Assets/", StringComparison.OrdinalIgnoreCase) == false)
|
||||
return ECollectAssetSearchError.InputPathMissingAssetsPrefix;
|
||||
|
||||
if (input.EndsWith("/"))
|
||||
return ECollectAssetSearchError.InputPathEndsWithSlash;
|
||||
|
||||
string fileName = System.IO.Path.GetFileName(input);
|
||||
if (fileName.Contains(".") == false)
|
||||
return ECollectAssetSearchError.InputPathMissingExtension;
|
||||
|
||||
if (AssetDatabase.IsValidFolder(input))
|
||||
return ECollectAssetSearchError.InputPathIsFolder;
|
||||
|
||||
string guid = AssetDatabase.AssetPathToGUID(input);
|
||||
if (string.IsNullOrEmpty(guid))
|
||||
return ECollectAssetSearchError.AssetPathNotExists;
|
||||
|
||||
return ECollectAssetSearchError.None;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取搜索路径错误提示信息
|
||||
/// </summary>
|
||||
/// <param name="error">搜索路径错误类型</param>
|
||||
/// <param name="input">搜索路径</param>
|
||||
/// <returns>错误提示信息</returns>
|
||||
public static string GetSearchPathErrorMessage(ECollectAssetSearchError error, string input)
|
||||
{
|
||||
switch (error)
|
||||
{
|
||||
case ECollectAssetSearchError.InputPathEmpty:
|
||||
return "Please enter an asset path.";
|
||||
case ECollectAssetSearchError.InputPathMissingAssetsPrefix:
|
||||
return "Path must start with Assets/.";
|
||||
case ECollectAssetSearchError.InputPathEndsWithSlash:
|
||||
return "Please enter a file path. Do not end with /.";
|
||||
case ECollectAssetSearchError.InputPathMissingExtension:
|
||||
return "Path is missing a file extension (e.g. .prefab, .png, .mat).";
|
||||
case ECollectAssetSearchError.InputPathIsFolder:
|
||||
return "Please enter an asset file path, not a folder path.";
|
||||
case ECollectAssetSearchError.AssetPathNotExists:
|
||||
return $"Asset not found: {input}";
|
||||
default:
|
||||
return "Invalid input format.";
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 在指定 Package 中搜索资源路径,找到第一个命中结果即返回
|
||||
/// </summary>
|
||||
/// <param name="package">搜索的资源包裹</param>
|
||||
/// <param name="assetPath">资源路径</param>
|
||||
/// <returns>搜索结果,如果未找到返回 null</returns>
|
||||
public static CollectAssetSearchResult SearchAssetPath(BundleCollectorPackage package, string assetPath)
|
||||
{
|
||||
if (ValidateSearchPath(assetPath) != ECollectAssetSearchError.None)
|
||||
return null;
|
||||
|
||||
IAssetIgnoreRule ignoreRule = BundleCollectorSettingData.GetAssetIgnoreRuleInstance(package.IgnoreRuleName);
|
||||
var command = new CollectCommand(package.PackageName, ignoreRule);
|
||||
command.SetFlag(ECollectFlags.IgnoreGetDependencies, true);
|
||||
command.UniqueBundleName = BundleCollectorSettingData.Setting.UniqueBundleName;
|
||||
command.EnableAddressable = package.EnableAddressable;
|
||||
command.SupportExtensionless = package.SupportExtensionless;
|
||||
command.LocationToLower = package.LocationToLower;
|
||||
command.IncludeAssetGUID = package.IncludeAssetGUID;
|
||||
command.AutoCollectShaders = package.AutoCollectShaders;
|
||||
|
||||
for (int groupIndex = 0; groupIndex < package.Groups.Count; groupIndex++)
|
||||
{
|
||||
var group = package.Groups[groupIndex];
|
||||
for (int collectIndex = 0; collectIndex < group.Collectors.Count; collectIndex++)
|
||||
{
|
||||
var collector = group.Collectors[collectIndex];
|
||||
|
||||
// 判断收集器是否可能收集指定资源
|
||||
if (IsCandidateCollector(collector, assetPath) == false)
|
||||
continue;
|
||||
|
||||
try
|
||||
{
|
||||
// 检测配置是否有效
|
||||
collector.CheckConfigError();
|
||||
|
||||
// 收集有效资源信息
|
||||
var collectAssets = collector.GetAllCollectAssets(command, group);
|
||||
foreach (var collectAsset in collectAssets)
|
||||
{
|
||||
if (string.Equals(collectAsset.AssetInfo.AssetPath, assetPath, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return new CollectAssetSearchResult(group, groupIndex, collector, collectIndex, assetPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogError($"Invalid collector : {collector.CollectPath}, error: {e.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 未找到匹配资源
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 判断收集器是否可能收集指定资源
|
||||
/// </summary>
|
||||
/// <param name="collector">收集器</param>
|
||||
/// <param name="assetPath">资源路径</param>
|
||||
/// <returns>如果收集器可能收集该资源返回 true</returns>
|
||||
private static bool IsCandidateCollector(BundleCollector collector, string assetPath)
|
||||
{
|
||||
if (string.IsNullOrEmpty(collector.CollectPath))
|
||||
return false;
|
||||
|
||||
if (AssetDatabase.IsValidFolder(collector.CollectPath))
|
||||
{
|
||||
string folderPath = collector.CollectPath.TrimEnd('/') + "/";
|
||||
return assetPath.StartsWith(folderPath, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
// 注意:资源收集器也可能直接配置的单个资源路径
|
||||
return string.Equals(assetPath, collector.CollectPath, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6c8bc2931bda7884198893f1d2e8f364
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,44 +0,0 @@
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// 搜索错误类型
|
||||
/// </summary>
|
||||
public enum ECollectAssetSearchError
|
||||
{
|
||||
/// <summary>
|
||||
/// 无错误
|
||||
/// </summary>
|
||||
None,
|
||||
|
||||
/// <summary>
|
||||
/// 输入路径为空
|
||||
/// </summary>
|
||||
InputPathEmpty,
|
||||
|
||||
/// <summary>
|
||||
/// 输入路径缺少 Assets/ 路径前缀
|
||||
/// </summary>
|
||||
InputPathMissingAssetsPrefix,
|
||||
|
||||
/// <summary>
|
||||
/// 输入路径以斜杠结尾
|
||||
/// </summary>
|
||||
InputPathEndsWithSlash,
|
||||
|
||||
/// <summary>
|
||||
/// 输入路径缺少文件扩展名
|
||||
/// </summary>
|
||||
InputPathMissingExtension,
|
||||
|
||||
/// <summary>
|
||||
/// 输入路径的是文件夹路径
|
||||
/// </summary>
|
||||
InputPathIsFolder,
|
||||
|
||||
/// <summary>
|
||||
/// 资源文件不存在
|
||||
/// </summary>
|
||||
AssetPathNotExists,
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9a2c8a878d6041b4d8bad2a2d2f1896d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -60,22 +60,21 @@ namespace YooAsset.Editor
|
||||
/// <returns>如果收集器配置有效返回 true</returns>
|
||||
public bool IsValid()
|
||||
{
|
||||
string assetGUID = AssetDatabase.AssetPathToGUID(CollectPath);
|
||||
if (string.IsNullOrEmpty(assetGUID))
|
||||
if (AssetDatabase.LoadAssetAtPath<UnityEngine.Object>(CollectPath) == null)
|
||||
return false;
|
||||
|
||||
if (CollectorType == ECollectorType.None)
|
||||
return false;
|
||||
|
||||
if (BundleCollectorSettingData.HasAddressRuleName(AddressRuleName) == false)
|
||||
return false;
|
||||
|
||||
if (BundleCollectorSettingData.HasBundlePackRuleName(PackRuleName) == false)
|
||||
return false;
|
||||
|
||||
if (BundleCollectorSettingData.HasAssetFilterRuleName(FilterRuleName) == false)
|
||||
return false;
|
||||
|
||||
if (BundleCollectorSettingData.HasAddressRuleName(AddressRuleName) == false)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -25,8 +25,6 @@ namespace YooAsset.Editor
|
||||
window.minSize = new Vector2(800, 600);
|
||||
}
|
||||
|
||||
private const string PlaceholderClass = "search-placeholder";
|
||||
|
||||
private Button _saveButton;
|
||||
private List<string> _collectorTypeList;
|
||||
private List<RuleDisplayName> _groupActiveRuleList;
|
||||
@@ -37,11 +35,6 @@ namespace YooAsset.Editor
|
||||
|
||||
private VisualElement _helpBoxContainer;
|
||||
|
||||
private ToolbarSearchField _searchField;
|
||||
private TextField _searchTextField;
|
||||
private Button _searchButton;
|
||||
private Label _searchResultLabel;
|
||||
|
||||
private Button _globalSettingsButton;
|
||||
private Button _packageSettingsButton;
|
||||
|
||||
@@ -73,8 +66,6 @@ namespace YooAsset.Editor
|
||||
private ScrollView _collectorScrollView;
|
||||
private PopupField<RuleDisplayName> _activeRulePopupField;
|
||||
|
||||
private string _highlightAssetPath;
|
||||
private int _highlightCollectorIndex = -1;
|
||||
private int _lastModifyPackageIndex = 0;
|
||||
private int _lastModifyGroupIndex = 0;
|
||||
private bool _showGlobalSettings = false;
|
||||
@@ -228,44 +219,6 @@ namespace YooAsset.Editor
|
||||
_saveButton = root.Q<Button>("SaveButton");
|
||||
_saveButton.clicked += OnSaveButtonClicked;
|
||||
|
||||
// 搜索相关
|
||||
_searchField = root.Q<ToolbarSearchField>("SearchField");
|
||||
_searchTextField = _searchField.Q<TextField>();
|
||||
_searchTextField.RegisterCallback<FocusInEvent>(evt =>
|
||||
{
|
||||
if (_searchTextField.ClassListContains(PlaceholderClass))
|
||||
{
|
||||
_searchField.value = string.Empty;
|
||||
ClearSearchPlaceholder();
|
||||
}
|
||||
});
|
||||
_searchTextField.RegisterCallback<FocusOutEvent>(evt =>
|
||||
{
|
||||
if (string.IsNullOrEmpty(_searchField.value))
|
||||
ApplySearchPlaceholder();
|
||||
});
|
||||
_searchField.RegisterCallback<DragUpdatedEvent>(evt =>
|
||||
{
|
||||
if (DragAndDrop.objectReferences.Length > 0)
|
||||
DragAndDrop.visualMode = DragAndDropVisualMode.Generic;
|
||||
});
|
||||
_searchField.RegisterCallback<DragPerformEvent>(evt =>
|
||||
{
|
||||
if (DragAndDrop.objectReferences.Length > 0)
|
||||
{
|
||||
string assetPath = AssetDatabase.GetAssetPath(DragAndDrop.objectReferences[0]);
|
||||
if (string.IsNullOrEmpty(assetPath) == false)
|
||||
{
|
||||
_searchField.value = assetPath;
|
||||
ClearSearchPlaceholder();
|
||||
}
|
||||
}
|
||||
});
|
||||
ApplySearchPlaceholder();
|
||||
_searchButton = root.Q<Button>("SearchButton");
|
||||
_searchButton.clicked += OnSearchButtonClicked;
|
||||
_searchResultLabel = root.Q<Label>("SearchResultLabel");
|
||||
|
||||
// 包裹容器
|
||||
_packageContainer = root.Q("PackageContainer");
|
||||
|
||||
@@ -470,8 +423,6 @@ namespace YooAsset.Editor
|
||||
|
||||
private void RefreshWindow()
|
||||
{
|
||||
_highlightAssetPath = null;
|
||||
_highlightCollectorIndex = -1;
|
||||
_groupContainer.visible = false;
|
||||
_collectorContainer.visible = false;
|
||||
|
||||
@@ -504,54 +455,6 @@ namespace YooAsset.Editor
|
||||
{
|
||||
BundleCollectorSettingData.SaveFile();
|
||||
}
|
||||
private void OnSearchButtonClicked()
|
||||
{
|
||||
_highlightAssetPath = null;
|
||||
_highlightCollectorIndex = -1;
|
||||
FillCollectorViewData();
|
||||
|
||||
string searchInput = GetSearchInput();
|
||||
var pathError = CollectAssetSearchUtility.ValidateSearchPath(searchInput);
|
||||
if (pathError != ECollectAssetSearchError.None)
|
||||
{
|
||||
string message = CollectAssetSearchUtility.GetSearchPathErrorMessage(pathError, searchInput);
|
||||
ShowSearchResult(message, new Color(1f, 0.4f, 0.4f));
|
||||
return;
|
||||
}
|
||||
|
||||
var selectPackage = _packageListView.selectedItem as BundleCollectorPackage;
|
||||
if (selectPackage == null)
|
||||
{
|
||||
string message = "No package selected. Please select a package first.";
|
||||
ShowSearchResult(message, new Color(1f, 0.8f, 0.3f));
|
||||
return;
|
||||
}
|
||||
|
||||
var searchResult = CollectAssetSearchUtility.SearchAssetPath(selectPackage, searchInput);
|
||||
if (searchResult == null)
|
||||
{
|
||||
string message = $"No results found in package '{selectPackage.PackageName}'.";
|
||||
ShowSearchResult(message, new Color(1f, 0.8f, 0.3f));
|
||||
return;
|
||||
}
|
||||
|
||||
string resultMessage = $"Found in group '{searchResult.Group.GroupName}', collector '{searchResult.Collector.CollectPath}'";
|
||||
ShowSearchResult(resultMessage, Color.white);
|
||||
|
||||
_searchResultLabel.style.unityFontStyleAndWeight = FontStyle.Bold;
|
||||
_searchResultLabel.style.unityTextAlign = TextAnchor.MiddleLeft;
|
||||
|
||||
_highlightAssetPath = searchResult.AssetPath;
|
||||
_highlightCollectorIndex = searchResult.CollectorIndex;
|
||||
|
||||
_groupContainer.visible = true;
|
||||
_lastModifyGroupIndex = searchResult.GroupIndex;
|
||||
|
||||
if (_groupListView.selectedIndex == searchResult.GroupIndex)
|
||||
FillCollectorViewData();
|
||||
else
|
||||
_groupListView.selectedIndex = searchResult.GroupIndex;
|
||||
}
|
||||
private void OnGlobalSettingsButtonClicked()
|
||||
{
|
||||
_showGlobalSettings = !_showGlobalSettings;
|
||||
@@ -577,45 +480,6 @@ namespace YooAsset.Editor
|
||||
return ruleDisplayName.ClassName;
|
||||
}
|
||||
|
||||
// 搜索栏相关
|
||||
private void ShowSearchResult(string message, Color color)
|
||||
{
|
||||
_searchResultLabel.text = message;
|
||||
_searchResultLabel.style.color = color;
|
||||
_searchResultLabel.style.unityFontStyleAndWeight = FontStyle.Normal;
|
||||
_searchResultLabel.style.unityTextAlign = TextAnchor.MiddleCenter;
|
||||
_searchResultLabel.style.display = DisplayStyle.Flex;
|
||||
}
|
||||
private void ClearSearchResult()
|
||||
{
|
||||
_searchResultLabel.text = string.Empty;
|
||||
_searchResultLabel.style.display = DisplayStyle.None;
|
||||
}
|
||||
private void ApplySearchPlaceholder()
|
||||
{
|
||||
_searchField.value = "Drag or enter asset path here (e.g. Assets/Res/icon.png)";
|
||||
if (_searchTextField.ClassListContains(PlaceholderClass) == false)
|
||||
_searchTextField.AddToClassList(PlaceholderClass);
|
||||
|
||||
var inputElement = _searchTextField.Q("unity-text-input");
|
||||
inputElement.style.color = new Color(0.7f, 0.7f, 0.7f, 0.6f);
|
||||
}
|
||||
private void ClearSearchPlaceholder()
|
||||
{
|
||||
if (_searchTextField.ClassListContains(PlaceholderClass))
|
||||
{
|
||||
_searchTextField.RemoveFromClassList(PlaceholderClass);
|
||||
var inputElement = _searchTextField.Q("unity-text-input");
|
||||
inputElement.style.color = StyleKeyword.Null;
|
||||
}
|
||||
}
|
||||
private string GetSearchInput()
|
||||
{
|
||||
if (_searchTextField.ClassListContains(PlaceholderClass))
|
||||
return string.Empty;
|
||||
return _searchField.value;
|
||||
}
|
||||
|
||||
// 设置栏相关
|
||||
private void RefreshSettings()
|
||||
{
|
||||
@@ -743,8 +607,6 @@ namespace YooAsset.Editor
|
||||
}
|
||||
private void OnPackageListViewSelectionChange(IEnumerable<object> objs)
|
||||
{
|
||||
ClearSearchResult();
|
||||
|
||||
var selectPackage = _packageListView.selectedItem as BundleCollectorPackage;
|
||||
if (selectPackage == null)
|
||||
{
|
||||
@@ -890,15 +752,6 @@ namespace YooAsset.Editor
|
||||
BindCollectorListViewItem(element, i);
|
||||
_collectorScrollView.Add(element);
|
||||
}
|
||||
|
||||
if (_highlightCollectorIndex >= 0 && _highlightCollectorIndex < selectGroup.Collectors.Count)
|
||||
{
|
||||
var targetElement = _collectorScrollView[_highlightCollectorIndex];
|
||||
var foldout = targetElement.Q<Foldout>("Foldout1");
|
||||
if (foldout != null)
|
||||
foldout.value = true;
|
||||
_highlightCollectorIndex = -1;
|
||||
}
|
||||
}
|
||||
private VisualElement MakeCollectorListViewItem()
|
||||
{
|
||||
@@ -1180,6 +1033,13 @@ namespace YooAsset.Editor
|
||||
// 清空旧元素
|
||||
foldout.Clear();
|
||||
|
||||
// 检测配置是否有效
|
||||
if (collector.IsValid() == false)
|
||||
{
|
||||
collector.CheckConfigError();
|
||||
return;
|
||||
}
|
||||
|
||||
List<CollectAssetInfo> collectAssetInfos = null;
|
||||
|
||||
try
|
||||
@@ -1195,15 +1055,12 @@ namespace YooAsset.Editor
|
||||
command.IncludeAssetGUID = _includeAssetGUIDToggle.value;
|
||||
command.AutoCollectShaders = _autoCollectShadersToggle.value;
|
||||
|
||||
// 检测配置是否有效
|
||||
collector.CheckConfigError();
|
||||
|
||||
// 收集有效资源信息
|
||||
collectAssetInfos = collector.GetAllCollectAssets(command, group);
|
||||
}
|
||||
catch (Exception e)
|
||||
catch (System.Exception e)
|
||||
{
|
||||
Debug.LogError($"Invalid collector : {collector.CollectPath}, error: {e.Message}");
|
||||
Debug.LogError(e.ToString());
|
||||
}
|
||||
|
||||
if (collectAssetInfos != null)
|
||||
@@ -1228,13 +1085,6 @@ namespace YooAsset.Editor
|
||||
label.style.width = 300;
|
||||
label.style.marginLeft = 0;
|
||||
label.style.flexGrow = 1;
|
||||
|
||||
if (string.IsNullOrEmpty(_highlightAssetPath) == false &&
|
||||
string.Equals(collectAsset.AssetInfo.AssetPath, _highlightAssetPath, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
label.style.color = new Color(1f, 0.2f, 0.2f);
|
||||
}
|
||||
|
||||
elementRow.Add(label);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,11 +5,6 @@
|
||||
<ui:Button text="Import" display-tooltip-when-elided="true" name="ImportButton" style="width: 50px; background-color: rgb(56, 147, 58);" />
|
||||
<ui:Button text="Fix" display-tooltip-when-elided="true" name="FixButton" style="width: 50px; background-color: rgb(56, 147, 58);" />
|
||||
</uie:Toolbar>
|
||||
<uie:Toolbar name="SearchToolbar" style="display: flex; flex-direction: row;">
|
||||
<uie:ToolbarSearchField focusable="true" name="SearchField" style="flex-grow: 1;" />
|
||||
<ui:Button text="Search" display-tooltip-when-elided="true" name="SearchButton" style="width: 60px; background-color: rgb(56, 147, 58);" />
|
||||
</uie:Toolbar>
|
||||
<ui:Label name="SearchResultLabel" style="display: none; height: 24px; -unity-text-align: middle-center; padding-left: 5px; padding-right: 5px;" />
|
||||
<ui:VisualElement name="PublicContainer" style="background-color: rgb(79, 79, 79); border-left-width: 5px; border-right-width: 5px; border-top-width: 5px; border-bottom-width: 5px;">
|
||||
<ui:VisualElement name="HelpBoxContainer" style="flex-grow: 1;" />
|
||||
<ui:VisualElement name="GlobalSettingsContainer">
|
||||
|
||||
@@ -73,12 +73,5 @@ namespace YooAsset
|
||||
/// <param name="bundleGuid">资源包的唯一标识符</param>
|
||||
/// <returns>如果缓存中存在该资源包则返回 true,否则返回 false。</returns>
|
||||
bool IsCached(string bundleGuid);
|
||||
|
||||
/// <summary>
|
||||
/// 获取已缓存的资源包文件路径
|
||||
/// </summary>
|
||||
/// <param name="bundleGuid">资源包的唯一标识符</param>
|
||||
/// <returns>返回已缓存的资源包文件路径,如果不存在则返回 null。</returns>
|
||||
string GetCacheFilePath(string bundleGuid);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ namespace YooAsset
|
||||
internal interface ICacheEntry
|
||||
{
|
||||
/// <summary>
|
||||
/// 资源包唯一标识
|
||||
/// Bundle 唯一标识
|
||||
/// </summary>
|
||||
string BundleGuid { get; }
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
namespace YooAsset
|
||||
{
|
||||
/// <summary>
|
||||
/// 清理缓存的操作选项
|
||||
/// 清理缓存操作选项
|
||||
/// </summary>
|
||||
internal readonly struct BCClearCacheOptions
|
||||
{
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
namespace YooAsset
|
||||
{
|
||||
/// <summary>
|
||||
/// 加载资源包的操作选项
|
||||
/// 加载资源包操作选项
|
||||
/// </summary>
|
||||
internal readonly struct BCLoadBundleOptions
|
||||
{
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
namespace YooAsset
|
||||
{
|
||||
/// <summary>
|
||||
/// 验证缓存的操作选项
|
||||
/// 验证缓存操作选项
|
||||
/// </summary>
|
||||
internal readonly struct BCVerifyCacheOptions
|
||||
{
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
namespace YooAsset
|
||||
{
|
||||
/// <summary>
|
||||
/// 写入缓存的操作选项
|
||||
/// 写入缓存操作选项
|
||||
/// </summary>
|
||||
internal readonly struct BCWriteCacheOptions
|
||||
{
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 创建加载内置资源目录操作实例
|
||||
/// </summary>
|
||||
/// <param name="options">加载内置资源目录的操作选项</param>
|
||||
/// <param name="options">加载内置资源目录的配置选项</param>
|
||||
internal LoadBuiltinCatalogOperation(LoadBuiltinCatalogOptions options)
|
||||
{
|
||||
_options = options;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
namespace YooAsset
|
||||
{
|
||||
/// <summary>
|
||||
/// 加载内置资源目录的操作选项
|
||||
/// 加载内置资源目录操作选项
|
||||
/// </summary>
|
||||
internal readonly struct LoadBuiltinCatalogOptions
|
||||
{
|
||||
|
||||
@@ -1,99 +0,0 @@
|
||||
using System;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
/// <summary>
|
||||
/// 从本地加载 ArchiveBundle 操作
|
||||
/// </summary>
|
||||
internal sealed class LoadLocalArchiveBundleOperation : BCLoadBundleOperation
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
LoadBundle,
|
||||
CheckResult,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly LoadLocalArchiveBundleOptions _options;
|
||||
private ArchiveBundle _archiveBundle;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
/// <summary>
|
||||
/// 创建本地 ArchiveBundle 加载操作实例
|
||||
/// </summary>
|
||||
/// <param name="options">从本地加载 ArchiveBundle 的操作选项</param>
|
||||
public LoadLocalArchiveBundleOperation(LoadLocalArchiveBundleOptions options)
|
||||
{
|
||||
_options = options;
|
||||
}
|
||||
protected override void InternalStart()
|
||||
{
|
||||
_steps = ESteps.LoadBundle;
|
||||
}
|
||||
protected override void InternalUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.LoadBundle)
|
||||
{
|
||||
if (_options.Bundle.IsEncrypted)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
SetError($"ArchiveBundle encrypted loading is not supported: '{_options.FilePath}'.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (FileUtility.IsFileIOSupported(_options.FilePath) == false)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
SetError($"FileIO is not supported for builtin path: '{_options.FilePath}'.");
|
||||
return;
|
||||
}
|
||||
|
||||
LoadResult result = ParseArchiveFile();
|
||||
if (result.Succeeded == false)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
SetError(result.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
_steps = ESteps.CheckResult;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.CheckResult)
|
||||
{
|
||||
if (_archiveBundle == null)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
SetError($"Loaded archive bundle is null.");
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
SetResult();
|
||||
BundleHandle = new ArchiveBundleHandle(_options.Bundle, _archiveBundle);
|
||||
}
|
||||
}
|
||||
}
|
||||
protected override void InternalWaitForCompletion()
|
||||
{
|
||||
ExecuteBatch();
|
||||
}
|
||||
|
||||
private LoadResult ParseArchiveFile()
|
||||
{
|
||||
try
|
||||
{
|
||||
_archiveBundle = ArchiveBundleHelper.LoadArchiveBundle(_options.FilePath);
|
||||
return LoadResult.Default();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return LoadResult.Failure($"Failed to parse archive file: {ex.Message}.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2bda507c0443af147bc0f8999f5b1229
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,31 +0,0 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
/// <summary>
|
||||
/// 加载 ArchiveBundle 的操作选项
|
||||
/// </summary>
|
||||
internal readonly struct LoadLocalArchiveBundleOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// 文件缓存名称
|
||||
/// </summary>
|
||||
public string CacheName { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 资源包描述
|
||||
/// </summary>
|
||||
public PackageBundle Bundle { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 文件加载路径
|
||||
/// </summary>
|
||||
public string FilePath { get; }
|
||||
|
||||
public LoadLocalArchiveBundleOptions(string cacheName, PackageBundle bundle, string filePath)
|
||||
{
|
||||
CacheName = cacheName;
|
||||
Bundle = bundle;
|
||||
FilePath = filePath;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cb278952b9622084da5b2515b095aef8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -30,7 +30,7 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 创建本地 AssetBundle 加载操作实例
|
||||
/// </summary>
|
||||
/// <param name="options">从本地加载 AssetBundle 的操作选项</param>
|
||||
/// <param name="options">从本地加载 AssetBundle 的配置选项</param>
|
||||
public LoadLocalAssetBundleOperation(LoadLocalAssetBundleOptions options)
|
||||
{
|
||||
_options = options;
|
||||
@@ -121,7 +121,7 @@ namespace YooAsset
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
SetResult();
|
||||
BundleHandle = new AssetBundleHandle(_options.Bundle, _assetBundle, _loadStream);
|
||||
BundleHandle = new AssetBundleHandle(_options.FilePath, _options.Bundle, _assetBundle, _loadStream);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
namespace YooAsset
|
||||
{
|
||||
/// <summary>
|
||||
/// 加载 AssetBundle 的操作选项
|
||||
/// 加载 AssetBundle 的上下文信息
|
||||
/// </summary>
|
||||
internal readonly struct LoadLocalAssetBundleOptions
|
||||
{
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace YooAsset
|
||||
/// <summary>
|
||||
/// 创建本地 RawBundle 加载操作实例
|
||||
/// </summary>
|
||||
/// <param name="options">从本地加载 RawBundle 的操作选项</param>
|
||||
/// <param name="options">从本地加载 RawBundle 的配置选项</param>
|
||||
public LoadLocalRawBundleOperation(LoadLocalRawBundleOptions options)
|
||||
{
|
||||
_options = options;
|
||||
@@ -100,7 +100,7 @@ namespace YooAsset
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
SetResult();
|
||||
BundleHandle = new RawBundleHandle(_options.Bundle, _rawBundle);
|
||||
BundleHandle = new RawBundleHandle(_options.FilePath, _options.Bundle, _rawBundle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
namespace YooAsset
|
||||
{
|
||||
/// <summary>
|
||||
/// 加载 RawBundle 的操作选项
|
||||
/// 加载 RawBundle 的上下文信息
|
||||
/// </summary>
|
||||
internal readonly struct LoadLocalRawBundleOptions
|
||||
{
|
||||
|
||||
@@ -22,9 +22,9 @@ namespace YooAsset
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
/// <summary>
|
||||
/// 创建 AssetBundle 加载操作实例
|
||||
/// 创建 LoadWebNormalAssetBundleOperation 实例
|
||||
/// </summary>
|
||||
/// <param name="options">从网络加载 AssetBundle 的操作选项</param>
|
||||
/// <param name="options">从网络加载 AssetBundle 的配置选项</param>
|
||||
public LoadWebNormalAssetBundleOperation(LoadWebAssetBundleOptions options)
|
||||
{
|
||||
_options = options;
|
||||
@@ -75,7 +75,7 @@ namespace YooAsset
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
SetResult();
|
||||
BundleHandle = new AssetBundleHandle(_options.Bundle, assetBundle, null);
|
||||
BundleHandle = new AssetBundleHandle(_downloadAssetBundleRequest.Url, _options.Bundle, assetBundle, null);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -133,7 +133,6 @@ namespace YooAsset
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
Prepare,
|
||||
DataRequest,
|
||||
CheckRequest,
|
||||
VerifyData,
|
||||
@@ -151,9 +150,9 @@ namespace YooAsset
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
/// <summary>
|
||||
/// 创建网络 AssetBundle 加载操作实例
|
||||
/// 创建 LoadWebEncryptedAssetBundleOperation 实例
|
||||
/// </summary>
|
||||
/// <param name="options">从网络加载 AssetBundle 的操作选项</param>
|
||||
/// <param name="options">从网络加载 AssetBundle 的配置选项</param>
|
||||
public LoadWebEncryptedAssetBundleOperation(LoadWebAssetBundleOptions options)
|
||||
{
|
||||
_options = options;
|
||||
@@ -163,27 +162,34 @@ namespace YooAsset
|
||||
}
|
||||
protected override void InternalStart()
|
||||
{
|
||||
_steps = ESteps.Prepare;
|
||||
_steps = ESteps.DataRequest;
|
||||
}
|
||||
protected override void InternalUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.Prepare)
|
||||
if (_steps == ESteps.DataRequest)
|
||||
{
|
||||
var decryptor = _options.AssetBundleDecryptor;
|
||||
if (decryptor == null)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
SetError($"{_options.CacheName} asset bundle decryptor is null.");
|
||||
SetError($"{_options.CacheName} decryptor is null.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (decryptor is IBundleMemoryDecryptor)
|
||||
{
|
||||
_decryptor = decryptor as IBundleMemoryDecryptor;
|
||||
_steps = ESteps.DataRequest;
|
||||
string url = _options.DownloadUrlPolicy.SelectUrl(_options.CandidateUrls);
|
||||
var args = new DownloadDataRequestArgs(
|
||||
url: url,
|
||||
timeout: 0,
|
||||
watchdogTimeout: _options.WatchdogTimeout);
|
||||
_downloadBytesRequest = _options.DownloadBackend.CreateBytesRequest(args);
|
||||
_downloadBytesRequest.SendRequest();
|
||||
_steps = ESteps.CheckRequest;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -193,18 +199,6 @@ namespace YooAsset
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.DataRequest)
|
||||
{
|
||||
string url = _options.DownloadUrlPolicy.SelectUrl(_options.CandidateUrls);
|
||||
var args = new DownloadDataRequestArgs(
|
||||
url: url,
|
||||
timeout: 0,
|
||||
watchdogTimeout: _options.WatchdogTimeout);
|
||||
_downloadBytesRequest = _options.DownloadBackend.CreateBytesRequest(args);
|
||||
_downloadBytesRequest.SendRequest();
|
||||
_steps = ESteps.CheckRequest;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.CheckRequest)
|
||||
{
|
||||
Progress = _downloadBytesRequest.DownloadProgress;
|
||||
@@ -231,7 +225,6 @@ namespace YooAsset
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
SetError(_downloadBytesRequest.Error);
|
||||
YooLogger.LogError(Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -253,7 +246,7 @@ namespace YooAsset
|
||||
}
|
||||
else
|
||||
{
|
||||
string error = $"Verify failed. Url: '{_downloadBytesRequest.Url}' Level: {_options.DownloadVerifyLevel} Result: {verifyResult}.";
|
||||
string error = $"[WebBundleVerify] Verify failed. Url: '{_downloadBytesRequest.Url}' Level: {_options.DownloadVerifyLevel} Result: {verifyResult}.";
|
||||
YooLogger.LogWarning(error);
|
||||
|
||||
if (IsWaitForCompletion == false && _downloadRetryController.HasRetriesRemaining())
|
||||
@@ -297,7 +290,7 @@ namespace YooAsset
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
SetResult();
|
||||
BundleHandle = new AssetBundleHandle(_options.Bundle, assetBundle, null);
|
||||
BundleHandle = new AssetBundleHandle(_downloadBytesRequest.Url, _options.Bundle, assetBundle, null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ using System.Collections.Generic;
|
||||
namespace YooAsset
|
||||
{
|
||||
/// <summary>
|
||||
/// 加载 AssetBundle 的操作选项
|
||||
/// 加载 AssetBundle 的上下文信息
|
||||
/// </summary>
|
||||
internal readonly struct LoadWebAssetBundleOptions
|
||||
{
|
||||
|
||||
@@ -1,212 +0,0 @@
|
||||
namespace YooAsset
|
||||
{
|
||||
/// <summary>
|
||||
/// 从网络加载 RawBundle 操作
|
||||
/// </summary>
|
||||
internal sealed class LoadWebRawBundleOperation : BCLoadBundleOperation
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
Prepare,
|
||||
DataRequest,
|
||||
CheckRequest,
|
||||
VerifyData,
|
||||
LoadBundle,
|
||||
TryAgain,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly LoadWebRawBundleOptions _options;
|
||||
private readonly DownloadRetryController _downloadRetryController;
|
||||
private IDownloadBytesRequest _downloadBytesRequest;
|
||||
private IBundleMemoryDecryptor _decryptor;
|
||||
private RawBundle _rawBundle;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
/// <summary>
|
||||
/// 创建网络 RawBundle 加载操作实例
|
||||
/// </summary>
|
||||
/// <param name="options">从网络加载 RawBundle 的操作选项</param>
|
||||
internal LoadWebRawBundleOperation(LoadWebRawBundleOptions options)
|
||||
{
|
||||
_options = options;
|
||||
|
||||
// 注意:网络原因失败后,重新尝试直到成功
|
||||
_downloadRetryController = new DownloadRetryController(int.MaxValue, options.DownloadRetryPolicy);
|
||||
}
|
||||
protected override void InternalStart()
|
||||
{
|
||||
_steps = ESteps.Prepare;
|
||||
}
|
||||
protected override void InternalUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.Prepare)
|
||||
{
|
||||
if (_options.Bundle.IsEncrypted == false)
|
||||
{
|
||||
_steps = ESteps.DataRequest;
|
||||
}
|
||||
else
|
||||
{
|
||||
var decryptor = _options.RawBundleDecryptor;
|
||||
if (decryptor == null)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
SetError($"{_options.CacheName} raw bundle decryptor is null.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (decryptor is IBundleMemoryDecryptor)
|
||||
{
|
||||
_decryptor = decryptor as IBundleMemoryDecryptor;
|
||||
_steps = ESteps.DataRequest;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
SetError($"{_options.CacheName} does not support '{decryptor.GetType().Name}'.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.DataRequest)
|
||||
{
|
||||
string url = _options.DownloadUrlPolicy.SelectUrl(_options.CandidateUrls);
|
||||
var args = new DownloadDataRequestArgs(
|
||||
url: url,
|
||||
timeout: 0,
|
||||
watchdogTimeout: _options.WatchdogTimeout);
|
||||
_downloadBytesRequest = _options.DownloadBackend.CreateBytesRequest(args);
|
||||
_downloadBytesRequest.SendRequest();
|
||||
_steps = ESteps.CheckRequest;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.CheckRequest)
|
||||
{
|
||||
Progress = _downloadBytesRequest.DownloadProgress;
|
||||
if (_downloadBytesRequest.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_downloadBytesRequest.Status == EDownloadRequestStatus.Succeeded)
|
||||
{
|
||||
_options.DownloadUrlPolicy.OnRequestSucceeded(_downloadBytesRequest.Url);
|
||||
_steps = ESteps.VerifyData;
|
||||
}
|
||||
else
|
||||
{
|
||||
string url = _downloadBytesRequest.Url;
|
||||
long httpCode = _downloadBytesRequest.HttpCode;
|
||||
string httpError = _downloadBytesRequest.HttpError;
|
||||
_options.DownloadUrlPolicy.OnRequestFailed(url, httpCode, httpError);
|
||||
if (IsWaitForCompletion == false && _downloadRetryController.CanRetryRequest(url, httpCode, httpError))
|
||||
{
|
||||
_downloadRetryController.StartRetryDelay();
|
||||
_steps = ESteps.TryAgain;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
SetError(_downloadBytesRequest.Error);
|
||||
YooLogger.LogError(Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.VerifyData)
|
||||
{
|
||||
// 注意:网络/代理/服务器异常导致内容不完整但请求仍成功
|
||||
EFileVerifyResult verifyResult;
|
||||
if (_options.DownloadVerifyLevel == EFileVerifyLevel.Low || _options.DownloadVerifyLevel == EFileVerifyLevel.Middle)
|
||||
verifyResult = FileVerifyHelper.VerifyFile(_downloadBytesRequest.Result, _options.Bundle.FileSize, 0);
|
||||
else if (_options.DownloadVerifyLevel == EFileVerifyLevel.High)
|
||||
verifyResult = FileVerifyHelper.VerifyFile(_downloadBytesRequest.Result, _options.Bundle.FileSize, _options.Bundle.FileCrc);
|
||||
else
|
||||
throw new YooInternalException($"Unexpected verify level: {_options.DownloadVerifyLevel}.");
|
||||
|
||||
if (verifyResult == EFileVerifyResult.Succeed)
|
||||
{
|
||||
_steps = ESteps.LoadBundle;
|
||||
}
|
||||
else
|
||||
{
|
||||
string error = $"Verify failed. Url: '{_downloadBytesRequest.Url}' Level: {_options.DownloadVerifyLevel} Result: {verifyResult}.";
|
||||
YooLogger.LogWarning(error);
|
||||
|
||||
if (IsWaitForCompletion == false && _downloadRetryController.HasRetriesRemaining())
|
||||
{
|
||||
_downloadRetryController.StartRetryDelay();
|
||||
_steps = ESteps.TryAgain;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
SetError(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.LoadBundle)
|
||||
{
|
||||
LoadResult result = LoadFromMemory(_decryptor, _downloadBytesRequest.Result);
|
||||
if (result.Succeeded == false)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
SetError(result.Error);
|
||||
return;
|
||||
}
|
||||
|
||||
_steps = ESteps.Done;
|
||||
SetResult();
|
||||
BundleHandle = new RawBundleHandle(_options.Bundle, _rawBundle);
|
||||
}
|
||||
|
||||
if (_steps == ESteps.TryAgain)
|
||||
{
|
||||
// 注意:失败后释放网络请求
|
||||
if (_downloadBytesRequest != null)
|
||||
{
|
||||
_downloadBytesRequest.Dispose();
|
||||
_downloadBytesRequest = null;
|
||||
}
|
||||
|
||||
if (_downloadRetryController.TickRetryDelay())
|
||||
{
|
||||
Progress = 0f;
|
||||
_steps = ESteps.DataRequest;
|
||||
}
|
||||
}
|
||||
}
|
||||
protected override void InternalDispose()
|
||||
{
|
||||
if (_downloadBytesRequest != null)
|
||||
{
|
||||
_downloadBytesRequest.Dispose();
|
||||
_downloadBytesRequest = null;
|
||||
}
|
||||
}
|
||||
|
||||
private LoadResult LoadFromMemory(IBundleMemoryDecryptor decryptor, byte[] fileData)
|
||||
{
|
||||
if (decryptor != null)
|
||||
{
|
||||
var args = new BundleDecryptArgs(_options.Bundle, fileData, null);
|
||||
var binaryData = decryptor.GetDecryptedData(args);
|
||||
if (binaryData == null)
|
||||
return LoadResult.Failure($"{_options.CacheName} decryptor returned null data.");
|
||||
|
||||
_rawBundle = new RawBundle(binaryData);
|
||||
return LoadResult.Default();
|
||||
}
|
||||
else
|
||||
{
|
||||
_rawBundle = new RawBundle(fileData);
|
||||
return LoadResult.Default();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b30e1d41b966e63488837244e907363b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,70 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
/// <summary>
|
||||
/// 加载 RawBundle 的操作选项
|
||||
/// </summary>
|
||||
internal readonly struct LoadWebRawBundleOptions
|
||||
{
|
||||
/// <summary>
|
||||
/// 文件缓存名称
|
||||
/// </summary>
|
||||
public string CacheName { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 资源包描述
|
||||
/// </summary>
|
||||
public PackageBundle Bundle { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 候选下载地址列表
|
||||
/// </summary>
|
||||
public IReadOnlyList<string> CandidateUrls { get; }
|
||||
|
||||
/// <summary>
|
||||
/// RawBundle 解密器
|
||||
/// </summary>
|
||||
public IBundleDecryptor RawBundleDecryptor { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 下载后台接口
|
||||
/// </summary>
|
||||
public IDownloadBackend DownloadBackend { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 下载数据校验级别
|
||||
/// </summary>
|
||||
public EFileVerifyLevel DownloadVerifyLevel { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 看门狗超时时间
|
||||
/// </summary>
|
||||
public int WatchdogTimeout { get; }
|
||||
|
||||
/// <summary>
|
||||
/// 下载重试判定策略
|
||||
/// </summary>
|
||||
public IDownloadRetryPolicy DownloadRetryPolicy { get; }
|
||||
|
||||
/// <summary>
|
||||
/// URL 选择策略
|
||||
/// </summary>
|
||||
public IDownloadUrlPolicy DownloadUrlPolicy { get; }
|
||||
|
||||
public LoadWebRawBundleOptions(string cacheName, PackageBundle bundle, IReadOnlyList<string> candidateUrls,
|
||||
IBundleDecryptor rawBundleDecryptor, IDownloadBackend downloadBackend, EFileVerifyLevel downloadVerifyLevel,
|
||||
int watchdogTimeout, IDownloadRetryPolicy downloadRetryPolicy, IDownloadUrlPolicy downloadUrlPolicy)
|
||||
{
|
||||
CacheName = cacheName;
|
||||
Bundle = bundle;
|
||||
CandidateUrls = candidateUrls;
|
||||
RawBundleDecryptor = rawBundleDecryptor;
|
||||
DownloadBackend = downloadBackend;
|
||||
DownloadVerifyLevel = downloadVerifyLevel;
|
||||
WatchdogTimeout = watchdogTimeout;
|
||||
DownloadRetryPolicy = downloadRetryPolicy;
|
||||
DownloadUrlPolicy = downloadUrlPolicy;
|
||||
}
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user