{"id":4913,"date":"2023-07-03T21:23:02","date_gmt":"2023-07-03T13:23:02","guid":{"rendered":"http:\/\/blog.coolcoding.cn\/?p=4913"},"modified":"2023-07-06T10:29:49","modified_gmt":"2023-07-06T02:29:49","slug":"%e6%94%b6%e9%9b%86unity%e5%8f%98%e4%bd%93%e5%b7%a5%e5%85%b7","status":"publish","type":"post","link":"https:\/\/blog.coolcoding.cn\/?p=4913","title":{"rendered":"\u6536\u96c6Unity\u53d8\u4f53\u5de5\u5177"},"content":{"rendered":"<h2>\u5904\u7406\u6b65\u9aa4<\/h2>\n<p>1\u3001\u67e5\u627e\u6240\u6709\u7684Material\u6587\u4ef6\uff0c\u6536\u96c6\u6240\u6709Material\u5bf9\u8c61\u7684shaderKeywords<br \/>\n2\u3001\u67e5\u627e\u6240\u6709\u7684Shader\u6587\u4ef6\uff0c\u83b7\u5f97 <strong>\u5e38\u7528\u7684Keyword\u5217\u8868<\/strong>\uff0c\u4ee5\u53ca <strong>\u6240\u6709\u7684Keyword\u5217\u8868<\/strong><br \/>\n3\u3001\u521b\u5efaShaderVariantCollection.ShaderVariant\u5bf9\u8c61svobj<br \/>\n4\u3001\u5224\u65adMaterials\u4e2d\u7684keywords\u5982\u679c\u5728 \u5e38\u7528\u7684Keyword\u5217\u8868\u4e2d\uff0c\u5219\u8ffd\u52a0\u5230svobj<br \/>\n5\u3001\u5982\u679c\u6709\u81ea\u5b9a\u4e49\u7684EnableKeyword\uff0c\u5224\u65ad\u5b83\u662f\u5426\u5728 \u6240\u6709\u7684Keyword\u5217\u8868\u4e2d\uff0c\u5982\u679c\u5728\uff0c\u8ffd\u52a0\u5230svobj<br \/>\n6\u3001\u5c06svobj\u5bf9\u8c61\u5199\u5165\u5230 ShaderVariant \u53d8\u4f53\u6587\u4ef6\u4e2d\uff0c\u5b8c\u6210\u6536\u96c6<\/p>\n<p><strong>\u603b\u7ed3<\/strong><br \/>\n\u5148\u628a\u6750\u8d28\u4e2d\u7528\u5230\u7684\u5e38\u7528\u7ec4\u5408\u5199\u5165\u5230\u53d8\u4f53\u4e2d<br \/>\n\u518d\u628a\u4ee3\u7801\u4e2d\u624b\u52a8\u7684\u7ec4\u5408\u5199\u5165\u5230\u53d8\u4f53\u4e2d\uff0c\u6ce8\u610f\uff1a\u4ee3\u7801\u4e2d\u63a7\u5236\u7684\u5b8f\uff0c\u8981\u7528multi_compile<\/p>\n<pre><code class=\"language-c#\">public int AddMultiCompileKeywords(Shader shader, ShaderVariantCollection shaderVariantCollections)\n{\n    if (mPassTypes.Length == 0)\n    {\n        return -2;\n    }\n\n    foreach(var strKeywords in mAllCombinaKeywords)\n    {\n        var keywordArray = strKeywords.Split(&#039; &#039;);\n        foreach (var passType in mPassTypes)\n        {\n            var ePassType = (UnityEngine.Rendering.PassType)passType;\n            var shaderVariant = new ShaderVariantCollection.ShaderVariant()\n            {\n                shader = shader,\n                passType = ePassType,\n                keywords = keywordArray\n            };\n            if (!shaderVariantCollections.Contains(shaderVariant))\n            {\n                shaderVariantCollections.Add(shaderVariant);\n            }\n        }\n    }\n\n    return 0;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5904\u7406\u6b65\u9aa4 1\u3001\u67e5\u627e\u6240\u6709\u7684Material\u6587\u4ef6\uff0c\u6536\u96c6\u6240\u6709Material\u5bf9\u8c61\u7684shaderKeywords 2\u3001 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/4913"}],"collection":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4913"}],"version-history":[{"count":8,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/4913\/revisions"}],"predecessor-version":[{"id":4922,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/4913\/revisions\/4922"}],"wp:attachment":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4913"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4913"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4913"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}