Update AssetBundleBuilder
parent
3e716887c9
commit
5b8a004720
|
@ -173,14 +173,11 @@ namespace YooAsset.Editor
|
|||
if (IsRawAsset)
|
||||
throw new Exception("Should never get here !");
|
||||
|
||||
if (AssetBundleCollectorSettingData.Setting.AutoCollectShaders)
|
||||
if (IsShaderAsset)
|
||||
{
|
||||
if (IsShaderAsset)
|
||||
{
|
||||
string shareBundleName = $"{AssetBundleCollectorSettingData.Setting.ShadersBundleName}.{YooAssetSettingsData.Setting.AssetBundleFileVariant}";
|
||||
_shareBundleName = EditorTools.GetRegularPath(shareBundleName).ToLower();
|
||||
return;
|
||||
}
|
||||
string shareBundleName = YooAssetSettingsData.GetUnityShadersBundleFullName();
|
||||
_shareBundleName = EditorTools.GetRegularPath(shareBundleName).ToLower();
|
||||
return;
|
||||
}
|
||||
|
||||
if (_referenceBundleNames.Count > 1)
|
||||
|
|
|
@ -63,16 +63,6 @@ namespace YooAsset.Editor
|
|||
/// </summary>
|
||||
public bool CopyBuildinTagFiles;
|
||||
|
||||
/// <summary>
|
||||
/// 自动收集着色器
|
||||
/// </summary>
|
||||
public bool AutoCollectShaders;
|
||||
|
||||
/// <summary>
|
||||
/// 自动收集的着色器资源包名称
|
||||
/// </summary>
|
||||
public string ShadersBundleName;
|
||||
|
||||
/// <summary>
|
||||
/// 加密服务类名称
|
||||
/// </summary>
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor.Build.Pipeline;
|
||||
using UnityEditor.Build.Pipeline.Interfaces;
|
||||
|
||||
namespace UnityEditor.Build.Pipeline.Tasks
|
||||
{
|
||||
public static class SBPBuildTasks
|
||||
{
|
||||
public static IList<IBuildTask> Create(string builtInShaderBundleName)
|
||||
{
|
||||
var buildTasks = new List<IBuildTask>();
|
||||
|
||||
// Setup
|
||||
buildTasks.Add(new SwitchToBuildPlatform());
|
||||
buildTasks.Add(new RebuildSpriteAtlasCache());
|
||||
|
||||
// Player Scripts
|
||||
buildTasks.Add(new BuildPlayerScripts());
|
||||
buildTasks.Add(new PostScriptsCallback());
|
||||
|
||||
// Dependency
|
||||
buildTasks.Add(new CalculateSceneDependencyData());
|
||||
#if UNITY_2019_3_OR_NEWER
|
||||
buildTasks.Add(new CalculateCustomDependencyData());
|
||||
#endif
|
||||
buildTasks.Add(new CalculateAssetDependencyData());
|
||||
buildTasks.Add(new StripUnusedSpriteSources());
|
||||
buildTasks.Add(new CreateBuiltInShadersBundle(builtInShaderBundleName));
|
||||
buildTasks.Add(new PostDependencyCallback());
|
||||
|
||||
// Packing
|
||||
buildTasks.Add(new GenerateBundlePacking());
|
||||
buildTasks.Add(new UpdateBundleObjectLayout());
|
||||
buildTasks.Add(new GenerateBundleCommands());
|
||||
buildTasks.Add(new GenerateSubAssetPathMaps());
|
||||
buildTasks.Add(new GenerateBundleMaps());
|
||||
buildTasks.Add(new PostPackingCallback());
|
||||
|
||||
// Writing
|
||||
buildTasks.Add(new WriteSerializedFiles());
|
||||
buildTasks.Add(new ArchiveAndCompressBundles());
|
||||
buildTasks.Add(new AppendBundleHash());
|
||||
buildTasks.Add(new GenerateLinkXml());
|
||||
buildTasks.Add(new PostWritingCallback());
|
||||
|
||||
return buildTasks;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: f38422f6a64300243af6b4fbf84644ba
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -2,11 +2,10 @@
|
|||
using System.Linq;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
using UnityEditor.Build.Pipeline;
|
||||
using UnityEditor.Build.Pipeline.Interfaces;
|
||||
using UnityEditor.Build.Pipeline.Tasks;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
|
@ -34,7 +33,8 @@ namespace YooAsset.Editor
|
|||
// 开始构建
|
||||
IBundleBuildResults buildResults;
|
||||
var buildParameters = buildParametersContext.GetSBPBuildParameters();
|
||||
var taskList = DefaultBuildTasks.Create(DefaultBuildTasks.Preset.AssetBundleBuiltInShaderExtraction);
|
||||
var shadersBunldeName = YooAssetSettingsData.GetUnityShadersBundleFullName();
|
||||
var taskList = SBPBuildTasks.Create(shadersBunldeName);
|
||||
ReturnCode exitCode = ContentPipeline.BuildAssetBundles(buildParameters, buildContent, out buildResults, taskList);
|
||||
if (exitCode < 0)
|
||||
{
|
||||
|
@ -46,13 +46,6 @@ namespace YooAsset.Editor
|
|||
buildResultContext.Results = buildResults;
|
||||
context.SetContextObject(buildResultContext);
|
||||
|
||||
// 添加Unity内置资源包信息
|
||||
if (buildResults.BundleInfos.Keys.Any(t => t == YooAssetSettings.UnityBuiltInShadersBundleName))
|
||||
{
|
||||
BuildBundleInfo builtInBundleInfo = new BuildBundleInfo(YooAssetSettings.UnityBuiltInShadersBundleName);
|
||||
buildMapContext.BundleInfos.Add(builtInBundleInfo);
|
||||
}
|
||||
|
||||
// 拷贝原生文件
|
||||
if (buildMode == EBuildMode.ForceRebuild || buildMode == EBuildMode.IncrementalBuild)
|
||||
{
|
||||
|
|
|
@ -183,24 +183,31 @@ namespace YooAsset.Editor
|
|||
/// </summary>
|
||||
private void UpdateBuiltInBundleReference(PatchManifest patchManifest, IBundleBuildResults buildResults)
|
||||
{
|
||||
// 获取所有依赖内置资源包的资源包列表
|
||||
List<string> builtInBundleReferenceList = new List<string>();
|
||||
// 获取所有依赖着色器资源包的资源包列表
|
||||
string shadersBunldeName = YooAssetSettingsData.GetUnityShadersBundleFullName();
|
||||
List<string> shaderBundleReferenceList = new List<string>();
|
||||
foreach (var valuePair in buildResults.BundleInfos)
|
||||
{
|
||||
if (valuePair.Value.Dependencies.Any(t => t == YooAssetSettings.UnityBuiltInShadersBundleName))
|
||||
builtInBundleReferenceList.Add(valuePair.Key);
|
||||
if (valuePair.Value.Dependencies.Any(t => t == shadersBunldeName))
|
||||
shaderBundleReferenceList.Add(valuePair.Key);
|
||||
}
|
||||
|
||||
// 获取着色器资源包索引
|
||||
Predicate<PatchBundle> predicate = new Predicate<PatchBundle>(s => s.BundleName == shadersBunldeName);
|
||||
int shaderBundleId = patchManifest.BundleList.FindIndex(predicate);
|
||||
if (shaderBundleId == -1)
|
||||
throw new Exception("没有发现着色器资源包!");
|
||||
|
||||
// 检测依赖交集并更新依赖ID
|
||||
int builtInBundleId = patchManifest.BundleList.Count - 1;
|
||||
foreach (var patchAsset in patchManifest.AssetList)
|
||||
{
|
||||
List<string> dependBundles = GetPatchAssetAllDependBundles(patchManifest, patchAsset);
|
||||
List<string> conflictAssetPathList = dependBundles.Intersect(builtInBundleReferenceList).ToList();
|
||||
List<string> conflictAssetPathList = dependBundles.Intersect(shaderBundleReferenceList).ToList();
|
||||
if (conflictAssetPathList.Count > 0)
|
||||
{
|
||||
List<int> newDependIDs = new List<int>(patchAsset.DependIDs);
|
||||
newDependIDs.Add(builtInBundleId);
|
||||
if(newDependIDs.Contains(shaderBundleId) == false)
|
||||
newDependIDs.Add(shaderBundleId);
|
||||
patchAsset.DependIDs = newDependIDs.ToArray();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,8 +48,6 @@ namespace YooAsset.Editor
|
|||
buildReport.Summary.BuildinTags = buildParameters.Parameters.BuildinTags;
|
||||
buildReport.Summary.EnableAddressable = buildParameters.Parameters.EnableAddressable;
|
||||
buildReport.Summary.CopyBuildinTagFiles = buildParameters.Parameters.CopyBuildinTagFiles;
|
||||
buildReport.Summary.AutoCollectShaders = AssetBundleCollectorSettingData.Setting.AutoCollectShaders;
|
||||
buildReport.Summary.ShadersBundleName = AssetBundleCollectorSettingData.Setting.ShadersBundleName;
|
||||
buildReport.Summary.EncryptionServicesClassName = buildParameters.Parameters.EncryptionServices == null ?
|
||||
"null" : buildParameters.Parameters.EncryptionServices.GetType().FullName;
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ namespace YooAsset.Editor
|
|||
void IBuildTask.Run(BuildContext context)
|
||||
{
|
||||
var buildParametersContext = context.GetContextObject<BuildParametersContext>();
|
||||
|
||||
|
||||
// 模拟构建模式下跳过验证
|
||||
if (buildParametersContext.Parameters.BuildMode == EBuildMode.SimulateBuild)
|
||||
return;
|
||||
|
@ -37,20 +37,31 @@ namespace YooAsset.Editor
|
|||
string[] buildedBundles = unityManifest.GetAllAssetBundles();
|
||||
|
||||
// 1. 过滤掉原生Bundle
|
||||
string[] expectBundles = buildMapContext.BundleInfos.Where(t => t.IsRawFile == false).Select(t => t.BundleName).ToArray();
|
||||
string[] mapBundles = buildMapContext.BundleInfos.Where(t => t.IsRawFile == false).Select(t => t.BundleName).ToArray();
|
||||
|
||||
// 2. 验证Bundle
|
||||
List<string> intersectBundleList = buildedBundles.Except(expectBundles).ToList();
|
||||
if (intersectBundleList.Count > 0)
|
||||
List<string> exceptBundleList1 = buildedBundles.Except(mapBundles).ToList();
|
||||
if (exceptBundleList1.Count > 0)
|
||||
{
|
||||
foreach (var intersectBundle in intersectBundleList)
|
||||
foreach (var exceptBundle in exceptBundleList1)
|
||||
{
|
||||
Debug.LogWarning($"差异资源包: {intersectBundle}");
|
||||
Debug.LogWarning($"差异资源包: {exceptBundle}");
|
||||
}
|
||||
throw new System.Exception("存在差异资源包!请查看警告信息!");
|
||||
}
|
||||
|
||||
// 3. 验证Asset
|
||||
// 3. 验证Bundle
|
||||
List<string> exceptBundleList2 = mapBundles.Except(buildedBundles).ToList();
|
||||
if (exceptBundleList2.Count > 0)
|
||||
{
|
||||
foreach (var exceptBundle in exceptBundleList2)
|
||||
{
|
||||
Debug.LogWarning($"差异资源包: {exceptBundle}");
|
||||
}
|
||||
throw new System.Exception("存在差异资源包!请查看警告信息!");
|
||||
}
|
||||
|
||||
// 4. 验证Asset
|
||||
bool isPass = true;
|
||||
var buildMode = buildParameters.Parameters.BuildMode;
|
||||
if (buildMode == EBuildMode.ForceRebuild || buildMode == EBuildMode.IncrementalBuild)
|
||||
|
@ -59,15 +70,20 @@ namespace YooAsset.Editor
|
|||
foreach (var buildedBundle in buildedBundles)
|
||||
{
|
||||
string filePath = $"{buildParameters.PipelineOutputDirectory}/{buildedBundle}";
|
||||
string[] allBuildinAssetPaths = GetAssetBundleAllAssets(filePath);
|
||||
string[] expectBuildinAssetPaths = buildMapContext.GetBuildinAssetPaths(buildedBundle);
|
||||
if (expectBuildinAssetPaths.Length != allBuildinAssetPaths.Length)
|
||||
string[] buildedAssetPaths = GetAssetBundleAllAssets(filePath);
|
||||
string[] mapAssetPaths = buildMapContext.GetBuildinAssetPaths(buildedBundle);
|
||||
if (mapAssetPaths.Length != buildedAssetPaths.Length)
|
||||
{
|
||||
Debug.LogWarning($"构建的Bundle文件内的资源对象数量和预期不匹配 : {buildedBundle}");
|
||||
var intersectAssetList = expectBuildinAssetPaths.Except(allBuildinAssetPaths).ToList();
|
||||
foreach (var intersectAssset in intersectAssetList)
|
||||
var exceptAssetList1 = mapAssetPaths.Except(buildedAssetPaths).ToList();
|
||||
foreach (var excpetAsset in exceptAssetList1)
|
||||
{
|
||||
Debug.LogWarning($"构建失败的资源对象路径为 : {intersectAssset}");
|
||||
Debug.LogWarning($"构建失败的资源对象路径为 : {excpetAsset}");
|
||||
}
|
||||
var exceptAssetList2 = buildedAssetPaths.Except(mapAssetPaths).ToList();
|
||||
foreach (var excpetAsset in exceptAssetList2)
|
||||
{
|
||||
Debug.LogWarning($"构建失败的资源对象路径为 : {excpetAsset}");
|
||||
}
|
||||
isPass = false;
|
||||
continue;
|
||||
|
@ -75,6 +91,7 @@ namespace YooAsset.Editor
|
|||
EditorTools.DisplayProgressBar("验证构建结果", ++progressValue, buildedBundles.Length);
|
||||
}
|
||||
EditorTools.ClearProgressBar();
|
||||
|
||||
if (isPass == false)
|
||||
{
|
||||
throw new Exception("构建结果验证没有通过,请参考警告日志!");
|
||||
|
|
|
@ -35,21 +35,29 @@ namespace YooAsset.Editor
|
|||
{
|
||||
var buildParameters = context.GetContextObject<BuildParametersContext>();
|
||||
var buildMapContext = context.GetContextObject<BuildMapContext>();
|
||||
|
||||
// 1. 移除特定Bundle
|
||||
List<string> buildedBundles = buildResults.BundleInfos.Keys.ToList();
|
||||
buildedBundles.Remove(YooAssetSettings.UnityBuiltInShadersBundleName);
|
||||
|
||||
// 2. 过滤掉原生Bundle
|
||||
// 1. 过滤掉原生Bundle
|
||||
List<string> expectBundles = buildMapContext.BundleInfos.Where(t => t.IsRawFile == false).Select(t => t.BundleName).ToList();
|
||||
|
||||
// 3. 验证Bundle
|
||||
List<string> intersectBundleList = buildedBundles.Except(expectBundles).ToList();
|
||||
if (intersectBundleList.Count > 0)
|
||||
// 2. 验证Bundle
|
||||
List<string> exceptBundleList1 = buildedBundles.Except(expectBundles).ToList();
|
||||
if (exceptBundleList1.Count > 0)
|
||||
{
|
||||
foreach (var intersectBundle in intersectBundleList)
|
||||
foreach (var exceptBundle in exceptBundleList1)
|
||||
{
|
||||
Debug.LogWarning($"差异资源包: {intersectBundle}");
|
||||
Debug.LogWarning($"差异资源包: {exceptBundle}");
|
||||
}
|
||||
throw new System.Exception("存在差异资源包!请查看警告信息!");
|
||||
}
|
||||
|
||||
// 3. 验证Bundle
|
||||
List<string> exceptBundleList2 = expectBundles.Except(buildedBundles).ToList();
|
||||
if (exceptBundleList2.Count > 0)
|
||||
{
|
||||
foreach (var exceptBundle in exceptBundleList2)
|
||||
{
|
||||
Debug.LogWarning($"差异资源包: {exceptBundle}");
|
||||
}
|
||||
throw new System.Exception("存在差异资源包!请查看警告信息!");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue