/// <summary> /// 预览结果 编辑器连线数据,但是build模式也会执行 /// 这里只建议设置BuildingCtx的ab颗粒度 /// </summary> /// <param name="target"></param> /// <param name="nodeData"></param> /// <param name="incoming"></param> /// <param name="connectionsToOutput"></param> /// <param name="outputFunc"></param> public override void Prepare(BuildTarget target, NodeData nodeData, IEnumerable <PerformGraph.AssetGroups> incoming, IEnumerable <ConnectionData> connectionsToOutput, PerformGraph.Output outputFunc) { if (incoming == null) { return; } this.BuildingCtx = BDFrameworkAssetsEnv.BuildingCtx; StopwatchTools.Begin(); //找到runtime List <AssetReference> runtimeAssetReferenceList = null; incoming.FirstOrDefault()?.assetGroups.TryGetValue(nameof(BDFrameworkAssetsEnv.FloderType.Runtime), out runtimeAssetReferenceList); if (runtimeAssetReferenceList == null) { Debug.LogError("Runtime数据获取失败!请检查前置节点!"); } //获取所有的图集设置 var atlasAssetReferenceList = runtimeAssetReferenceList.FindAll((af) => af.extension == ".spriteatlas"); this.SetAllSpriteAtlasAB(atlasAssetReferenceList); //输出传入的 var outMap = new Dictionary <string, List <AssetReference> >(); foreach (var assetgroup in incoming) { foreach (var group in assetgroup.assetGroups) { if (group.Key == nameof(BDFrameworkAssetsEnv.FloderType.Runtime)) //runtime 特殊处理 { //不直接操作传入的容器存储 var newAssetList = group.Value.ToList(); foreach (var atlas in atlasAssetReferenceList) { newAssetList.Remove(atlas); } outMap[group.Key] = newAssetList; } else { outMap[group.Key] = group.Value.ToList(); } } } StopwatchTools.End("【搜集图集】"); //atlas outMap[nameof(BDFrameworkAssetsEnv.FloderType.SpriteAtlas)] = atlasAssetReferenceList.ToList(); var output = connectionsToOutput?.FirstOrDefault(); if (output != null) { outputFunc(output, outMap); } }
/// <summary> /// 预览结果 编辑器连线数据,但是build模式也会执行 /// 这里只建议设置BuildingCtx的ab颗粒度 /// </summary> /// <param name="target"></param> /// <param name="nodeData"></param> /// <param name="incoming"></param> /// <param name="connectionsToOutput"></param> /// <param name="outputFunc"></param> public override void Prepare(BuildTarget target, NodeData nodeData, IEnumerable <PerformGraph.AssetGroups> incoming, IEnumerable <ConnectionData> connectionsToOutput, PerformGraph.Output outputFunc) { //检测混淆 StopwatchTools.Begin(); if (BuildingCtx == null) { BuildingCtx = new AssetBundleBuildingContext(); } BuildingCtx.BuildParams.BuildTarget = target; BuildingCtx.CheckABObfuscationSource(); //设置所有节点参数请求,依次传参 Debug.Log("【初始化框架资源环境】配置:\n" + JsonMapper.ToJson(BuildingCtx.BuildParams)); var outMap = new Dictionary <string, List <AssetReference> >(); //预览模式 if ((AssetGraphWindowsModeEnum)this.AssetGraphWindowsMode == AssetGraphWindowsModeEnum.预览节点模式) { //生成buildinfo //创建构建上下文信息 GenBuildingCtx(); //输出 outMap = new Dictionary <string, List <AssetReference> >() { { nameof(FloderType.Runtime), BuildingCtx.RuntimeAssetsList.ToList() }, //传递新容器 { nameof(FloderType.Depend), BuildingCtx.DependAssetList.ToList() } }; } else if ((AssetGraphWindowsModeEnum)this.AssetGraphWindowsMode == AssetGraphWindowsModeEnum.配置节点模式) { //输出 outMap = new Dictionary <string, List <AssetReference> >() { { nameof(FloderType.Runtime), new List <AssetReference>() }, //传递新容器 { nameof(FloderType.Depend), new List <AssetReference>() } }; } StopwatchTools.End("【初始化框架资源环境】"); var output = connectionsToOutput?.FirstOrDefault(); if (output != null) { outputFunc(output, outMap); // } }
/// <summary> /// 预览结果 编辑器连线数据,但是build模式也会执行 /// 这里只建议设置BuildingCtx的ab颗粒度 /// </summary> /// <param name="target"></param> /// <param name="nodeData"></param> /// <param name="incoming"></param> /// <param name="connectionsToOutput"></param> /// <param name="outputFunc"></param> public override void Prepare(BuildTarget target, NodeData nodeData, IEnumerable <PerformGraph.AssetGroups> incoming, IEnumerable <ConnectionData> connectionsToOutput, PerformGraph.Output outputFunc) { if (incoming == null) { return; } this.BuildingCtx = BDFrameworkAssetsEnv.BuildingCtx; StopwatchTools.Begin(); //收集变体 if (!isCollectedShaderKW) //防止GUI每次调用prepare时候都触发,真正打包时候 会重新构建 { Debug.Log("------------>收集Key word"); ShaderCollection.CollectShaderVariant(); isCollectedShaderKW = true; } //开始搜集传入的 shader varint var outMap = new Dictionary <string, List <AssetReference> >(); var incomingShaderAndVariantList = new List <AssetReference>(); var dependice = AssetDatabase.GetDependencies(BResources.ALL_SHADER_VARAINT_ASSET_PATH); var dependShaders = dependice.Where((depend) => { var type = AssetDatabase.GetMainAssetTypeAtPath(depend); if (type == typeof(Shader) || type == typeof(ShaderVariantCollection)) { //Debug.LogError("【搜集Shader】剔除非shader文件" + type.FullName); return(true); } return(false); }); //遍历传入的并且移除shader需要的 foreach (var ags in incoming) { foreach (var group in ags.assetGroups) { //拷贝一份 var newList = group.Value.ToList(); // for (int i = newList.Count - 1; i >= 0; i--) { //不直接操作传入的容器存储 var af = newList[i]; var ret = dependShaders.FirstOrDefault((dp) => dp.Equals(af.importFrom, StringComparison.OrdinalIgnoreCase)); if (ret != null) { newList.RemoveAt(i); incomingShaderAndVariantList.Add(af); } else { if (af.assetType == typeof(Shader)) { Debug.LogError($"【搜集KeyWord】 : {af.importFrom},请检查是否直接引用了FBX这类,SubAsset中有Mat的资产,如是请Ctrl+D复制引用!"); //寻找遗漏查找依赖资源 this.BuildingCtx.BuildingAssetInfos.AssetInfoMap.TryGetValue(af.importFrom, out var shaderAssetData); if (shaderAssetData != null) { var returnBD = this.BuildingCtx.BuildingAssetInfos.AssetInfoMap.FirstOrDefault((bd) => bd.Value.DependAssetList.Contains(shaderAssetData.ABName) || bd.Value.DependAssetList.Contains(af.importFrom, StringComparer.Ordinal)); if (returnBD.Value != null) { Debug.LogError("主资源:" + returnBD.Key); } } } } } //输出 outMap[group.Key] = newList; } } //依赖shader if (incomingShaderAndVariantList.Count > 0) //0的情况一般为 调试模式~ { foreach (var dependShader in dependShaders) { var retsult = incomingShaderAndVariantList.Find((ar) => ar.importFrom.Equals(dependShader, StringComparison.OrdinalIgnoreCase)); if (retsult == null) { var af = AssetReference.CreateReference(dependShader); incomingShaderAndVariantList.Add(af); Debug.LogError("没传入的依赖shader 单独添加:" + dependShader); } } } //设置ab foreach (var sharder in incomingShaderAndVariantList) { this.BuildingCtx.BuildingAssetInfos.SetABName(sharder.importFrom, AssetBundleName, BuildingAssetInfos.SetABNameMode.Force); } StopwatchTools.End("【搜集KeyWord】"); //输出shader outMap[nameof(BDFrameworkAssetsEnv.FloderType.Shaders)] = incomingShaderAndVariantList; //输出 var output = connectionsToOutput?.FirstOrDefault(); if (output != null) { outputFunc(output, outMap); } }