update editor code

pull/134/head
hevinci 2023-07-17 19:38:11 +08:00
parent ffffff16e9
commit ecb6f71f81
3 changed files with 96 additions and 56 deletions

View File

@ -8,28 +8,31 @@ namespace YooAsset.Editor
{ {
public class BuildBundleInfo public class BuildBundleInfo
{ {
public class InfoWrapper #region 补丁文件的关键信息
{
/// <summary> /// <summary>
/// 构建内容的哈希值 /// Unity引擎生成的哈希值构建内容的哈希值
/// </summary> /// </summary>
public string ContentHash { set; get; } public string PackageUnityHash { set; get; }
/// <summary>
/// Unity引擎生成的CRC
/// </summary>
public uint PackageUnityCRC { set; get; }
/// <summary> /// <summary>
/// 文件哈希值 /// 文件哈希值
/// </summary> /// </summary>
public string FileHash { set; get; } public string PackageFileHash { set; get; }
/// <summary> /// <summary>
/// 文件哈希值 /// 文件哈希值
/// </summary> /// </summary>
public string FileCRC { set; get; } public string PackageFileCRC { set; get; }
/// <summary> /// <summary>
/// 文件哈希值 /// 文件哈希值
/// </summary> /// </summary>
public long FileSize { set; get; } public long PackageFileSize { set; get; }
/// <summary> /// <summary>
/// 构建输出的文件路径 /// 构建输出的文件路径
@ -37,10 +40,22 @@ namespace YooAsset.Editor
public string BuildOutputFilePath { set; get; } public string BuildOutputFilePath { set; get; }
/// <summary> /// <summary>
/// 补丁包输出文件路径 /// 补丁包的源文件路径
/// </summary> /// </summary>
public string PackageOutputFilePath { set; get; } public string PackageSourceFilePath { set; get; }
}
/// <summary>
/// 补丁包的目标文件路径
/// </summary>
public string PackageDestFilePath { set; get; }
/// <summary>
/// 加密生成文件的路径
/// 注意:如果未加密该路径为空
/// </summary>
public string EncryptedFilePath { set; get; }
#endregion
/// <summary> /// <summary>
/// 资源包名称 /// 资源包名称
@ -53,22 +68,11 @@ namespace YooAsset.Editor
/// </summary> /// </summary>
public readonly List<BuildAssetInfo> AllMainAssets = new List<BuildAssetInfo>(); public readonly List<BuildAssetInfo> AllMainAssets = new List<BuildAssetInfo>();
/// <summary>
/// 补丁文件信息
/// </summary>
public readonly InfoWrapper BundleInfo = new InfoWrapper();
/// <summary> /// <summary>
/// Bundle文件的加载方法 /// Bundle文件的加载方法
/// </summary> /// </summary>
public EBundleLoadMethod LoadMethod { set; get; } public EBundleLoadMethod LoadMethod { set; get; }
/// <summary>
/// 加密生成文件的路径
/// 注意:如果未加密该路径为空
/// </summary>
public string EncryptedFilePath { set; get; }
/// <summary> /// <summary>
/// 是否为原生文件 /// 是否为原生文件
/// </summary> /// </summary>
@ -208,9 +212,10 @@ namespace YooAsset.Editor
{ {
PackageBundle packageBundle = new PackageBundle(); PackageBundle packageBundle = new PackageBundle();
packageBundle.BundleName = BundleName; packageBundle.BundleName = BundleName;
packageBundle.FileHash = BundleInfo.FileHash; packageBundle.FileHash = PackageFileHash;
packageBundle.FileCRC = BundleInfo.FileCRC; packageBundle.FileCRC = PackageFileCRC;
packageBundle.FileSize = BundleInfo.FileSize; packageBundle.FileSize = PackageFileSize;
packageBundle.UnityCRC = PackageUnityCRC;
packageBundle.IsRawFile = IsRawFile; packageBundle.IsRawFile = IsRawFile;
packageBundle.LoadMethod = (byte)LoadMethod; packageBundle.LoadMethod = (byte)LoadMethod;
packageBundle.Tags = GetBundleTags(); packageBundle.Tags = GetBundleTags();

View File

@ -70,7 +70,7 @@ namespace YooAsset.Editor
int fileTotalCount = buildMapContext.Collection.Count; int fileTotalCount = buildMapContext.Collection.Count;
foreach (var bundleInfo in buildMapContext.Collection) foreach (var bundleInfo in buildMapContext.Collection)
{ {
EditorTools.CopyFile(bundleInfo.BundleInfo.BuildOutputFilePath, bundleInfo.BundleInfo.PackageOutputFilePath, true); EditorTools.CopyFile(bundleInfo.PackageSourceFilePath, bundleInfo.PackageDestFilePath, true);
EditorTools.DisplayProgressBar("拷贝补丁文件", ++progressValue, fileTotalCount); EditorTools.DisplayProgressBar("拷贝补丁文件", ++progressValue, fileTotalCount);
} }
EditorTools.ClearProgressBar(); EditorTools.ClearProgressBar();

View File

@ -29,32 +29,35 @@ namespace YooAsset.Editor
// 2.更新构建输出的文件路径 // 2.更新构建输出的文件路径
foreach (var bundleInfo in buildMapContext.Collection) foreach (var bundleInfo in buildMapContext.Collection)
{ {
bundleInfo.BuildOutputFilePath = $"{pipelineOutputDirectory}/{bundleInfo.BundleName}";
if (bundleInfo.IsEncryptedFile) if (bundleInfo.IsEncryptedFile)
bundleInfo.BundleInfo.BuildOutputFilePath = bundleInfo.EncryptedFilePath; bundleInfo.PackageSourceFilePath = bundleInfo.EncryptedFilePath;
else else
bundleInfo.BundleInfo.BuildOutputFilePath = $"{pipelineOutputDirectory}/{bundleInfo.BundleName}"; bundleInfo.PackageSourceFilePath = bundleInfo.BuildOutputFilePath;
} }
// 3.更新文件其它信息 // 3.更新文件其它信息
foreach (var bundleInfo in buildMapContext.Collection) foreach (var bundleInfo in buildMapContext.Collection)
{ {
string buildOutputFilePath = bundleInfo.BundleInfo.BuildOutputFilePath; bundleInfo.PackageUnityHash = GetUnityHash(bundleInfo, context);
bundleInfo.BundleInfo.ContentHash = GetBundleContentHash(bundleInfo, context); bundleInfo.PackageUnityCRC = GetUnityCRC(bundleInfo, context);
bundleInfo.BundleInfo.FileHash = GetBundleFileHash(buildOutputFilePath, buildParametersContext); bundleInfo.PackageFileHash = GetBundleFileHash(bundleInfo.PackageSourceFilePath, buildParametersContext);
bundleInfo.BundleInfo.FileCRC = GetBundleFileCRC(buildOutputFilePath, buildParametersContext); bundleInfo.PackageFileCRC = GetBundleFileCRC(bundleInfo.PackageSourceFilePath, buildParametersContext);
bundleInfo.BundleInfo.FileSize = GetBundleFileSize(buildOutputFilePath, buildParametersContext); bundleInfo.PackageFileSize = GetBundleFileSize(bundleInfo.PackageSourceFilePath, buildParametersContext);
} }
// 4.更新补丁包输出的文件路径 // 4.更新补丁包输出的文件路径
foreach (var bundleInfo in buildMapContext.Collection) foreach (var bundleInfo in buildMapContext.Collection)
{ {
string fileExtension = ManifestTools.GetRemoteBundleFileExtension(bundleInfo.BundleName); string bundleName = bundleInfo.BundleName;
string fileName = ManifestTools.GetRemoteBundleFileName(outputNameStyle, bundleInfo.BundleName, fileExtension, bundleInfo.BundleInfo.FileHash); string fileHash = bundleInfo.PackageFileHash;
bundleInfo.BundleInfo.PackageOutputFilePath = $"{packageOutputDirectory}/{fileName}"; string fileExtension = ManifestTools.GetRemoteBundleFileExtension(bundleName);
string fileName = ManifestTools.GetRemoteBundleFileName(outputNameStyle, bundleName, fileExtension, fileHash);
bundleInfo.PackageDestFilePath = $"{packageOutputDirectory}/{fileName}";
} }
} }
private string GetBundleContentHash(BuildBundleInfo bundleInfo, BuildContext context) private string GetUnityHash(BuildBundleInfo bundleInfo, BuildContext context)
{ {
var buildParametersContext = context.GetContextObject<BuildParametersContext>(); var buildParametersContext = context.GetContextObject<BuildParametersContext>();
var parameters = buildParametersContext.Parameters; var parameters = buildParametersContext.Parameters;
@ -64,7 +67,7 @@ namespace YooAsset.Editor
if (bundleInfo.IsRawFile) if (bundleInfo.IsRawFile)
{ {
string filePath = bundleInfo.BundleInfo.BuildOutputFilePath; string filePath = bundleInfo.PackageSourceFilePath;
return HashUtility.FileMD5(filePath); return HashUtility.FileMD5(filePath);
} }
@ -75,7 +78,7 @@ namespace YooAsset.Editor
if (hash.isValid) if (hash.isValid)
return hash.ToString(); return hash.ToString();
else else
throw new Exception($"Not found bundle in build result : {bundleInfo.BundleName}"); throw new Exception($"Not found bundle hash in build result : {bundleInfo.BundleName}");
} }
else if (parameters.BuildPipeline == EBuildPipeline.ScriptableBuildPipeline) else if (parameters.BuildPipeline == EBuildPipeline.ScriptableBuildPipeline)
{ {
@ -84,7 +87,39 @@ namespace YooAsset.Editor
if (buildResult.Results.BundleInfos.TryGetValue(bundleInfo.BundleName, out var value)) if (buildResult.Results.BundleInfos.TryGetValue(bundleInfo.BundleName, out var value))
return value.Hash.ToString(); return value.Hash.ToString();
else else
throw new Exception($"Not found bundle in build result : {bundleInfo.BundleName}"); throw new Exception($"Not found bundle hash in build result : {bundleInfo.BundleName}");
}
else
{
throw new System.NotImplementedException();
}
}
private uint GetUnityCRC(BuildBundleInfo bundleInfo, BuildContext context)
{
var buildParametersContext = context.GetContextObject<BuildParametersContext>();
var parameters = buildParametersContext.Parameters;
var buildMode = parameters.BuildMode;
if (buildMode == EBuildMode.DryRunBuild || buildMode == EBuildMode.SimulateBuild)
return 0;
if (bundleInfo.IsRawFile)
return 0;
if (parameters.BuildPipeline == EBuildPipeline.BuiltinBuildPipeline)
{
string filePath = bundleInfo.BuildOutputFilePath;
if (BuildPipeline.GetCRCForAssetBundle(filePath, out uint crc))
return crc;
else
throw new Exception($"Not found bundle crc in build result : {bundleInfo.BundleName}");
}
else if (parameters.BuildPipeline == EBuildPipeline.ScriptableBuildPipeline)
{
var buildResult = context.GetContextObject<TaskBuilding_SBP.BuildResultContext>();
if (buildResult.Results.BundleInfos.TryGetValue(bundleInfo.BundleName, out var value))
return value.Crc;
else
throw new Exception($"Not found bundle crc in build result : {bundleInfo.BundleName}");
} }
else else
{ {