{"id":68,"date":"2025-09-17T23:34:41","date_gmt":"2025-09-17T15:34:41","guid":{"rendered":"http:\/\/cl-blog.top\/?p=68"},"modified":"2025-09-22T23:41:43","modified_gmt":"2025-09-22T15:41:43","slug":"unity%e7%bc%96%e8%be%91%e5%99%a8%e7%9a%84inspector%e9%9d%a2%e6%9d%bf%e4%b8%ad%e5%ae%9e%e7%8e%b0%e4%b8%ad%e6%96%87%e6%a0%87%e7%ad%be%e3%80%82","status":"publish","type":"post","link":"https:\/\/cl-blog.top\/index.php\/2025\/09\/17\/unity%e7%bc%96%e8%be%91%e5%99%a8%e7%9a%84inspector%e9%9d%a2%e6%9d%bf%e4%b8%ad%e5%ae%9e%e7%8e%b0%e4%b8%ad%e6%96%87%e6%a0%87%e7%ad%be%e3%80%82\/","title":{"rendered":"Unity\u7f16\u8f91\u5668\u7684Inspector\u9762\u677f\u4e2d,\u5b9e\u73b0\u4e2d\u6587\u6807\u7b7e\u3002"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u4f7f\u7528\u81ea\u5b9a\u4e49\u5c5e\u6027\uff08\u5b9e\u73b0\u4e2d\u6587\u6807\u7b7e\uff09<\/h2>\n\n\n\n<p class=\"has-medium-font-size\">\u6b65\u9aa41\uff1a\u521b\u5efa&nbsp;<code>ChineseLabelAttribute.cs<\/code><\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"theme:visual-assist toolbar-overlay:false lang:c# decode:true \">using UnityEngine;\n\npublic class ChineseLabelAttribute : PropertyAttribute\n{\n    public readonly string Label;\n    \n    public ChineseLabelAttribute(string label)\n    {\n        Label = label;\n    }\n}<\/pre><\/div>\n\n\n\n<p>\u8fd9\u6bb5\u4ee3\u7801\u5b9a\u4e49\u4e86\u4e00\u4e2a\u65b0\u7684<strong>\u7279\u6027\uff08Attribute\uff09\u200b<\/strong>\uff0c\u540d\u4e3a <code>ChineseLabelAttribute<\/code>\u3002\u5b83\u7684\u4e3b\u8981\u4f5c\u7528\u662f\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u200b<strong>\u6807\u8bb0\u4e0e\u5b58\u50a8<\/strong>\u200b\uff1a\u5f53\u4f60\u5e0c\u671b\u4e00\u4e2a\u5b57\u6bb5\u5728Unity\u68c0\u89c6\u5668\u4e2d\u663e\u793a\u4e2d\u6587\u540d\u79f0\u65f6\uff0c\u53ef\u4ee5\u7528 <code>[ChineseLabel(\"\u4e2d\u6587\u540d\u79f0\")]<\/code>\u6765\u6807\u8bb0\u8fd9\u4e2a\u5b57\u6bb5\u3002\u8fd9\u4e2a\u7279\u6027\u7c7b\u4f1a<strong>\u5b58\u50a8\u4f60\u63d0\u4f9b\u7684\u4e2d\u6587\u6587\u672c<\/strong>\u3002<\/li>\n\n\n\n<li>\u200b<strong>\u5143\u6570\u636e\u9644\u52a0<\/strong>\u200b\uff1a\u5b83\u7ee7\u627f\u81eaUnity\u7684 <code>PropertyAttribute<\/code>\uff0c\u8fd9\u610f\u5473\u7740\u5b83\u53ef\u4ee5\u4f5c\u4e3a\u5143\u6570\u636e\u9644\u52a0\u5230\u811a\u672c\u7684\u5b57\u6bb5\u4e0a\uff0c\u7528\u4e8e\u5411Unity\u7f16\u8f91\u5668\u63d0\u4f9b\u989d\u5916\u7684\u4fe1\u606f\uff0c\u4f46\u672c\u8eab\u5e76\u4e0d\u6539\u53d8\u5b57\u6bb5\u7684\u7ed8\u5236\u65b9\u5f0f \u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"has-medium-font-size\">\u6b65\u9aa42\uff1a\u521b\u5efa <code>ChineseLabelDrawer.cs<\/code>\uff08\u653e\u5728Editor\u6587\u4ef6\u5939\uff09<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><\/div>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:c# decode:true \" >#if UNITY_EDITOR\nusing UnityEditor;\nusing UnityEngine;\n\n[CustomPropertyDrawer(typeof(ChineseLabelAttribute))]\npublic class ChineseLabelDrawer : PropertyDrawer\n{\n    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)\n    {\n        ChineseLabelAttribute attr = attribute as ChineseLabelAttribute;\n        EditorGUI.PropertyField(position, property, new GUIContent(attr.Label));\n    }\n}\n#endif<\/pre><\/div>\n\n\n\n<p>\u8fd9\u6bb5\u4ee3\u7801\u662f\u4e00\u4e2a<strong>\u81ea\u5b9a\u4e49\u7ed8\u5236\u5668\uff08PropertyDrawer\uff09\u200b<\/strong>\uff0c\u5b83\u8d1f\u8d23<strong>\u5982\u4f55\u7ed8\u5236<\/strong>\u88ab <code>ChineseLabelAttribute<\/code>\u6807\u8bb0\u7684\u5b57\u6bb5\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u200b<strong>\u91cd\u5199\u7ed8\u5236\u903b\u8f91<\/strong>\u200b\uff1a\u5b83\u7ee7\u627f\u81ea <code>PropertyDrawer<\/code>\u5e76\u91cd\u5199 <code>OnGUI<\/code>\u65b9\u6cd5\u3002\u8fd9\u4e2a\u65b9\u6cd5\u51b3\u5b9a\u4e86\u5c5e\u6027\u5728\u68c0\u89c6\u5668\u4e2d\u7684\u5b9e\u9645\u663e\u793a\u6837\u5b50\u3002<\/li>\n\n\n\n<li>\u200b<strong>\u66ff\u6362\u663e\u793a\u6807\u7b7e<\/strong>\u200b\uff1a\u5728 <code>OnGUI<\/code>\u65b9\u6cd5\u4e2d\uff0c\u5b83\u83b7\u53d6\u5b57\u6bb5\u4e0a <code>ChineseLabelAttribute<\/code>\u4e2d\u5b58\u50a8\u7684\u4e2d\u6587\u6807\u7b7e\uff0c\u7136\u540e\u7528\u8fd9\u4e2a\u4e2d\u6587\u6587\u672c<strong>\u66ff\u6362\u6389\u539f\u672c\u9ed8\u8ba4\u7684\u82f1\u6587\u53d8\u91cf\u540d<\/strong>\uff0c\u6700\u540e\u8c03\u7528 <code>EditorGUI.PropertyField<\/code>\u6765\u7ed8\u5236\u8fd9\u4e2a\u5b57\u6bb5 \u3002<\/li>\n\n\n\n<li>\u200b<strong>\u7f16\u8f91\u5668\u811a\u672c\u8981\u6c42<\/strong>\u200b\uff1a\u200b<strong>\u5fc5\u987b<\/strong>\u5c06\u6b64\u7c7b\u653e\u5728\u9879\u76ee\u7684 \u200b<strong><code>Editor<\/code><\/strong>\u200b \u6587\u4ef6\u5939\u4e0b\uff08\u4f8b\u5982 <code>Assets\/Editor\/ChineseLabelDrawer.cs<\/code>\uff09\uff0c\u5426\u5219Unity\u65e0\u6cd5\u6b63\u786e\u8bc6\u522b\u548c\u7f16\u8bd1\u5b83\u3002<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f7f\u7528\u81ea\u5b9a\u4e49\u5c5e\u6027\uff08\u5b9e\u73b0\u4e2d\u6587\u6807\u7b7e\uff09 \u6b65\u9aa41\uff1a\u521b\u5efa&nbsp;ChineseLabelAttribute.cs \u8fd9\u6bb5 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10],"tags":[],"class_list":["post-68","post","type-post","status-publish","format-standard","hentry","category-unity"],"_links":{"self":[{"href":"https:\/\/cl-blog.top\/index.php\/wp-json\/wp\/v2\/posts\/68","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cl-blog.top\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cl-blog.top\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cl-blog.top\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cl-blog.top\/index.php\/wp-json\/wp\/v2\/comments?post=68"}],"version-history":[{"count":13,"href":"https:\/\/cl-blog.top\/index.php\/wp-json\/wp\/v2\/posts\/68\/revisions"}],"predecessor-version":[{"id":86,"href":"https:\/\/cl-blog.top\/index.php\/wp-json\/wp\/v2\/posts\/68\/revisions\/86"}],"wp:attachment":[{"href":"https:\/\/cl-blog.top\/index.php\/wp-json\/wp\/v2\/media?parent=68"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cl-blog.top\/index.php\/wp-json\/wp\/v2\/categories?post=68"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cl-blog.top\/index.php\/wp-json\/wp\/v2\/tags?post=68"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}