{"id":228,"date":"2019-04-28T19:26:41","date_gmt":"2019-04-28T19:26:41","guid":{"rendered":"https:\/\/docs.sisus.co\/power-inspector\/?p=228"},"modified":"2019-09-16T16:11:04","modified_gmt":"2019-09-16T16:11:04","slug":"drawers-for-assets","status":"publish","type":"post","link":"https:\/\/docs.sisus.co\/power-inspector\/extending-power-inspector\/drawers-for-assets\/","title":{"rendered":"07. Drawers For Assets"},"content":{"rendered":"<h1>Extending A Base Class<\/h1>\n<p>If you want to create a new <a href=\"https:\/\/docs.sisus.co\/power-inspector\/terminology\/drawer\/\">drawer<\/a> for an asset type <a href=\"https:\/\/docs.sisus.co\/power-inspector\/terminology\/unity-object\/\">Unity Object<\/a>, you can derive from one of two base classes that implements the <strong>IAssetDrawer<\/strong> interface.<\/p>\n<p>Asset type Unity Objects refer to Unity Objects that cannot exist in the scene, that is all Unity Objects except Components and GameObjects. One such example is <a href=\"https:\/\/docs.unity3d.com\/Manual\/class-ScriptableObject.html\">ScriptableObjects<\/a>.<\/p>\n<h2>1. AssetDrawer<\/h2>\n<p>Extend <strong>AssetDrawer <\/strong>if an <a href=\"https:\/\/docs.sisus.co\/power-inspector\/terminology\/editor\/\">Editor<\/a> <strong>is not<\/strong> used for drawing the class members of the drawer.<\/p>\n<p>This gives you the most power to customize the drawer, and should be used when possible for the best results.<\/p>\n<h2>2. CustomEditorAssetDrawer<\/h2>\n<p>Extend <strong>CustomEditorAssetDrawer<\/strong> if an Editor <strong>is<\/strong> used for drawing the class members of the drawer.<\/p>\n<p>In this case your options for customizing the drawer will be more limited, but you can still do things like add new header buttons or customize the context menu.<\/p>\n<p>This is mainly used when the target asset has a <a href=\"https:\/\/docs.unity3d.com\/Manual\/editor-CustomEditors.html\">Custom Editor<\/a>.<\/p>\n<pre><strong>Example: <\/strong>ModelDrawer<\/pre>\n<h1>DrawerForAssetAttribute<\/h1>\n<p>For Power Inspector to know which assets should be represented by the drawer class you&#8217;ve created, you&#8217;ll need to add the DrawerForAsset attribute to the class.<\/p>\n<h1>Setup<\/h1>\n<p>When Power Inspector prepares a drawer for use inside an Inspector, it will call two methods inside the drawer class:<\/p>\n<ol>\n<li>First, it will call the <strong>SetupInterface<\/strong> method (defined in the IEditorlessAssetDrawer and ICustomEditorAssetDrawer interfaces).<\/li>\n<li>After that has finished, it will call the <strong>LateSetup<\/strong> method (defined in the base IDrawer interface).<\/li>\n<\/ol>\n<p>All drawer class also contain a <strong>Setup<\/strong> method. The only job of the <strong>SetupInterface <\/strong>method is to take the parameters provided by Power Inspector, and to convert them into a form that the main Setup method can accept, and then call that Setup method.<\/p>\n<p>You can <strong>override<\/strong> the Setup and LateSetup methods if you want to customize the setup phase.<\/p>\n<pre><strong>IMPORTANT: <\/strong>If you override Setup or LateSetup, remember to always also call <strong>base.Setup <\/strong>and <strong>base.LateSetup<\/strong><strong>!\r\n<\/strong><\/pre>\n<h1>DoGenerateMemberBuildList<\/h1>\n<p>You can override the DoGenerateMemberBuildList method to gain control over which class members to include inside the drawer. This is done through deciding which LinkedMemberInfos are placed inside the memberBuildList.<\/p>\n<h1>DoBuildMembers<\/h1>\n<p>You can also override DoBuildMembers to customize exactly how member drawers are built from the memberBuildList that was previously generated by the DoGenerateMemberBuildList method.<\/p>\n<p>During the execution of this method all member drawers should be created and placed into the members array.<\/p>\n<p>You can use ParentDrawerUtility.BuildMembers to automatically generate members based on the contents of the memberBuildList.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Extending A Base Class If you want to create a new drawer for an asset type Unity Object, you can derive from one of two base classes that implements the IAssetDrawer interface. Asset type Unity Objects refer to Unity Objects that cannot exist in the scene, that is all Unity Objects except Components and GameObjects. ..<\/p>\n<div class=\"clear-fix\"><\/div>\n<p><a href=\"https:\/\/docs.sisus.co\/power-inspector\/extending-power-inspector\/drawers-for-assets\/\" title=\"read more\">Read more<\/a><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[10],"tags":[],"_links":{"self":[{"href":"https:\/\/docs.sisus.co\/power-inspector\/wp-json\/wp\/v2\/posts\/228"}],"collection":[{"href":"https:\/\/docs.sisus.co\/power-inspector\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.sisus.co\/power-inspector\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.sisus.co\/power-inspector\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.sisus.co\/power-inspector\/wp-json\/wp\/v2\/comments?post=228"}],"version-history":[{"count":8,"href":"https:\/\/docs.sisus.co\/power-inspector\/wp-json\/wp\/v2\/posts\/228\/revisions"}],"predecessor-version":[{"id":1041,"href":"https:\/\/docs.sisus.co\/power-inspector\/wp-json\/wp\/v2\/posts\/228\/revisions\/1041"}],"wp:attachment":[{"href":"https:\/\/docs.sisus.co\/power-inspector\/wp-json\/wp\/v2\/media?parent=228"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.sisus.co\/power-inspector\/wp-json\/wp\/v2\/categories?post=228"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.sisus.co\/power-inspector\/wp-json\/wp\/v2\/tags?post=228"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}