{"id":14299,"date":"2015-09-02T21:53:29","date_gmt":"2015-09-02T12:53:29","guid":{"rendered":"http:\/\/labs.gree.jp\/blog\/?p=14299"},"modified":"2015-09-29T23:33:36","modified_gmt":"2015-09-29T14:33:36","slug":"reordablelist%e3%81%a8propertydrawer%e3%82%92%e7%b5%84%e3%81%bf%e5%90%88%e3%82%8f%e3%81%9b%e3%81%a6%e4%bd%bf%e3%81%86","status":"publish","type":"post","link":"https:\/\/labs.gree.jp\/blog\/2015\/09\/14299\/","title":{"rendered":"ReorderableList\u3068PropertyDrawer\u3092\u7d44\u307f\u5408\u308f\u305b\u3066\u4f7f\u3046"},"content":{"rendered":"<p>\u305f\u3073\u305f\u3073\u3067\u3059\u304c\u3061\u3087\u3073\u3048\u3067\u3059\u3002\u4eca\u65e5\u306fReorderableList\u3068PropertyDrawer\u306e\u7d44\u307f\u5408\u308f\u305b\u3067\u60a9\u3093\u3067\u3057\u307e\u3063\u305f\u306e\u3067\u307e\u305f\u66f8\u3044\u3068\u304d\u307e\u3059\u3002<\/p>\n<h1>UnityEditor\u3067\u4e26\u3073\u66ff\u3048\u3067\u304d\u308b\u30ea\u30b9\u30c8\u304c\u6b32\u3057\u3044<\/h1>\n<p>\u3068\u306a\u308b\u3068\u3001\u3042\u307e\u308a\u8aac\u660e\u304c\u3055\u308c\u3066\u3044\u306a\u3044ReorderableList\u3092\u3064\u304b\u3046\u306e\u304c\u3068\u3066\u3082\u826f\u3044\u611f\u3058\u3067\u3059\u3002\u304c\u6d77\u5916\u3067\u3082\u65e5\u672c\u3067\u3082ReorderableList\u3068PropertyDrawer\u306e\u7d44\u307f\u5408\u308f\u305b\u3063\u3066<br \/>\n\u5206\u304b\u308a\u3084\u3059\u3044\u89e3\u8aac\u304c\u306a\u304f\u3053\u3093\u304c\u3089\u304c\u308a\u304c\u3061\u3067\u3059\u3002\u5fa1\u591a\u5206\u306b\u3082\u308c\u305a\u30cf\u30de\u3063\u3066\u3057\u307e\u3063\u305f\u306e\u3067\u5fd8\u308c\u306a\u3044\u3088\u3046\u306b\u66f8\u3044\u3068\u304d\u307e\u3059\u3002<\/p>\n<h2>PropertyDrawer<\/h2>\n<p>PropertyDrawer\u306fSystem.Serializable\u306eAttribute\u3092\u4ed8\u3051\u305fPrimitive\u3084\u30af\u30e9\u30b9\u306a\u3069\u3092\u3044\u3044\u611f\u3058\u306b\u8868\u793a\u3057\u3066\u304f\u308c\u308b\u6a5f\u80fd\u3067\u3059\u3002<br \/>\n\u30ab\u30b9\u30bf\u30e0Inspector\u306fComponent\u3068\u5bfe\u3001\u30ab\u30b9\u30bf\u30e0PropertyDrawer\u306f\u30d7\u30ed\u30d1\u30c6\u30a3\u3084\u30d5\u30a3\u30fc\u30eb\u30c9\u3068\u5bfe\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u4f8b\u3048\u3070\u3001PersonData\u3068\u3044\u3046\u30af\u30e9\u30b9\u304c\u3042\u308b\u3068\u3057\u3066\u3001PropertyDrawer\u3092\u30ab\u30b9\u30bf\u30e0\u3057\u305f\u3044\u5834\u5408\u306f\u4e0b\u8a18\u306e\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"lang:c# decode:true \" title=\"PersonData.cs\" >using System;\nusing UnityEngine;\n\n[Serializable]\npublic class PersonData\n{\n    public string Name;\n\n    public int Age;\n\n    public override string ToString()\n    {\n        return string.Format(\"{0} {1}\", Name, Age);\n    }\n}<\/pre>\n<p>Addressbook\u3068\u3044\u3046Monobehaviour\u3092\u7d99\u627f\u3057\u305f\u30af\u30e9\u30b9\u3092\u4f5c\u6210\u3057\u3001PersonData\u3092\u3082\u305f\u305b\u3066\u307f\u307e\u3059<\/p>\n<pre class=\"lang:c# decode:true \" title=\"Addressbook.cs\" >using UnityEngine;\nusing System.Collections;\n\npublic class Addressbook : MonoBehaviour\n{\n    [SerializeField]\n    PersonData data;\n}\n<\/pre>\n<p>\u3053\u306e\u72b6\u614b\u3067GameObject\u306b\u30a2\u30bf\u30c3\u30c1\u3059\u308b\u3068\u3001\u3053\u306e\u3088\u3046\u306a\u8868\u793a\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><a href=\"http:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2015\/09\/before_propertydrawer.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2015\/09\/before_propertydrawer.jpg\" alt=\"before_propertydrawer\" width=\"289\" height=\"97\" class=\"alignnone size-full wp-image-14300\" srcset=\"https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2015\/09\/before_propertydrawer.jpg 289w, https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2015\/09\/before_propertydrawer-276x93.jpg 276w\" sizes=\"auto, (max-width: 289px) 100vw, 289px\" \/><\/a><\/p>\n<p>\u3053\u306e\u5834\u5408\u305d\u306e\u307e\u307e\u3067\u3082\u5341\u5206\u898b\u3084\u3059\u3044\u72b6\u614b\u306a\u306e\u3067\u3059\u304c\u3001PropertyDrawer\u3092\u4f7f\u3063\u3066data\u30d5\u30a3\u30fc\u30eb\u30c9\u306e\u8868\u793a\u3092\u5909\u66f4\u3057\u3066\u307f\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<br \/>\n\u4e0b\u8a18\u30b9\u30af\u30ea\u30d7\u30c8\u3092Editor\/PersonDataDrawer.cs\u3068\u3044\u3046\u540d\u524d\u3067\u4fdd\u5b58\u3057\u3066\u518d\u8aad\u307f\u8fbc\u307f\u3092\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<pre class=\"lang:c# decode:true \" title=\"Editor\/PersonDataDrawer.cs\" >using UnityEngine;\nusing System.Collections;\nusing UnityEditor;\n\n\n[CustomPropertyDrawer(typeof (PersonData))]\npublic class PersonDataDrawer : PropertyDrawer\n{\n    public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)\n    {\n        \/\/\u3068\u308a\u3042\u3048\u305alabel\u306a\u3057\u3067\u534a\u5206\u306b\u3057\u305f\u5165\u529b\u30d5\u30a3\u30fc\u30eb\u30c9\u3092\u3064\u304f\u308b\n        position.width *= 0.5f;\n        EditorGUI.PropertyField(position, property.FindPropertyRelative(\"Name\"), GUIContent.none);\n\n        position.x += position.width;\n        EditorGUI.PropertyField(position, property.FindPropertyRelative(\"Age\"), GUIContent.none);\n    }\n}<\/pre>\n<p><a href=\"http:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2015\/09\/after_propertydrawer.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2015\/09\/after_propertydrawer.jpg\" alt=\"after_propertydrawer\" width=\"284\" height=\"109\" class=\"alignnone size-full wp-image-14301\" srcset=\"https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2015\/09\/after_propertydrawer.jpg 284w, https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2015\/09\/after_propertydrawer-276x106.jpg 276w\" sizes=\"auto, (max-width: 284px) 100vw, 284px\" \/><\/a><\/p>\n<p>\u3053\u306e\u3088\u3046\u306b\u3001data\u30d5\u30a3\u30fc\u30eb\u30c9\u306eInspector\u3067\u306e\u898b\u305f\u76ee\u3092\u30ab\u30b9\u30bf\u30e0\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3057\u305f\u3002<br \/>\n\u4eca\u56de\u306e\u5834\u5408\u3001\u3082\u3068\u3082\u3068\u306e\u72b6\u614b\u306e\u307b\u3046\u304c\u898b\u3084\u3059\u3044\u306e\u3067\u3059\u304c\u81ea\u524d\u3067\u30ab\u30b9\u30bf\u30e0\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3001\u3068\u3044\u3046\u306e\u304c\u308f\u304b\u308c\u3070OK\u3067\u3059\u3002<\/p>\n<h2>ReorderableList\u3068\u7d44\u307f\u5408\u308f\u305b\u3057\u3066\u307f\u308b<\/h2>\n<p>ReorderableList\u306fMecanim\u306a\u3069\u306ePriority\u5909\u66f4\u306a\u3069\u3067\u4f7f\u308f\u308c\u3066\u3044\u308bUI\u90e8\u5206\u3067\u3059\u3002\u9806\u756a\u304c\u91cd\u8981\u306a\u30ea\u30b9\u30c8\u3092Inspector\u4e0a\u3067\u5909\u66f4\u3057\u305f\u3044\u5834\u5408\u306fReorderableList\u3092\u4f7f\u3046\u306e\u304c<br \/>\n\u73fe\u5b9f\u7684\u306a\u624b\u6bb5\u3060\u3068\u601d\u3044\u307e\u3059\u3002<br \/>\nAddressbook\u306e\u30ab\u30b9\u30bf\u30e0\u30a4\u30f3\u30b9\u30da\u30af\u30bf\u30fc\u3092\u4f5c\u6210\u3057\u3001\u81ea\u524d\u3067Addressbook\u306eInspector\u3092\u63cf\u753b\u3067\u304d\u308b\u3088\u3046\u306b\u3057\u307e\u3059\u3002<\/p>\n<p>\u4e0b\u8a18\u30b9\u30af\u30ea\u30d7\u30c8\u3092Editor\/AddressbookInspector.cs\u3067\u4fdd\u5b58\u3057\u307e\u3059\u3002<\/p>\n<pre class=\"lang:c# decode:true \" title=\"Editor\/AddressbookInspector.cs\" >using UnityEngine;\nusing UnityEditor;\nusing UnityEditorInternal;\n\n[CustomEditor(typeof(Addressbook))]\npublic class AddressbookInspector : Editor\n{\n    private ReorderableList reorderableList;\n\n    void OnEnable()\n    {\n        \/\/SerializedObject\u304b\u3089data(Addressbook.data)\u3092\u53d6\u5f97\u3057\u3001ReordableList\u3092\u4f5c\u6210\u3059\u308b\n        reorderableList = new ReorderableList(serializedObject, serializedObject.FindProperty(\"data\"));\n        reorderableList.drawElementCallback += (Rect rect, int index, bool selected, bool focused) =&gt;\n        {\n            SerializedProperty property = reorderableList.serializedProperty.GetArrayElementAtIndex(index);\n            \/\/ PropertyField\u3092\u4f7f\u3063\u3066\u3088\u3057\u306a\u306b\u30d7\u30ed\u30d1\u30c6\u30a3\u306e\u63cf\u753b\u3092\u884c\u3046\uff08PersonData\u306fPropertyDrawer\u3092\u4f7f\u3063\u3066\u3044\u308b\u306e\u3067\u305d\u3061\u3089\u306b\u79fb\u8b72\u3055\u308c\u307e\u3059\uff09\n            EditorGUI.PropertyField(rect, property, GUIContent.none);\n        };\n        reorderableList.drawHeaderCallback += rect =&gt;\n        {\n            EditorGUI.LabelField(rect, \"Addressbok:\");\n        };\n    }\n\n    public override void OnInspectorGUI()\n    {\n        \/\/ \u81ea\u524d\u3067\u63cf\u753b\u3057\u3066\u3044\u308b\u90e8\u5206\u3002ApplyModifiedProperties\u3082\u5fd8\u308c\u305a\u306b\uff01\n        reorderableList.DoLayoutList();\n        serializedObject.ApplyModifiedProperties();\n    }\n}<\/pre>\n<p>\u3064\u3044\u3067\u306bAddressbook.cs\u306ePersonData\u3082ReordableList\u3067\u6271\u3044\u3084\u3059\u3044\u3088\u3046\u306b\u914d\u5217\u306b\u3057\u3066\u304a\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n<pre class=\"lang:c# decode:true \" title=\"Addressbook.cs\" >using UnityEngine;\nusing System.Collections;\n\npublic class Addressbook : MonoBehaviour\n{\n    [SerializeField]\n    PersonData[] data;\n\n}\n<\/pre>\n<p>\u3053\u306e\u72b6\u614b\u3067\u6700\u65b0\u306e\u72b6\u614b\u306b\u3059\u308b\u3068Inspector\u304c\u6b21\u306e\u3088\u3046\u306a\u8868\u793a\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n<p><a href=\"http:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2015\/09\/reordablelist_1.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2015\/09\/reordablelist_1.jpg\" alt=\"reordablelist_1\" width=\"289\" height=\"86\" class=\"alignnone size-full wp-image-14302\" srcset=\"https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2015\/09\/reordablelist_1.jpg 289w, https:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2015\/09\/reordablelist_1-276x82.jpg 276w\" sizes=\"auto, (max-width: 289px) 100vw, 289px\" \/><\/a><\/p>\n<p>\u53f3\u4e0b\u306e+\u30dc\u30bf\u30f3\u3092\u62bc\u3059\u3053\u3068\u3067\u884c\u3092\u8ffd\u52a0\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p><a href=\"http:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2015\/09\/reordablelist_2.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/labs.gree.jp\/blog\/wp-content\/uploads\/2015\/09\/reordablelist_2.jpg\" alt=\"reordablelist_2\" width=\"270\" height=\"98\" class=\"alignnone size-full wp-image-14303\" \/><\/a><\/p>\n<p>ReordableList\u3078\u306e\u30a4\u30d9\u30f3\u30c8\u8ffd\u52a0\u3001\u767b\u9332\u304c\u82e5\u5e72\u9069\u5f53\u3067\u306f\u3042\u308a\u307e\u3059\u304c\u307e\u3041\u307e\u3041\u3001\u3001\u3001\u3001\u3046\u3054\u3044\u3066\u3044\u308b\u306e\u3067\u826f\u3057\u3068\u3057\u307e\u3057\u3087\u3046\u3002<br \/>\n\u5b9f\u969b\u306b\u4f7f\u3046\u5834\u5408\u306fReordableList\u306e\u30a4\u30d9\u30f3\u30c8\u3092\u6b63\u3057\u304f\u8a2d\u5b9a\u3057\u3066\u304f\u3060\u3055\u3044\u3002\u30c9\u30ad\u30e5\u30e1\u30f3\u30c8\u306b\u8a18\u8f09\u304c\u3042\u308a\u307e\u305b\u3093\u304c\u3001\u5b89\u85e4\u3055\u3093\u306e<a href=\"http:\/\/anchan828.github.io\/editor-manual\/\">UnityEditor\u62e1\u5f35<\/a>\u306b\u8a73\u3057\u304f\u8a18\u8f09\u3042\u3063\u305f\u308a\u3001\u4e0b\u8a18\u30da\u30fc\u30b8\u306b\u30a4\u30d9\u30f3\u30c8\u306b\u3064\u3044\u3066\u66f8\u3044\u3066\u3042\u3063\u305f\u308a\u3057\u307e\u3059\u3002<\/p>\n<div class=\"blog-card\">\n<div class=\"blog-card-body-outer\">\n<div class=\"blog-card-body\">\n<h5 class=\"blog-card-title\">\n\t\t\t\t\t\t\t\t<a href=\"http:\/\/www.toxicfork.com\/90\/fixed-width-labels-for-fields-in-unity3d\">firtoz | notes on building<\/a><br \/>\n\t\t\t\t\t\t\t<\/h5>\n<p class=\"blog-card-text\">\n\t\t\t\t\t\t\t\tNotes on building real things: AI, web, games, and the systems behind them.\t\t\t\t\t\t\t<\/p>\n<div class=\"blog-card-site-title\">\n\t\t\t\t\t\t\t<a href=\"http:\/\/www.toxicfork.com\"><br \/>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<img decoding=\"async\" loading=\"lazy\" src=\"https:\/\/firtoz.com\/media\/81b50cc6-d514-4e22-a984-e72746e63078.png\" width=\"16\" height=\"16\" alt=\"\" ><br \/>\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tfirtoz\t\t\t\t\t\t\t<\/a>\n\t\t\t\t\t\t<\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div class=\"blog-card-image-outer\">\n\t\t\t\t\t\t<a href=\"http:\/\/www.toxicfork.com\/90\/fixed-width-labels-for-fields-in-unity3d\" class=\"blog-card-image-frame\"><br \/>\n\t\t\t\t\t\t\t<img decoding=\"async\" class=\"blog-card-image-src\" src=\"https:\/\/firtoz.com\/og.png\" alt=\"\"><br \/>\n\t\t\t\t\t\t<\/a>\n\t\t\t\t\t<\/div>\n<\/p><\/div>\n<h2>\u307e\u3068\u3081<\/h2>\n<p>\u7c21\u5358\u3067\u306f\u3042\u308a\u307e\u3059\u304c\u3001ReorderableList\u3068PropertyDrawer\u3092\u7d44\u307f\u5408\u308f\u305b\u305f\u5834\u5408\u306e\u3084\u308a\u65b9\u306b\u3064\u3044\u3066\u307e\u3068\u3081\u307e\u3057\u305f\u3002<br \/>\nprimitive\u306a\u914d\u5217\u4ee5\u5916\u3092\u4fdd\u5b58\u3057\u305f\u308a\u3001\u63cf\u753b\u3057\u3088\u3046\u3068\u3059\u308b\u3068\u30ab\u30b9\u30bf\u30e0\u30a4\u30f3\u30b9\u30da\u30af\u30bf\u30fc+drawElementCallback\u3060\u3068\u304b\u306a\u308a\u3064\u3089\u3044\u611f\u3058\u306b\u306a\u3063\u3066\u3057\u307e\u3046\u306e\u3067<br \/>\nPropertyDrawer\u3092\u4f5c\u6210\u3057\u3066\u5229\u7528\u3059\u308b\u306e\u304c\u4f5c\u308a\u65b9\u7684\u306b\u3082\u3084\u308a\u3084\u3059\u3044\u304b\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n<p>\u3067\u306f\u3067\u306f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u305f\u3073\u305f\u3073\u3067\u3059\u304c\u3061\u3087\u3073\u3048\u3067\u3059\u3002\u4eca\u65e5\u306fReorderableList\u3068PropertyDrawer\u306e\u7d44\u307f\u5408\u308f\u305b\u3067\u60a9\u3093\u3067\u3057\u307e\u3063\u305f\u306e\u3067\u307e\u305f\u66f8\u3044\u3068\u304d\u307e\u3059\u3002 UnityEditor\u3067\u4e26\u3073\u66ff\u3048\u3067\u304d\u308b\u30ea\u30b9\u30c8\u304c\u6b32\u3057\u3044 \u3068\u306a\u308b\u3068\u3001\u3042\u307e\u308a\u8aac\u660e [&hellip;]<\/p>\n","protected":false},"author":100,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[],"tags":[40],"class_list":["post-14299","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","tag-unity"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/posts\/14299","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/users\/100"}],"replies":[{"embeddable":true,"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/comments?post=14299"}],"version-history":[{"count":3,"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/posts\/14299\/revisions"}],"predecessor-version":[{"id":14327,"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/posts\/14299\/revisions\/14327"}],"wp:attachment":[{"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/media?parent=14299"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/categories?post=14299"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/labs.gree.jp\/blog\/wp-json\/wp\/v2\/tags?post=14299"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}