mirror of https://github.com/tuyoogame/YooAsset
Update AssetBundleBuilder
parent
1253ce71af
commit
4ea52a9287
|
@ -35,6 +35,26 @@ namespace YooAsset.Editor
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 构建内容哈希值
|
||||
/// </summary>
|
||||
public string ContentHash { set; get; } = "00000000000000000000000000000000"; //32位
|
||||
|
||||
/// <summary>
|
||||
/// 文件哈希值
|
||||
/// </summary>
|
||||
public string FileHash { set; get; } = "00000000000000000000000000000000"; //32位
|
||||
|
||||
/// <summary>
|
||||
/// 文件CRC32
|
||||
/// </summary>
|
||||
public string FileCRC { set; get; } = "00000000"; //8位
|
||||
|
||||
/// <summary>
|
||||
/// 文件大小
|
||||
/// </summary>
|
||||
public long FileSize { set; get; } = 0;
|
||||
|
||||
|
||||
public BuildBundleInfo(string bundleName)
|
||||
{
|
||||
|
|
|
@ -34,19 +34,24 @@ namespace YooAsset.Editor
|
|||
public string FileName;
|
||||
|
||||
/// <summary>
|
||||
/// 哈希值
|
||||
/// 内容哈希值
|
||||
/// </summary>
|
||||
public string Hash;
|
||||
public string ContentHash;
|
||||
|
||||
/// <summary>
|
||||
/// 文件哈希值
|
||||
/// </summary>
|
||||
public string FileHash;
|
||||
|
||||
/// <summary>
|
||||
/// 文件校验码
|
||||
/// </summary>
|
||||
public string CRC;
|
||||
public string FileCRC;
|
||||
|
||||
/// <summary>
|
||||
/// 文件大小(字节数)
|
||||
/// </summary>
|
||||
public long SizeBytes;
|
||||
public long FileSize;
|
||||
|
||||
/// <summary>
|
||||
/// Tags
|
||||
|
|
|
@ -10,7 +10,7 @@ namespace YooAsset.Editor
|
|||
[TaskAttribute("资源构建内容打包")]
|
||||
public class TaskBuilding : IBuildTask
|
||||
{
|
||||
public class UnityManifestContext : IContextObject
|
||||
public class BuildResultContext : IContextObject
|
||||
{
|
||||
public AssetBundleManifest UnityManifest;
|
||||
}
|
||||
|
@ -26,19 +26,19 @@ namespace YooAsset.Editor
|
|||
return;
|
||||
|
||||
BuildAssetBundleOptions opt = buildParametersContext.GetPipelineBuildOptions();
|
||||
AssetBundleManifest unityManifest = BuildPipeline.BuildAssetBundles(buildParametersContext.PipelineOutputDirectory, buildMapContext.GetPipelineBuilds(), opt, buildParametersContext.Parameters.BuildTarget);
|
||||
if (unityManifest == null)
|
||||
AssetBundleManifest buildResults = BuildPipeline.BuildAssetBundles(buildParametersContext.PipelineOutputDirectory, buildMapContext.GetPipelineBuilds(), opt, buildParametersContext.Parameters.BuildTarget);
|
||||
if (buildResults == null)
|
||||
throw new Exception("构建过程中发生错误!");
|
||||
|
||||
BuildRunner.Log("Unity引擎打包成功!");
|
||||
UnityManifestContext unityManifestContext = new UnityManifestContext();
|
||||
unityManifestContext.UnityManifest = unityManifest;
|
||||
context.SetContextObject(unityManifestContext);
|
||||
BuildResultContext buildResultContext = new BuildResultContext();
|
||||
buildResultContext.UnityManifest = buildResults;
|
||||
context.SetContextObject(buildResultContext);
|
||||
|
||||
// 拷贝原生文件
|
||||
if (buildMode == EBuildMode.ForceRebuild || buildMode == EBuildMode.IncrementalBuild)
|
||||
{
|
||||
CopyRawBundle(buildMapContext, buildParametersContext);
|
||||
UpdateBuildBundleInfo(buildMapContext, buildParametersContext, buildResultContext);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -60,5 +60,31 @@ namespace YooAsset.Editor
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新构建结果
|
||||
/// </summary>
|
||||
private void UpdateBuildBundleInfo(BuildMapContext buildMapContext, BuildParametersContext buildParametersContext, BuildResultContext buildResult)
|
||||
{
|
||||
foreach (var bundleInfo in buildMapContext.BundleInfos)
|
||||
{
|
||||
string filePath = $"{buildParametersContext.PipelineOutputDirectory}/{bundleInfo.BundleName}";
|
||||
bundleInfo.FileHash = HashUtility.FileMD5(filePath);
|
||||
bundleInfo.FileCRC = HashUtility.FileCRC32(filePath);
|
||||
bundleInfo.FileSize = FileUtility.GetFileSize(filePath);
|
||||
if (bundleInfo.IsRawFile)
|
||||
{
|
||||
bundleInfo.ContentHash = bundleInfo.FileHash;
|
||||
}
|
||||
else
|
||||
{
|
||||
var hash = buildResult.UnityManifest.GetAssetBundleHash(bundleInfo.BundleName);
|
||||
if (hash.isValid)
|
||||
bundleInfo.ContentHash = hash.ToString();
|
||||
else
|
||||
throw new Exception($"Not found bundle in build result : {bundleInfo.BundleName}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -12,7 +12,7 @@ namespace YooAsset.Editor
|
|||
[TaskAttribute("资源构建内容打包")]
|
||||
public class TaskBuilding_SBP : IBuildTask
|
||||
{
|
||||
public class SBPBuildResultContext : IContextObject
|
||||
public class BuildResultContext : IContextObject
|
||||
{
|
||||
public IBundleBuildResults Results;
|
||||
}
|
||||
|
@ -42,14 +42,14 @@ namespace YooAsset.Editor
|
|||
}
|
||||
|
||||
BuildRunner.Log("Unity引擎打包成功!");
|
||||
SBPBuildResultContext buildResultContext = new SBPBuildResultContext();
|
||||
BuildResultContext buildResultContext = new BuildResultContext();
|
||||
buildResultContext.Results = buildResults;
|
||||
context.SetContextObject(buildResultContext);
|
||||
|
||||
// 拷贝原生文件
|
||||
if (buildMode == EBuildMode.ForceRebuild || buildMode == EBuildMode.IncrementalBuild)
|
||||
{
|
||||
CopyRawBundle(buildMapContext, buildParametersContext);
|
||||
UpdateBuildBundleInfo(buildMapContext, buildParametersContext, buildResultContext);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -71,5 +71,31 @@ namespace YooAsset.Editor
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新构建结果
|
||||
/// </summary>
|
||||
private void UpdateBuildBundleInfo(BuildMapContext buildMapContext, BuildParametersContext buildParametersContext, BuildResultContext buildResult)
|
||||
{
|
||||
foreach (var bundleInfo in buildMapContext.BundleInfos)
|
||||
{
|
||||
string filePath = $"{buildParametersContext.PipelineOutputDirectory}/{bundleInfo.BundleName}";
|
||||
bundleInfo.FileHash = HashUtility.FileMD5(filePath);
|
||||
bundleInfo.FileCRC = HashUtility.FileCRC32(filePath);
|
||||
bundleInfo.FileSize = FileUtility.GetFileSize(filePath);
|
||||
if (bundleInfo.IsRawFile)
|
||||
{
|
||||
bundleInfo.ContentHash = bundleInfo.FileHash;
|
||||
}
|
||||
else
|
||||
{
|
||||
// 注意:当资源包的依赖列表发生变化的时候,ContentHash也会发生变化!
|
||||
if (buildResult.Results.BundleInfos.TryGetValue(bundleInfo.BundleName, out var value))
|
||||
bundleInfo.ContentHash = value.Hash.ToString();
|
||||
else
|
||||
throw new Exception($"Not found bundle in build result : {bundleInfo.BundleName}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -22,8 +22,6 @@ namespace YooAsset.Editor
|
|||
private void CreatePatchManifestFile(BuildContext context)
|
||||
{
|
||||
var buildParameters = context.GetContextObject<BuildParametersContext>();
|
||||
var buildMapContext = context.GetContextObject<BuildMapContext>();
|
||||
var encryptionContext = context.GetContextObject<TaskEncryption.EncryptionContext>();
|
||||
int resourceVersion = buildParameters.Parameters.BuildVersion;
|
||||
|
||||
// 创建新补丁清单
|
||||
|
@ -33,13 +31,13 @@ namespace YooAsset.Editor
|
|||
patchManifest.EnableAddressable = buildParameters.Parameters.EnableAddressable;
|
||||
patchManifest.OutputNameStyle = (int)buildParameters.Parameters.OutputNameStyle;
|
||||
patchManifest.BuildinTags = buildParameters.Parameters.BuildinTags;
|
||||
patchManifest.BundleList = GetAllPatchBundle(buildParameters, buildMapContext, encryptionContext);
|
||||
patchManifest.AssetList = GetAllPatchAsset(buildParameters, buildMapContext, patchManifest);
|
||||
patchManifest.BundleList = GetAllPatchBundle(context);
|
||||
patchManifest.AssetList = GetAllPatchAsset(context, patchManifest);
|
||||
|
||||
// 更新Unity内置资源包的引用关系
|
||||
if (buildParameters.Parameters.BuildPipeline == EBuildPipeline.ScriptableBuildPipeline)
|
||||
{
|
||||
var buildResultContext = context.GetContextObject<TaskBuilding_SBP.SBPBuildResultContext>();
|
||||
var buildResultContext = context.GetContextObject<TaskBuilding_SBP.BuildResultContext>();
|
||||
UpdateBuiltInBundleReference(patchManifest, buildResultContext.Results);
|
||||
}
|
||||
|
||||
|
@ -64,27 +62,28 @@ namespace YooAsset.Editor
|
|||
/// <summary>
|
||||
/// 获取资源包列表
|
||||
/// </summary>
|
||||
private List<PatchBundle> GetAllPatchBundle(BuildParametersContext buildParameters, BuildMapContext buildMapContext,
|
||||
TaskEncryption.EncryptionContext encryptionContext)
|
||||
private List<PatchBundle> GetAllPatchBundle(BuildContext context)
|
||||
{
|
||||
var buildParameters = context.GetContextObject<BuildParametersContext>();
|
||||
var buildMapContext = context.GetContextObject<BuildMapContext>();
|
||||
var encryptionContext = context.GetContextObject<TaskEncryption.EncryptionContext>();
|
||||
|
||||
List<PatchBundle> result = new List<PatchBundle>(1000);
|
||||
|
||||
List<string> buildinTags = buildParameters.Parameters.GetBuildinTags();
|
||||
var buildMode = buildParameters.Parameters.BuildMode;
|
||||
bool standardBuild = buildMode == EBuildMode.ForceRebuild || buildMode == EBuildMode.IncrementalBuild;
|
||||
foreach (var bundleInfo in buildMapContext.BundleInfos)
|
||||
{
|
||||
var bundleName = bundleInfo.BundleName;
|
||||
string filePath = $"{buildParameters.PipelineOutputDirectory}/{bundleName}";
|
||||
string hash = GetFileHash(filePath, standardBuild);
|
||||
string crc32 = GetFileCRC(filePath, standardBuild);
|
||||
long size = GetFileSize(filePath, standardBuild);
|
||||
string contentHash = bundleInfo.ContentHash;
|
||||
string fileHash = bundleInfo.FileHash;
|
||||
string fileCRC = bundleInfo.FileCRC;
|
||||
long fileSize = bundleInfo.FileSize;
|
||||
string[] tags = buildMapContext.GetBundleTags(bundleName);
|
||||
bool isEncrypted = encryptionContext.IsEncryptFile(bundleName);
|
||||
bool isBuildin = IsBuildinBundle(tags, buildinTags);
|
||||
bool isRawFile = bundleInfo.IsRawFile;
|
||||
|
||||
PatchBundle patchBundle = new PatchBundle(bundleName, hash, crc32, size, tags);
|
||||
PatchBundle patchBundle = new PatchBundle(bundleName, contentHash, fileHash, fileCRC, fileSize, tags);
|
||||
patchBundle.SetFlagsValue(isEncrypted, isBuildin, isRawFile);
|
||||
result.Add(patchBundle);
|
||||
}
|
||||
|
@ -104,33 +103,15 @@ namespace YooAsset.Editor
|
|||
}
|
||||
return false;
|
||||
}
|
||||
private string GetFileHash(string filePath, bool standardBuild)
|
||||
{
|
||||
if (standardBuild)
|
||||
return HashUtility.FileMD5(filePath);
|
||||
else
|
||||
return "00000000000000000000000000000000"; //32位
|
||||
}
|
||||
private string GetFileCRC(string filePath, bool standardBuild)
|
||||
{
|
||||
if (standardBuild)
|
||||
return HashUtility.FileCRC32(filePath);
|
||||
else
|
||||
return "00000000"; //8位
|
||||
}
|
||||
private long GetFileSize(string filePath, bool standardBuild)
|
||||
{
|
||||
if (standardBuild)
|
||||
return FileUtility.GetFileSize(filePath);
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取资源列表
|
||||
/// </summary>
|
||||
private List<PatchAsset> GetAllPatchAsset(BuildParametersContext buildParameters, BuildMapContext buildMapContext, PatchManifest patchManifest)
|
||||
private List<PatchAsset> GetAllPatchAsset(BuildContext context, PatchManifest patchManifest)
|
||||
{
|
||||
var buildParameters = context.GetContextObject<BuildParametersContext>();
|
||||
var buildMapContext = context.GetContextObject<BuildMapContext>();
|
||||
|
||||
List<PatchAsset> result = new List<PatchAsset>(1000);
|
||||
foreach (var bundleInfo in buildMapContext.BundleInfos)
|
||||
{
|
||||
|
@ -206,7 +187,7 @@ namespace YooAsset.Editor
|
|||
if (conflictAssetPathList.Count > 0)
|
||||
{
|
||||
List<int> newDependIDs = new List<int>(patchAsset.DependIDs);
|
||||
if(newDependIDs.Contains(shaderBundleId) == false)
|
||||
if (newDependIDs.Contains(shaderBundleId) == false)
|
||||
newDependIDs.Add(shaderBundleId);
|
||||
patchAsset.DependIDs = newDependIDs.ToArray();
|
||||
}
|
||||
|
|
|
@ -81,7 +81,7 @@ namespace YooAsset.Editor
|
|||
reportAssetInfo.AssetTags = patchAsset.AssetTags;
|
||||
reportAssetInfo.AssetGUID = AssetDatabase.AssetPathToGUID(patchAsset.AssetPath);
|
||||
reportAssetInfo.MainBundleName = mainBundle.BundleName;
|
||||
reportAssetInfo.MainBundleSize = mainBundle.SizeBytes;
|
||||
reportAssetInfo.MainBundleSize = mainBundle.FileSize;
|
||||
reportAssetInfo.DependBundles = GetDependBundles(patchManifest, patchAsset);
|
||||
reportAssetInfo.DependAssets = GetDependAssets(buildMapContext, mainBundle.BundleName, patchAsset.AssetPath);
|
||||
buildReport.AssetInfos.Add(reportAssetInfo);
|
||||
|
@ -94,9 +94,10 @@ namespace YooAsset.Editor
|
|||
ReportBundleInfo reportBundleInfo = new ReportBundleInfo();
|
||||
reportBundleInfo.BundleName = patchBundle.BundleName;
|
||||
reportBundleInfo.FileName = patchBundle.FileName;
|
||||
reportBundleInfo.Hash = patchBundle.Hash;
|
||||
reportBundleInfo.CRC = patchBundle.CRC;
|
||||
reportBundleInfo.SizeBytes = patchBundle.SizeBytes;
|
||||
reportBundleInfo.ContentHash = patchBundle.ContentHash;
|
||||
reportBundleInfo.FileHash = patchBundle.FileHash;
|
||||
reportBundleInfo.FileCRC = patchBundle.FileCRC;
|
||||
reportBundleInfo.FileSize = patchBundle.FileSize;
|
||||
reportBundleInfo.Tags = patchBundle.Tags;
|
||||
reportBundleInfo.Flags = patchBundle.Flags;
|
||||
buildReport.BundleInfos.Add(reportBundleInfo);
|
||||
|
@ -172,7 +173,7 @@ namespace YooAsset.Editor
|
|||
long fileBytes = 0;
|
||||
foreach (var patchBundle in patchManifest.BundleList)
|
||||
{
|
||||
fileBytes += patchBundle.SizeBytes;
|
||||
fileBytes += patchBundle.FileSize;
|
||||
}
|
||||
return fileBytes;
|
||||
}
|
||||
|
@ -192,7 +193,7 @@ namespace YooAsset.Editor
|
|||
foreach (var patchBundle in patchManifest.BundleList)
|
||||
{
|
||||
if (patchBundle.IsBuildin)
|
||||
fileBytes += patchBundle.SizeBytes;
|
||||
fileBytes += patchBundle.FileSize;
|
||||
}
|
||||
return fileBytes;
|
||||
}
|
||||
|
@ -212,7 +213,7 @@ namespace YooAsset.Editor
|
|||
foreach (var patchBundle in patchManifest.BundleList)
|
||||
{
|
||||
if (patchBundle.IsEncrypted)
|
||||
fileBytes += patchBundle.SizeBytes;
|
||||
fileBytes += patchBundle.FileSize;
|
||||
}
|
||||
return fileBytes;
|
||||
}
|
||||
|
@ -232,7 +233,7 @@ namespace YooAsset.Editor
|
|||
foreach (var patchBundle in patchManifest.BundleList)
|
||||
{
|
||||
if (patchBundle.IsRawFile)
|
||||
fileBytes += patchBundle.SizeBytes;
|
||||
fileBytes += patchBundle.FileSize;
|
||||
}
|
||||
return fileBytes;
|
||||
}
|
||||
|
|
|
@ -22,8 +22,8 @@ namespace YooAsset.Editor
|
|||
// 验证构建结果
|
||||
if (buildParametersContext.Parameters.VerifyBuildingResult)
|
||||
{
|
||||
var unityManifestContext = context.GetContextObject<TaskBuilding.UnityManifestContext>();
|
||||
VerifyingBuildingResult(context, unityManifestContext.UnityManifest);
|
||||
var buildResultContext = context.GetContextObject<TaskBuilding.BuildResultContext>();
|
||||
VerifyingBuildingResult(context, buildResultContext.UnityManifest);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ namespace YooAsset.Editor
|
|||
// 验证构建结果
|
||||
if (buildParametersContext.Parameters.VerifyBuildingResult)
|
||||
{
|
||||
var buildResultContext = context.GetContextObject<TaskBuilding_SBP.SBPBuildResultContext>();
|
||||
var buildResultContext = context.GetContextObject<TaskBuilding_SBP.BuildResultContext>();
|
||||
VerifyingBuildingResult(context, buildResultContext.Results);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue