//更新变体数量 可以通过变体公式计算 另外是否可通过编译出的文件计算? public void UpdateVariantCount() { totalVariantCount = 0; actualBuildVariantCount = 0; //遍历pass for (int i = 0; i < passes.Count; i++) { StripShaderPass pass = passes[i]; int matCount = materials.Count; int pasStripCount = 1; int passBuildCount = 1; //遍历编译指令行 for (int l = 0; l < pass.keywordLines.Count; l++) { StripKeywordLine line = pass.keywordLines[l]; //kLineEnabledCount 所有enable的keyword 有没有 _ int kLineEnabledCount = line.hasUnderStriporeVariant ? 1 : 0; //line.keywords 里不包含 __ 有_ 关键字+1 int kLineCount = kLineEnabledCount; //如果是 缩写的关键字 if (ShaderHelper.IsBuiltinShortcut(line.shaderLineType)) { StripKeyword[] stripKeyword = null; if (pass.hasSkipKeyword) { stripKeyword = pass.skipKeywords.ToArray(); } kLineCount += ShaderHelper.GetShortcutVariantCount(line.shaderLineType, stripKeyword); } //multi_compile shader_fearure 要除去skip else if (ShaderHelper.IsInputShortcut(line.shaderLineType) && line.shaderLineType != ShaderLineType.SKIP_VARIANTS) { if (ShaderHelper.IsSahderFeature(line.shaderLineType) && line.keywords.Count == 1) { kLineCount += 2; } else { kLineCount += line.keywords.Count; } } for (int k = 0; k < line.keywords.Count; k++) { StripKeyword keyword = line.keywords[k]; if (keyword.enabled) { //如果是 shader feature检查是否有材质使用 if (ShaderHelper.IsBuiltinShortcut(line.shaderLineType) || ShaderHelper.IsSahderFeature(line.shaderLineType)) { for (int m = 0; m < matCount; m++) { //遍历关联的材质 if (materials[m].ContainsKeyword(keyword.name)) { kLineEnabledCount++; break; } } } else { kLineEnabledCount++; } } } //实际使用的关键字 if (kLineEnabledCount > 0) { //实际使用的参与编译的 指令行的指令乘积 passBuildCount *= kLineEnabledCount; } //全部编译指令行的指令乘积 包括没有使用的fearure pasStripCount *= kLineCount; } totalVariantCount += pasStripCount; actualBuildVariantCount += passBuildCount; } //计算enabed关键字数量 keywordEnabledCount = 0; int keywordCount = keywords.Count; for (int k = 0; k < keywordCount; k++) { if (keywords[k].enabled) { keywordEnabledCount++; } } }