{"id":5533,"date":"2023-12-16T13:21:16","date_gmt":"2023-12-16T05:21:16","guid":{"rendered":"http:\/\/blog.coolcoding.cn\/?p=5533"},"modified":"2023-12-18T19:39:28","modified_gmt":"2023-12-18T11:39:28","slug":"unity-sortinggroup%e4%bd%bf%e7%94%a8%e8%ae%b0%e5%bd%95","status":"publish","type":"post","link":"https:\/\/blog.coolcoding.cn\/?p=5533","title":{"rendered":"Unity SortingGroup\u4f7f\u7528\u8bb0\u5f55"},"content":{"rendered":"\n<p>\u5982\u679c\u4e00\u4e2aSpine\u6709\u591a\u4e2a\u5c42\uff0c\u591a\u4e2aSpine\u653e\u5728\u4e00\u8d77\uff0c\u9700\u8981\u7ed9\u6bcf\u4e2aSpine\u8eab\u4e0a\u6302\u4e00\u4e2aSortingGroup\uff0c\u4ee5\u4fdd\u8bc1\u5176\u6e32\u67d3\u5c42\u6b21\u662f\u6b63\u786e\u7684<\/p>\n\n\n\n<p>\u5982\u679c\u4e00\u4e2aSpine\u7684\u9aa8\u9abc\u4e0b\uff0c\u6302\u4e86\u591a\u4e2aSpine\uff0c\u8fd9\u4e2a\u7236\u7ea7Spine\u8eab\u4e0a\u6302\u4e86SortingGroup\uff0c\u5219\u5176\u5b50\u8282\u70b9\u7684\u6e32\u67d3\u6b21\u5e8f\uff0c\u662f\u6309\u8282\u70b9\u7684\u6811\u5f62\u7ed3\u6784\u8fdb\u884c\u6e32\u67d3\uff0c\u800c\u975eZ\u503c<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>SortingGroup\u57282D\u9879\u76ee\u975e\u5e38\u91cd\u8981\uff0c\u4ed6\u201c\u8981\u6c42\u201d\u6b64\u8282\u70b9\u4e0b\u7684\u7269\u4ef6\u6253\u6210\u4e00\u7ec4\uff08\u89c6\u4e3a\u4e00\u4e2a\u6574\u4f53\uff09\u6e32\u67d3\u6210\u4e3a\u4e00\u5c42<br>\u5728SortingGroup\u5185\u90e8\uff0c\u53ef\u4ee5\u4f7f\u7528SortingLayer\u548cOrderInLayer\u8fdb\u884c\u6392\u5e8f<\/p>\n\n\n\n<p>SortingLayer\u7684\u4f18\u5148\u7ea7\u5927\u4e8eOrderInLayer\u7684\u4f18\u5148\u7ea7<\/p>\n\n\n\n<p>SortingLayer \u53ef\u4ee5\u7406\u89e3\u4e3a &#8211; \u5730\u8868 \u3001 \u4eba\u7269\u3001HUD\u5c42\uff1b\u6bcf\u5c42\u90fd\u4f1a\u4e25\u683c\u533a\u5206\u6e32\u67d3\u5c42\u7ea7<\/p>\n\n\n\n<p>OrderInLayer \u53ef\u4ee5\u7406\u89e3\u4e3a\uff0cHUD\u5c42\uff0c\u6bcf\u4e2aHUD\u9700\u8981\u5185\u90e8\u8fdb\u884c\u4e00\u4e2a\u6e32\u67d3\u5c42\u6b21\u6392\u5e8f<\/p>\n\n\n\n<p>\u6bcf\u4e2aHUD\uff0c\u90fd\u9700\u8981\u4f7f\u7528\u4e00\u4e2aSortingGroup\uff0c\u4ee5\u4fdd\u8bc1\u6bcf\u4e2a\u73a9\u5bb6\u7684HUD\u662f\u4e00\u6b21\u6027\u7ed8\u5236\u5b8c\u7684\uff0c\u5728SortingGroup\u4e0a\u9762\uff0c\u8bbe\u7f6e\u597dOrderInLayer\u5373\u53ef<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>using UnityEngine;\r\n\r\n&#91;RequireComponent(typeof(MeshRenderer))]\r\n&#91;ExecuteInEditMode]\r\npublic class TextMeshSort : MonoBehaviour\r\n{\r\n    public string LayerName = \"Layer1\";\r\n    public int mSortingOrder = 99;\r\n\r\n    void Update()\r\n    {\r\n        var m = GetComponent&lt;MeshRenderer>();\r\n        if (m != null)\r\n        {\r\n            var mSortingLayerId = SortingLayer.NameToID(LayerName);\r\n            m.sortingLayerID = mSortingLayerId;\r\n            m.sortingOrder = mSortingOrder;\r\n        }\r\n    }\r\n}\r\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u679c\u4e00\u4e2aSpine\u6709\u591a\u4e2a\u5c42\uff0c\u591a\u4e2aSpine\u653e\u5728\u4e00\u8d77\uff0c\u9700\u8981\u7ed9\u6bcf\u4e2aSpine\u8eab\u4e0a\u6302\u4e00\u4e2aSortingGroup\uff0c\u4ee5 [&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\/5533"}],"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=5533"}],"version-history":[{"count":5,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/5533\/revisions"}],"predecessor-version":[{"id":5542,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=\/wp\/v2\/posts\/5533\/revisions\/5542"}],"wp:attachment":[{"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5533"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5533"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.coolcoding.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5533"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}