{"id":5656,"date":"2024-05-12T23:10:41","date_gmt":"2024-05-12T15:10:41","guid":{"rendered":"http:\/\/blog.coolcoding.cn\/?p=5656"},"modified":"2024-05-28T13:22:53","modified_gmt":"2024-05-28T05:22:53","slug":"unity-ugui-%e8%83%8c%e6%99%af%e6%a8%a1%e7%b3%8a%e7%9a%84%e4%b8%80%e7%a7%8d%e5%a4%84%e7%90%86%e6%96%b9%e6%a1%88","status":"publish","type":"post","link":"https:\/\/blog.coolcoding.cn\/?p=5656","title":{"rendered":"Unity UGUI \u80cc\u666f\u52a8\u6001\u6a21\u7cca\u7684\u4e00\u79cd\u5904\u7406\u65b9\u6848"},"content":{"rendered":"\n<p>\u4e00\u3001\u903b\u8f91\u5c42\u9884\u5904\u7406<\/p>\n\n\n\n<p>\u5c06UI\u5207\u5206\u6210\u4e8c\u6bb5\uff0c\u5047\u5982\u7b2c\u4e00\u6bb5\u4e3aUI\u5c42\uff0c\u7b2c\u4e8c\u6bb5\u4e3aUIOverlay\u5c42<\/p>\n\n\n\n<p>\uff08\u5c06UI\u5c42\u7684layer\u8bbe\u7f6e\u4e3a\u9ed8\u8ba4\u7684UI\u5c42\uff0c\u65b0\u5efa\u4e00\u4e2alayer\uff0c\u547d\u540d\u4e3aUIOverlay\uff09<\/p>\n\n\n\n<p>\u5c06\u9762\u677f\u6253\u5f00\u6216\u8005\u5173\u95ed\u65f6\uff0c\u627e\u5230\u6700\u9876\u5c42\u7684\u6a21\u7cca\u5e95\u677f\uff0c\u7136\u540e<\/p>\n\n\n\n<p>\u5c06\u6b64\u5e95\u677f\u4e0b\u9762\u7684\uff0c\u8bbe\u7f6e\u4e3aUI\u5c42<\/p>\n\n\n\n<p>\u5c06\u6b64\u5e95\u677f\u4e0a\u9762\u7684\uff0c\u8bbe\u7f6e\u4e3aUIOverlay\u5c42<\/p>\n\n\n\n<p>\u4e8c\u3001\u6e32\u67d3\u5c42\u6dfb\u52a0\u6a21\u7cca<\/p>\n\n\n\n<p>1\u3001\u4fee\u6539URP\u5e95\u5c42\u7ba1\u7ebf\u4ee3\u7801\uff0c\u5728\u6e32\u67d3\u534a\u900f\u660e\u7269\u4ef6\u7684\u5730\u65b9\uff0c\u518d\u6e32\u67d3\u4e00\u904d\u534a\u900f\u660e\u7269\u4ef6<\/p>\n\n\n\n<p>2\u3001\u6216\u8005\u518d\u6dfb\u52a0\u4e00\u4e2aUI\u76f8\u673a\uff0c\u628aCullingMask\u8bbe\u7f6e\u4e3aUIOverlay<\/p>\n\n\n\n<p><strong>\u5373\u753b2\u904dUI\u5143\u7d20\uff0c\u7b2c\u4e00\u904d\u6b63\u5e38\u753b\uff0c\u7b2c\u4e8c\u904d\u53ea\u753b\u5e26\u6709\u6a21\u7cca\u7684UI\u9762\u677f<\/strong><\/p>\n\n\n\n<p><strong>\u7136\u540e\u5728\u7b2c\u4e00\u904d\u753b\u5b8c\u4e4b\u540e\uff0c\u628a\u989c\u8272RT\u62f7\u51fa\u6765\uff0c\u505a\u51e0\u6b21\u6a21\u7cca\uff0c\u7136\u540e\u6b64RT\u5b58\u597d\u5907\u7528\u5373\u53ef<\/strong><\/p>\n\n\n\n<!--nextpage-->\n\n\n\n<p>\u5177\u4f53\u5b9e\u73b0\u90e8\u5206\u4ee3\u7801<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public struct RenderingData\n{\n    public CullingResults cullResults;\n    public CameraData cameraData;\n    public LightData lightData;\n    public ShadowData shadowData;\n    public PostProcessingData postProcessingData;\n    public bool supportsDynamicBatching;\n    public PerObjectData perObjectData;\n    public short customSortingLayerRange;\n}\n\n\/\/ ScriptableRenderer.cs\nif (renderBlocks.GetLength(RenderPassBlock.MainRenderingTransparent) > 0)\n{\n    if ( mBlurCameraName.Length > 0 &amp;&amp; renderingData.cameraData.camera.name == mBlurCameraName)\n    {\n        renderingData.customSortingLayerRange = mBlurSortingLayer;\n    }\n\n    using var profScope = new ProfilingScope(null, Profiling.RenderBlock.mainRenderingOpaque);\n    ExecuteBlock(RenderPassBlock.MainRenderingTransparent, in renderBlocks, context, ref renderingData);\n    renderingData.customSortingLayerRange = 0;\n}\n\n\/\/ Render2DLightingPass.cs\nProfiler.BeginSample(\"Render Sprites Unlit\");\nvar customSortingLayerRange = renderingData.customSortingLayerRange;\nif (customSortingLayerRange != 0)\n{\n    filterSettings.sortingLayerRange = new SortingLayerRange(short.MinValue, (short)(customSortingLayerRange-1));\n    Render(context, cmd, ref renderingData, ref filterSettings, unlitDrawSettings);\n\n    ScriptableRenderer.ProcessBlurPass(context, renderingData);\n    cmd.SetRenderTarget(colorAttachment, RenderBufferLoadAction.Load, storeAction, depthAttachment, RenderBufferLoadAction.Load, storeAction);\n    context.ExecuteCommandBuffer(cmd);\n\n    filterSettings.sortingLayerRange = new SortingLayerRange( (short)(customSortingLayerRange), (short)(customSortingLayerRange));\n    Render(context, cmd, ref renderingData, ref filterSettings, unlitDrawSettings);\n}\nelse\n{\n    Render(context, cmd, ref renderingData, ref filterSettings, unlitDrawSettings);\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u903b\u8f91\u5c42\u9884\u5904\u7406 \u5c06UI\u5207\u5206\u6210\u4e8c\u6bb5\uff0c\u5047\u5982\u7b2c\u4e00\u6bb5\u4e3aUI\u5c42\uff0c\u7b2c\u4e8c\u6bb5\u4e3aUIOverlay\u5c42 \uff08\u5c06UI\u5c42\u7684layer\u8bbe [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/5656"}],"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=5656"}],"version-history":[{"count":6,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/5656\/revisions"}],"predecessor-version":[{"id":5675,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/5656\/revisions\/5675"}],"wp:attachment":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5656"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5656"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5656"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}