mirror of
https://github.com/tuyoogame/YooAsset.git
synced 2026-05-14 19:40:47 +00:00
Compare commits
2 Commits
4c717b69db
...
6b23927f71
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6b23927f71 | ||
|
|
dfa9ff6954 |
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2e49e0ae672b9944783571b2ad737df9
|
||||
guid: da26c791ca572fe4a818405173661568
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
@@ -0,0 +1,112 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3f8daa3aacb5da8458fc073431da1891
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,46 @@
|
||||
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}.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 83bdf0f6502d23f49ae900d98f459c7b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,48 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 19ef6fc50bd422c4db6fa53cbf0fe226
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,61 @@
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a03062dc3dd175c438fcb92d3e06a33b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b9dccc7a4589001469444e571235890a
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,29 @@
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 289e760820002e34b9054a81098d5fa4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,23 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e4fb32a77b3e799448cf4eae2a97a49e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,21 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 813f7821d87b6f8498ddc4d675512413
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,21 @@
|
||||
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>();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 21e10b308293d2e45972a9b4ba143a74
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,23 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 721f0030551d41c40a2c6d3206c3897a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,23 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3e12187230b544940aeae7cb3c556299
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,17 @@
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 16ff5758e3a98b64193c61ca68e94ddd
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,17 @@
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 409de066b34f4b64fa9eaee790045492
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,31 @@
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f463d370e0512bb4c8d79e22fe149500
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,51 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6263649b351967840836e9ca443c5574
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,5 +1,4 @@
|
||||
|
||||
namespace YooAsset.Editor
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
/// <summary>
|
||||
/// 编辑器模拟构建管线的构建映射生成任务
|
||||
@@ -13,10 +12,17 @@ namespace YooAsset.Editor
|
||||
var buildMapContext = CreateBuildMap(true, buildParametersContext.Parameters);
|
||||
context.SetContextObject(buildMapContext);
|
||||
|
||||
if (buildParametersContext.Parameters.BuildBundleType == (int)EBundleType.RawBundle)
|
||||
// 注意:检查每个原生文件资源包只能包含一个原生文件
|
||||
if (buildParametersContext.Parameters.BuildBundleType == (int)EBundleType.VirtualRawBundle)
|
||||
{
|
||||
CheckRawBundleMapContent(buildMapContext);
|
||||
}
|
||||
|
||||
// 检查归档资源包内每个子文件大小不超过上限
|
||||
if (buildParametersContext.Parameters.BuildBundleType == (int)EBundleType.VirtualArchiveBundle)
|
||||
{
|
||||
CheckArchiveBundleMapContent(buildMapContext);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
using System;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
@@ -6,5 +7,18 @@ 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,4 +1,3 @@
|
||||
using System;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
|
||||
@@ -36,7 +36,6 @@ namespace YooAsset.Editor
|
||||
/// <remarks>开启此项可以节省运行时清单占用的内存</remarks>
|
||||
public bool ReplaceAssetPathWithAddress = false;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取旧版构建管线的构建选项
|
||||
/// </summary>
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
|
||||
@@ -20,8 +20,6 @@ namespace YooAsset.Editor
|
||||
{
|
||||
string packageOutputDirectory = buildParametersContext.GetPackageOutputDirectory();
|
||||
BuildLogger.Log($"Start making patch package: '{packageOutputDirectory}'.");
|
||||
|
||||
// 拷贝所有补丁文件
|
||||
CopyPackageBundles(buildMapContext);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
using System;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
@@ -16,6 +15,9 @@ namespace YooAsset.Editor
|
||||
// 检测构建参数
|
||||
buildParametersContext.CheckBuildParameters();
|
||||
|
||||
// 检测未保存场景
|
||||
CheckDirtyScenes();
|
||||
|
||||
// 删除历史缓存
|
||||
if (buildParameters.ClearBuildCacheFiles)
|
||||
{
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
@@ -19,18 +16,7 @@ namespace YooAsset.Editor
|
||||
|
||||
protected override string GetUnityHash(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.ComputeFileMD5(filePath);
|
||||
}
|
||||
return ComputeFileHash(bundleInfo, context);
|
||||
}
|
||||
protected override uint GetUnityCRC(BuildBundleInfo bundleInfo, BuildContext context)
|
||||
{
|
||||
@@ -38,18 +24,7 @@ namespace YooAsset.Editor
|
||||
}
|
||||
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.ComputeFileMD5(filePath);
|
||||
}
|
||||
return ComputeFileHash(bundleInfo, context);
|
||||
}
|
||||
protected override uint GetBundleFileCRC(BuildBundleInfo bundleInfo, BuildContext context)
|
||||
{
|
||||
@@ -62,12 +37,15 @@ namespace YooAsset.Editor
|
||||
return FileUtility.GetFileSize(filePath);
|
||||
}
|
||||
|
||||
private string GetFileMD5IncludePath(string filePath)
|
||||
private string ComputeFileHash(BuildBundleInfo bundleInfo, BuildContext context)
|
||||
{
|
||||
string pathHash = HashUtility.ComputeMD5(filePath.ToLowerInvariant());
|
||||
string contentHash = HashUtility.ComputeFileMD5(filePath);
|
||||
string combined = pathHash + contentHash;
|
||||
return HashUtility.ComputeMD5(combined);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,3 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
using System;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
@@ -11,7 +10,7 @@ namespace YooAsset.Editor
|
||||
void IBuildTask.Run(BuildContext context)
|
||||
{
|
||||
var buildParametersContext = context.GetContextObject<BuildParametersContext>();
|
||||
var buildParameters = buildParametersContext.Parameters as ScriptableBuildParameters;
|
||||
var buildParameters = buildParametersContext.Parameters;
|
||||
|
||||
// 检测构建参数
|
||||
buildParametersContext.CheckBuildParameters();
|
||||
@@ -29,13 +28,6 @@ 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,6 +72,17 @@ 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,6 +58,16 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
BuildBundleTypeIsUnknown = 117,
|
||||
|
||||
/// <summary>
|
||||
/// 构建管线不支持指定的资源包类型
|
||||
/// </summary>
|
||||
BuildBundleTypeNotSupported = 118,
|
||||
|
||||
/// <summary>
|
||||
/// 构建管线不支持资源包加密
|
||||
/// </summary>
|
||||
BundleEncryptionNotSupported = 119,
|
||||
|
||||
/// <summary>
|
||||
/// 建议使用 SBP 构建管线
|
||||
/// </summary>
|
||||
|
||||
@@ -270,5 +270,27 @@ 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,5 +106,16 @@ 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,9 +16,7 @@ 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();
|
||||
@@ -27,7 +25,7 @@ namespace YooAsset.Editor
|
||||
buildParameters.BuildPipeline = EBuildPipeline.EditorSimulateBuildPipeline.ToString();
|
||||
buildParameters.BuildBundleType = buildParam.BuildBundleType;
|
||||
buildParameters.BuildTarget = EditorUserBuildSettings.activeBuildTarget;
|
||||
buildParameters.PackageName = packageName;
|
||||
buildParameters.PackageName = buildParam.PackageName;
|
||||
buildParameters.PackageVersion = "Simulate";
|
||||
buildParameters.FileNameStyle = EFileNameStyle.HashName;
|
||||
buildParameters.BundledCopyOption = EBundledCopyOption.None;
|
||||
|
||||
@@ -30,5 +30,10 @@ namespace YooAsset.Editor
|
||||
/// 团结引擎 InstantAsset 构建管线 (IABP)
|
||||
/// </summary>
|
||||
InstantAssetBuildPipeline,
|
||||
|
||||
/// <summary>
|
||||
/// 归档文件构建管线 (AFBP)
|
||||
/// </summary>
|
||||
ArchiveFileBuildPipeline,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 17a0d1dece605b74fb10ceb9761147e9
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,166 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 31e95ed362aa6fb43ad104edf5599b89
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,14 @@
|
||||
<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>
|
||||
@@ -0,0 +1,10 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3a043220a198ef14c8656a51c520ccd3
|
||||
ScriptedImporter:
|
||||
internalIDToNameTable: []
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
script: {fileID: 13804, guid: 0000000000000000e000000000000000, type: 0}
|
||||
@@ -30,6 +30,11 @@ namespace YooAsset.Editor
|
||||
/// </summary>
|
||||
protected TextField _buildVersionField;
|
||||
|
||||
/// <summary>
|
||||
/// 构建资源包类型下拉框
|
||||
/// </summary>
|
||||
protected DropdownField _buildBundleTypeField;
|
||||
|
||||
|
||||
public override void CreateView(VisualElement parent)
|
||||
{
|
||||
@@ -50,6 +55,10 @@ namespace YooAsset.Editor
|
||||
_buildVersionField = Root.Q<TextField>("BuildVersion");
|
||||
SetBuildVersionField(_buildVersionField);
|
||||
|
||||
// 构建资源包类型
|
||||
_buildBundleTypeField = Root.Q<DropdownField>("BuildBundleType");
|
||||
SetBuildBundleTypeField(_buildBundleTypeField);
|
||||
|
||||
// 构建按钮
|
||||
var buildButton = Root.Q<Button>("Build");
|
||||
buildButton.clicked += BuildButton_clicked;
|
||||
@@ -80,7 +89,7 @@ namespace YooAsset.Editor
|
||||
buildParameters.BuildOutputRoot = BundleBuilderHelper.GetDefaultBuildOutputRoot();
|
||||
buildParameters.BundledFileRoot = BundleBuilderHelper.GetStreamingAssetsRoot();
|
||||
buildParameters.BuildPipeline = PipelineName.ToString();
|
||||
buildParameters.BuildBundleType = (int)EBundleType.VirtualBundle;
|
||||
buildParameters.BuildBundleType = (int)Enum.Parse(typeof(EBundleType), _buildBundleTypeField.value);
|
||||
buildParameters.BuildTarget = BuildTarget;
|
||||
buildParameters.PackageName = PackageName;
|
||||
buildParameters.PackageVersion = _buildVersionField.value;
|
||||
@@ -94,5 +103,19 @@ namespace YooAsset.Editor
|
||||
if (buildResult.Success)
|
||||
EditorUtility.RevealInFinder(buildResult.OutputPackageDirectory);
|
||||
}
|
||||
|
||||
private void SetBuildBundleTypeField(DropdownField dropdownField)
|
||||
{
|
||||
var bundleTypes = Enum.GetValues(typeof(EBundleType))
|
||||
.Cast<EBundleType>()
|
||||
.Where(type => type.ToString().StartsWith("Virtual"))
|
||||
.Select(type => type.ToString())
|
||||
.ToList();
|
||||
|
||||
dropdownField.choices = bundleTypes;
|
||||
dropdownField.SetValueWithoutNotify(EBundleType.VirtualAssetBundle.ToString());
|
||||
dropdownField.style.width = StyleWidth;
|
||||
UIElementsTools.SetElementLabelMinWidth(dropdownField, LabelMinWidth);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
<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:DropdownField label="Build Bundle Type" 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>
|
||||
|
||||
@@ -0,0 +1,99 @@
|
||||
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.FilePath, _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}.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2bda507c0443af147bc0f8999f5b1229
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,31 @@
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: cb278952b9622084da5b2515b095aef8
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -118,6 +118,11 @@ namespace YooAsset
|
||||
var operation = new BBCLoadRawBundleOperation(this, options.Bundle);
|
||||
return operation;
|
||||
}
|
||||
else if (options.Bundle.GetBundleType() == (int)EBundleType.ArchiveBundle)
|
||||
{
|
||||
var operation = new BBCLoadArchiveBundleOperation(this, options.Bundle);
|
||||
return operation;
|
||||
}
|
||||
else
|
||||
{
|
||||
string error = $"{nameof(BuiltinBundleCache)} does not support bundle type: {options.Bundle.GetBundleType()}.";
|
||||
|
||||
@@ -0,0 +1,97 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
/// <summary>
|
||||
/// 内置文件缓存加载 ArchiveBundle 操作
|
||||
/// </summary>
|
||||
internal sealed class BBCLoadArchiveBundleOperation : BCLoadBundleOperation
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
GetEntry,
|
||||
LoadBundle,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly BuiltinBundleCache _fileCache;
|
||||
private readonly PackageBundle _bundle;
|
||||
private LoadLocalArchiveBundleOperation _loadLocalArchiveBundleOp;
|
||||
private BuiltinBundleCacheEntry _cacheEntry;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
/// <summary>
|
||||
/// 创建内置 ArchiveBundle 加载操作实例
|
||||
/// </summary>
|
||||
/// <param name="fileCache">内置文件缓存系统</param>
|
||||
/// <param name="bundle">资源包描述</param>
|
||||
public BBCLoadArchiveBundleOperation(BuiltinBundleCache fileCache, PackageBundle bundle)
|
||||
{
|
||||
_fileCache = fileCache;
|
||||
_bundle = bundle;
|
||||
}
|
||||
protected override void InternalStart()
|
||||
{
|
||||
_steps = ESteps.GetEntry;
|
||||
}
|
||||
protected override void InternalUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.GetEntry)
|
||||
{
|
||||
_cacheEntry = _fileCache.GetEntry(_bundle.BundleGuid);
|
||||
if (_cacheEntry == null)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
SetError($"File cache entry not found: '{_bundle.BundleGuid}'.");
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.LoadBundle;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.LoadBundle)
|
||||
{
|
||||
if (_loadLocalArchiveBundleOp == null)
|
||||
{
|
||||
var options = new LoadLocalArchiveBundleOptions(
|
||||
cacheName: _fileCache.GetType().Name,
|
||||
bundle: _bundle,
|
||||
filePath: _cacheEntry.FilePath);
|
||||
_loadLocalArchiveBundleOp = new LoadLocalArchiveBundleOperation(options);
|
||||
_loadLocalArchiveBundleOp.StartOperation();
|
||||
AddChildOperation(_loadLocalArchiveBundleOp);
|
||||
}
|
||||
|
||||
if (IsWaitForCompletion)
|
||||
_loadLocalArchiveBundleOp.WaitForCompletion();
|
||||
|
||||
_loadLocalArchiveBundleOp.UpdateOperation();
|
||||
if (_loadLocalArchiveBundleOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_loadLocalArchiveBundleOp.Status == EOperationStatus.Succeeded)
|
||||
{
|
||||
if (_loadLocalArchiveBundleOp.BundleHandle == null)
|
||||
throw new YooInternalException("Loaded archive bundle handle is null.");
|
||||
|
||||
_steps = ESteps.Done;
|
||||
SetResult();
|
||||
BundleHandle = _loadLocalArchiveBundleOp.BundleHandle;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
SetError(_loadLocalArchiveBundleOp.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
protected override void InternalWaitForCompletion()
|
||||
{
|
||||
ExecuteBatch();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a0848660bde87a2419d2dbc34b9f587c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -95,94 +95,4 @@ namespace YooAsset
|
||||
ExecuteBatch();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 内置文件缓存加载 RawBundle 操作
|
||||
/// </summary>
|
||||
internal sealed class BBCLoadRawBundleOperation : BCLoadBundleOperation
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
GetEntry,
|
||||
LoadBundle,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly BuiltinBundleCache _fileCache;
|
||||
private readonly PackageBundle _bundle;
|
||||
private LoadLocalRawBundleOperation _loadLocalRawBundleOp;
|
||||
private BuiltinBundleCacheEntry _cacheEntry;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
public BBCLoadRawBundleOperation(BuiltinBundleCache fileCache, PackageBundle bundle)
|
||||
{
|
||||
_fileCache = fileCache;
|
||||
_bundle = bundle;
|
||||
}
|
||||
protected override void InternalStart()
|
||||
{
|
||||
_steps = ESteps.GetEntry;
|
||||
}
|
||||
protected override void InternalUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.GetEntry)
|
||||
{
|
||||
_cacheEntry = _fileCache.GetEntry(_bundle.BundleGuid);
|
||||
if (_cacheEntry == null)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
SetError($"File cache entry not found: '{_bundle.BundleGuid}'.");
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.LoadBundle;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.LoadBundle)
|
||||
{
|
||||
if(_loadLocalRawBundleOp == null)
|
||||
{
|
||||
var options = new LoadLocalRawBundleOptions(
|
||||
cacheName: _fileCache.GetType().Name,
|
||||
bundle: _bundle,
|
||||
filePath: _cacheEntry.FilePath,
|
||||
rawBundleDecryptor: _fileCache.Config.RawBundleDecryptor);
|
||||
_loadLocalRawBundleOp = new LoadLocalRawBundleOperation(options);
|
||||
_loadLocalRawBundleOp.StartOperation();
|
||||
AddChildOperation(_loadLocalRawBundleOp);
|
||||
}
|
||||
|
||||
if (IsWaitForCompletion)
|
||||
_loadLocalRawBundleOp.WaitForCompletion();
|
||||
|
||||
_loadLocalRawBundleOp.UpdateOperation();
|
||||
if (_loadLocalRawBundleOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if(_loadLocalRawBundleOp.Status == EOperationStatus.Succeeded)
|
||||
{
|
||||
if (_loadLocalRawBundleOp.BundleHandle == null)
|
||||
throw new YooInternalException("Loaded bundle handle is null.");
|
||||
|
||||
_steps = ESteps.Done;
|
||||
SetResult();
|
||||
BundleHandle = _loadLocalRawBundleOp.BundleHandle;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
SetError(_loadLocalRawBundleOp.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
protected override void InternalWaitForCompletion()
|
||||
{
|
||||
ExecuteBatch();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,93 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
/// <summary>
|
||||
/// 内置文件缓存加载 RawBundle 操作
|
||||
/// </summary>
|
||||
internal sealed class BBCLoadRawBundleOperation : BCLoadBundleOperation
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
GetEntry,
|
||||
LoadBundle,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly BuiltinBundleCache _fileCache;
|
||||
private readonly PackageBundle _bundle;
|
||||
private LoadLocalRawBundleOperation _loadLocalRawBundleOp;
|
||||
private BuiltinBundleCacheEntry _cacheEntry;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
public BBCLoadRawBundleOperation(BuiltinBundleCache fileCache, PackageBundle bundle)
|
||||
{
|
||||
_fileCache = fileCache;
|
||||
_bundle = bundle;
|
||||
}
|
||||
protected override void InternalStart()
|
||||
{
|
||||
_steps = ESteps.GetEntry;
|
||||
}
|
||||
protected override void InternalUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.GetEntry)
|
||||
{
|
||||
_cacheEntry = _fileCache.GetEntry(_bundle.BundleGuid);
|
||||
if (_cacheEntry == null)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
SetError($"File cache entry not found: '{_bundle.BundleGuid}'.");
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.LoadBundle;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.LoadBundle)
|
||||
{
|
||||
if(_loadLocalRawBundleOp == null)
|
||||
{
|
||||
var options = new LoadLocalRawBundleOptions(
|
||||
cacheName: _fileCache.GetType().Name,
|
||||
bundle: _bundle,
|
||||
filePath: _cacheEntry.FilePath,
|
||||
rawBundleDecryptor: _fileCache.Config.RawBundleDecryptor);
|
||||
_loadLocalRawBundleOp = new LoadLocalRawBundleOperation(options);
|
||||
_loadLocalRawBundleOp.StartOperation();
|
||||
AddChildOperation(_loadLocalRawBundleOp);
|
||||
}
|
||||
|
||||
if (IsWaitForCompletion)
|
||||
_loadLocalRawBundleOp.WaitForCompletion();
|
||||
|
||||
_loadLocalRawBundleOp.UpdateOperation();
|
||||
if (_loadLocalRawBundleOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if(_loadLocalRawBundleOp.Status == EOperationStatus.Succeeded)
|
||||
{
|
||||
if (_loadLocalRawBundleOp.BundleHandle == null)
|
||||
throw new YooInternalException("Loaded raw bundle handle is null.");
|
||||
|
||||
_steps = ESteps.Done;
|
||||
SetResult();
|
||||
BundleHandle = _loadLocalRawBundleOp.BundleHandle;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
SetError(_loadLocalRawBundleOp.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
protected override void InternalWaitForCompletion()
|
||||
{
|
||||
ExecuteBatch();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 902c99ab0d4f6b34995fd47a9cf3172b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -117,14 +117,19 @@ namespace YooAsset
|
||||
/// <inheritdoc />
|
||||
public BCLoadBundleOperation LoadBundleAsync(BCLoadBundleOptions options)
|
||||
{
|
||||
if (options.Bundle.GetBundleType() == (int)EBundleType.VirtualBundle)
|
||||
if (options.Bundle.GetBundleType() == (int)EBundleType.VirtualAssetBundle)
|
||||
{
|
||||
var operation = new EBCLoadVirtualBundleOperation(this, options.Bundle);
|
||||
var operation = new EBCLoadVirtualAssetBundleOperation(this, options.Bundle);
|
||||
return operation;
|
||||
}
|
||||
else if (options.Bundle.GetBundleType() == (int)EBundleType.RawBundle)
|
||||
else if (options.Bundle.GetBundleType() == (int)EBundleType.VirtualRawBundle)
|
||||
{
|
||||
var operation = new EBCLoadRawBundleOperation(this, options.Bundle);
|
||||
var operation = new EBCLoadVirtualRawBundleOperation(this, options.Bundle);
|
||||
return operation;
|
||||
}
|
||||
else if (options.Bundle.GetBundleType() == (int)EBundleType.VirtualArchiveBundle)
|
||||
{
|
||||
var operation = new EBCLoadVirtualArchiveBundleOperation(this, options.Bundle);
|
||||
return operation;
|
||||
}
|
||||
else
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
@@ -12,14 +10,12 @@ namespace YooAsset
|
||||
{
|
||||
None,
|
||||
CheckCache,
|
||||
CheckFilePath,
|
||||
LoadBundle,
|
||||
Done,
|
||||
}
|
||||
|
||||
protected readonly EditorBundleCache _fileCache;
|
||||
protected readonly PackageBundle _bundle;
|
||||
protected string _editorFilePath;
|
||||
private int _asyncSimulateFrame;
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
@@ -47,21 +43,7 @@ namespace YooAsset
|
||||
return;
|
||||
}
|
||||
|
||||
_steps = ESteps.CheckFilePath;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.CheckFilePath)
|
||||
{
|
||||
_editorFilePath = EditorFileSystemHelper.GetEditorFilePath(_bundle);
|
||||
if (string.IsNullOrEmpty(_editorFilePath))
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
SetError($"Editor file path is null. Bundle: '{_bundle.BundleName}'.");
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.LoadBundle;
|
||||
}
|
||||
_steps = ESteps.LoadBundle;
|
||||
}
|
||||
|
||||
if (_steps == ESteps.LoadBundle)
|
||||
@@ -107,44 +89,4 @@ namespace YooAsset
|
||||
return UnityEngine.Random.Range(_fileCache.Config.AsyncSimulateMinFrame, _fileCache.Config.AsyncSimulateMaxFrame + 1);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 编辑器文件缓存加载虚拟资源包操作
|
||||
/// </summary>
|
||||
internal sealed class EBCLoadVirtualBundleOperation : EBCLoadBundleBaseOperation
|
||||
{
|
||||
public EBCLoadVirtualBundleOperation(EditorBundleCache fileCache, PackageBundle bundle)
|
||||
: base(fileCache, bundle) { }
|
||||
|
||||
protected override void CreateBundleHandle()
|
||||
{
|
||||
SetResult();
|
||||
BundleHandle = new VirtualBundleHandle(_editorFilePath, _bundle);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 编辑器文件缓存加载原生资源包操作
|
||||
/// </summary>
|
||||
internal sealed class EBCLoadRawBundleOperation : EBCLoadBundleBaseOperation
|
||||
{
|
||||
public EBCLoadRawBundleOperation(EditorBundleCache fileCache, PackageBundle bundle)
|
||||
: base(fileCache, bundle) { }
|
||||
|
||||
protected override void CreateBundleHandle()
|
||||
{
|
||||
try
|
||||
{
|
||||
byte[] data = File.ReadAllBytes(_editorFilePath);
|
||||
var rawBundle = new RawBundle(data);
|
||||
SetResult();
|
||||
BundleHandle = new RawBundleHandle(_editorFilePath, _bundle, rawBundle);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
SetError($"Failed to load raw bundle: {ex.Message}.");
|
||||
YooLogger.LogError(Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
/// <summary>
|
||||
/// 编辑器文件缓存加载虚拟归档资源包操作
|
||||
/// </summary>
|
||||
internal sealed class EBCLoadVirtualArchiveBundleOperation : EBCLoadBundleBaseOperation
|
||||
{
|
||||
public EBCLoadVirtualArchiveBundleOperation(EditorBundleCache fileCache, PackageBundle bundle)
|
||||
: base(fileCache, bundle) { }
|
||||
|
||||
protected override void CreateBundleHandle()
|
||||
{
|
||||
if (_bundle.MainAssets.Count == 0)
|
||||
{
|
||||
SetError($"Virtual archive bundle has no main assets. Bundle: '{_bundle.BundleName}'.");
|
||||
return;
|
||||
}
|
||||
|
||||
var archiveAssetPaths = new HashSet<string>();
|
||||
foreach (var packageAsset in _bundle.MainAssets)
|
||||
{
|
||||
archiveAssetPaths.Add(packageAsset.AssetPath);
|
||||
}
|
||||
|
||||
var virtualArchiveBundle = new VirtualArchiveBundle(archiveAssetPaths);
|
||||
string virtualBundlePath = $"VirtualArchiveBundle://{_bundle.BundleName}";
|
||||
|
||||
SetResult();
|
||||
BundleHandle = new VirtualArchiveBundleHandle(virtualBundlePath, _bundle, virtualArchiveBundle);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2c5933cfa184e744caf09534b4205a7d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,27 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
/// <summary>
|
||||
/// 编辑器文件缓存加载虚拟资源包操作
|
||||
/// </summary>
|
||||
internal sealed class EBCLoadVirtualAssetBundleOperation : EBCLoadBundleBaseOperation
|
||||
{
|
||||
public EBCLoadVirtualAssetBundleOperation(EditorBundleCache fileCache, PackageBundle bundle)
|
||||
: base(fileCache, bundle) { }
|
||||
|
||||
protected override void CreateBundleHandle()
|
||||
{
|
||||
string editorFilePath = EditorFileSystemHelper.GetEditorFilePath(_bundle);
|
||||
if (string.IsNullOrEmpty(editorFilePath))
|
||||
{
|
||||
SetError($"Editor file path is null. Bundle: '{_bundle.BundleName}'.");
|
||||
return;
|
||||
}
|
||||
|
||||
SetResult();
|
||||
BundleHandle = new VirtualAssetBundleHandle(editorFilePath, _bundle);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ada198bd3d003a0419611c4dfc53b00a
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
/// <summary>
|
||||
/// 编辑器文件缓存加载原生资源包操作
|
||||
/// </summary>
|
||||
internal sealed class EBCLoadVirtualRawBundleOperation : EBCLoadBundleBaseOperation
|
||||
{
|
||||
public EBCLoadVirtualRawBundleOperation(EditorBundleCache fileCache, PackageBundle bundle)
|
||||
: base(fileCache, bundle) { }
|
||||
|
||||
protected override void CreateBundleHandle()
|
||||
{
|
||||
string editorFilePath = EditorFileSystemHelper.GetEditorFilePath(_bundle);
|
||||
if (string.IsNullOrEmpty(editorFilePath))
|
||||
{
|
||||
SetError($"Editor file path is null. Bundle: '{_bundle.BundleName}'.");
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
byte[] data = File.ReadAllBytes(editorFilePath);
|
||||
var rawBundle = new RawBundle(data);
|
||||
|
||||
SetResult();
|
||||
BundleHandle = new VirtualRawBundleHandle(editorFilePath, _bundle, rawBundle);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
SetError($"Failed to read raw bundle file: {ex.Message}.");
|
||||
YooLogger.LogError(Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0bea6c7169e36554eb2d33ec897c9aa9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,98 @@
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
/// <summary>
|
||||
/// 沙盒文件缓存加载 ArchiveBundle 操作
|
||||
/// </summary>
|
||||
internal sealed class SBCLoadArchiveBundleOperation : BCLoadBundleOperation
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
GetEntry,
|
||||
LoadBundle,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly SandboxBundleCache _fileCache;
|
||||
private readonly PackageBundle _bundle;
|
||||
private LoadLocalArchiveBundleOperation _loadLocalArchiveBundleOp;
|
||||
private SandboxBundleCacheEntry _cacheEntry;
|
||||
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
/// <summary>
|
||||
/// 创建沙盒 ArchiveBundle 加载操作实例
|
||||
/// </summary>
|
||||
/// <param name="fileCache">沙盒文件缓存系统</param>
|
||||
/// <param name="bundle">资源包描述</param>
|
||||
public SBCLoadArchiveBundleOperation(SandboxBundleCache fileCache, PackageBundle bundle)
|
||||
{
|
||||
_fileCache = fileCache;
|
||||
_bundle = bundle;
|
||||
}
|
||||
protected override void InternalStart()
|
||||
{
|
||||
_steps = ESteps.GetEntry;
|
||||
}
|
||||
protected override void InternalUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.GetEntry)
|
||||
{
|
||||
_cacheEntry = _fileCache.GetEntry(_bundle.BundleGuid);
|
||||
if (_cacheEntry == null)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
SetError($"File cache entry not found: '{_bundle.BundleGuid}'.");
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.LoadBundle;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.LoadBundle)
|
||||
{
|
||||
if (_loadLocalArchiveBundleOp == null)
|
||||
{
|
||||
var options = new LoadLocalArchiveBundleOptions(
|
||||
cacheName: _fileCache.GetType().Name,
|
||||
bundle: _bundle,
|
||||
filePath: _cacheEntry.DataFilePath);
|
||||
_loadLocalArchiveBundleOp = new LoadLocalArchiveBundleOperation(options);
|
||||
_loadLocalArchiveBundleOp.StartOperation();
|
||||
AddChildOperation(_loadLocalArchiveBundleOp);
|
||||
}
|
||||
|
||||
if (IsWaitForCompletion)
|
||||
_loadLocalArchiveBundleOp.WaitForCompletion();
|
||||
|
||||
_loadLocalArchiveBundleOp.UpdateOperation();
|
||||
if (_loadLocalArchiveBundleOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_loadLocalArchiveBundleOp.Status == EOperationStatus.Succeeded)
|
||||
{
|
||||
if (_loadLocalArchiveBundleOp.BundleHandle == null)
|
||||
throw new YooInternalException("Loaded archive bundle handle is null.");
|
||||
|
||||
_steps = ESteps.Done;
|
||||
SetResult();
|
||||
BundleHandle = _loadLocalArchiveBundleOp.BundleHandle;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
SetError(_loadLocalArchiveBundleOp.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
protected override void InternalWaitForCompletion()
|
||||
{
|
||||
ExecuteBatch();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a2636312b474afb469ed624ae6c2e3a5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -209,122 +209,4 @@ namespace YooAsset
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 沙盒文件缓存加载 RawBundle 操作
|
||||
/// </summary>
|
||||
internal sealed class SBCLoadRawBundleOperation : BCLoadBundleOperation
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
GetEntry,
|
||||
LoadBundle,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly SandboxBundleCache _fileCache;
|
||||
private readonly PackageBundle _bundle;
|
||||
private LoadLocalRawBundleOperation _loadLocalRawBundleOp;
|
||||
private SandboxBundleCacheEntry _cacheEntry;
|
||||
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
/// <summary>
|
||||
/// 创建沙盒 RawBundle 加载操作实例
|
||||
/// </summary>
|
||||
/// <param name="fileCache">沙盒文件缓存系统</param>
|
||||
/// <param name="bundle">资源包描述</param>
|
||||
public SBCLoadRawBundleOperation(SandboxBundleCache fileCache, PackageBundle bundle)
|
||||
{
|
||||
_fileCache = fileCache;
|
||||
_bundle = bundle;
|
||||
}
|
||||
protected override void InternalStart()
|
||||
{
|
||||
_steps = ESteps.GetEntry;
|
||||
}
|
||||
protected override void InternalUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.GetEntry)
|
||||
{
|
||||
_cacheEntry = _fileCache.GetEntry(_bundle.BundleGuid);
|
||||
if (_cacheEntry == null)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
SetError($"File cache entry not found: '{_bundle.BundleGuid}'.");
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.LoadBundle;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.LoadBundle)
|
||||
{
|
||||
if (_loadLocalRawBundleOp == null)
|
||||
{
|
||||
var options = new LoadLocalRawBundleOptions(
|
||||
cacheName: _fileCache.GetType().Name,
|
||||
bundle: _bundle,
|
||||
filePath: _cacheEntry.DataFilePath,
|
||||
rawBundleDecryptor: _fileCache.Config.RawBundleDecryptor);
|
||||
_loadLocalRawBundleOp = new LoadLocalRawBundleOperation(options);
|
||||
_loadLocalRawBundleOp.StartOperation();
|
||||
AddChildOperation(_loadLocalRawBundleOp);
|
||||
}
|
||||
|
||||
if (IsWaitForCompletion)
|
||||
_loadLocalRawBundleOp.WaitForCompletion();
|
||||
|
||||
_loadLocalRawBundleOp.UpdateOperation();
|
||||
if (_loadLocalRawBundleOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_loadLocalRawBundleOp.Status == EOperationStatus.Succeeded)
|
||||
{
|
||||
if (_loadLocalRawBundleOp.BundleHandle == null)
|
||||
throw new YooInternalException("Loaded raw bundle handle is null.");
|
||||
|
||||
_steps = ESteps.Done;
|
||||
SetResult();
|
||||
BundleHandle = _loadLocalRawBundleOp.BundleHandle;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
SetError(_loadLocalRawBundleOp.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
protected override void InternalWaitForCompletion()
|
||||
{
|
||||
ExecuteBatch();
|
||||
}
|
||||
}
|
||||
|
||||
#if TUANJIE_1_8_OR_NEWER
|
||||
internal sealed class SBCLoadInstantBundleOperation : BCLoadBundleOperation
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
GetEntry,
|
||||
LoadBundle,
|
||||
Done,
|
||||
}
|
||||
|
||||
protected override void InternalStart()
|
||||
{
|
||||
throw new NotImplementedException($"{nameof(SBCLoadInstantBundleOperation)} is not implemented.");
|
||||
}
|
||||
protected override void InternalUpdate()
|
||||
{
|
||||
throw new NotImplementedException($"{nameof(SBCLoadInstantBundleOperation)} is not implemented.");
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using UnityEngine;
|
||||
|
||||
namespace YooAsset
|
||||
{
|
||||
/// <summary>
|
||||
/// 沙盒文件缓存加载 RawBundle 操作
|
||||
/// </summary>
|
||||
internal sealed class SBCLoadRawBundleOperation : BCLoadBundleOperation
|
||||
{
|
||||
private enum ESteps
|
||||
{
|
||||
None,
|
||||
GetEntry,
|
||||
LoadBundle,
|
||||
Done,
|
||||
}
|
||||
|
||||
private readonly SandboxBundleCache _fileCache;
|
||||
private readonly PackageBundle _bundle;
|
||||
private LoadLocalRawBundleOperation _loadLocalRawBundleOp;
|
||||
private SandboxBundleCacheEntry _cacheEntry;
|
||||
|
||||
private ESteps _steps = ESteps.None;
|
||||
|
||||
/// <summary>
|
||||
/// 创建沙盒 RawBundle 加载操作实例
|
||||
/// </summary>
|
||||
/// <param name="fileCache">沙盒文件缓存系统</param>
|
||||
/// <param name="bundle">资源包描述</param>
|
||||
public SBCLoadRawBundleOperation(SandboxBundleCache fileCache, PackageBundle bundle)
|
||||
{
|
||||
_fileCache = fileCache;
|
||||
_bundle = bundle;
|
||||
}
|
||||
protected override void InternalStart()
|
||||
{
|
||||
_steps = ESteps.GetEntry;
|
||||
}
|
||||
protected override void InternalUpdate()
|
||||
{
|
||||
if (_steps == ESteps.None || _steps == ESteps.Done)
|
||||
return;
|
||||
|
||||
if (_steps == ESteps.GetEntry)
|
||||
{
|
||||
_cacheEntry = _fileCache.GetEntry(_bundle.BundleGuid);
|
||||
if (_cacheEntry == null)
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
SetError($"File cache entry not found: '{_bundle.BundleGuid}'.");
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.LoadBundle;
|
||||
}
|
||||
}
|
||||
|
||||
if (_steps == ESteps.LoadBundle)
|
||||
{
|
||||
if (_loadLocalRawBundleOp == null)
|
||||
{
|
||||
var options = new LoadLocalRawBundleOptions(
|
||||
cacheName: _fileCache.GetType().Name,
|
||||
bundle: _bundle,
|
||||
filePath: _cacheEntry.DataFilePath,
|
||||
rawBundleDecryptor: _fileCache.Config.RawBundleDecryptor);
|
||||
_loadLocalRawBundleOp = new LoadLocalRawBundleOperation(options);
|
||||
_loadLocalRawBundleOp.StartOperation();
|
||||
AddChildOperation(_loadLocalRawBundleOp);
|
||||
}
|
||||
|
||||
if (IsWaitForCompletion)
|
||||
_loadLocalRawBundleOp.WaitForCompletion();
|
||||
|
||||
_loadLocalRawBundleOp.UpdateOperation();
|
||||
if (_loadLocalRawBundleOp.IsDone == false)
|
||||
return;
|
||||
|
||||
if (_loadLocalRawBundleOp.Status == EOperationStatus.Succeeded)
|
||||
{
|
||||
if (_loadLocalRawBundleOp.BundleHandle == null)
|
||||
throw new YooInternalException("Loaded raw bundle handle is null.");
|
||||
|
||||
_steps = ESteps.Done;
|
||||
SetResult();
|
||||
BundleHandle = _loadLocalRawBundleOp.BundleHandle;
|
||||
}
|
||||
else
|
||||
{
|
||||
_steps = ESteps.Done;
|
||||
SetError(_loadLocalRawBundleOp.Error);
|
||||
}
|
||||
}
|
||||
}
|
||||
protected override void InternalWaitForCompletion()
|
||||
{
|
||||
ExecuteBatch();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ab6c7b21f247bff4997e36040109f0a5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -137,6 +137,11 @@ namespace YooAsset
|
||||
var operation = new SBCLoadRawBundleOperation(this, options.Bundle);
|
||||
return operation;
|
||||
}
|
||||
else if (options.Bundle.GetBundleType() == (int)EBundleType.ArchiveBundle)
|
||||
{
|
||||
var operation = new SBCLoadArchiveBundleOperation(this, options.Bundle);
|
||||
return operation;
|
||||
}
|
||||
else
|
||||
{
|
||||
string error = $"{nameof(SandboxBundleCache)} does not support bundle type: {options.Bundle.GetBundleType()}.";
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user