{"id":1035,"date":"2019-09-16T16:05:08","date_gmt":"2019-09-16T16:05:08","guid":{"rendered":"https:\/\/docs.sisus.co\/power-inspector\/?p=1035"},"modified":"2021-03-24T18:11:43","modified_gmt":"2021-03-24T18:11:43","slug":"referencing-code-in-power-inspector","status":"publish","type":"post","link":"https:\/\/docs.sisus.co\/power-inspector\/extending-power-inspector\/referencing-code-in-power-inspector\/","title":{"rendered":"01. Referencing Code in Power Inspector"},"content":{"rendered":"<h1>Assembly Definition Files<\/h1>\n<p><img loading=\"lazy\" class=\"alignnone size-full wp-image-1333\" src=\"https:\/\/docs.sisus.co\/power-inspector\/wp-content\/uploads\/2019\/09\/assembly-definition-file.png\" alt=\"\" width=\"908\" height=\"363\" srcset=\"https:\/\/docs.sisus.co\/power-inspector\/wp-content\/uploads\/sites\/2\/2019\/09\/assembly-definition-file.png 908w, https:\/\/docs.sisus.co\/power-inspector\/wp-content\/uploads\/sites\/2\/2019\/09\/assembly-definition-file-300x120.png 300w, https:\/\/docs.sisus.co\/power-inspector\/wp-content\/uploads\/sites\/2\/2019\/09\/assembly-definition-file-768x307.png 768w\" sizes=\"(max-width: 908px) 100vw, 908px\" \/><\/p>\n<p>Power Inspector makes use of <a href=\"https:\/\/docs.unity3d.com\/Manual\/ScriptCompilationAssemblyDefinitionFiles.html\"><strong>assembly definition files<\/strong><\/a> to separate its scripts into assemblies that are kept separate from the other scripts in your project.<\/p>\n<p>This reduces the compilation times in your project, because Unity does not need to rebuild the Power Inspector assemblies every time you make changes to your own code when there are no references between them.<\/p>\n<p>This however also means that in order to make any references from your code to code in Power Inspector, you will have to first go through a couple of steps:<\/p>\n<ol>\n<li>Make sure that the script file from which you are trying to reference Power Inspector is included in an assembly definition file. If not, you can create a new assembly definition file in the <strong>Project view<\/strong> by selecting the root folder for your script assets, clicking the <strong>Create<\/strong> button and selecting <strong>Assembly Definition<\/strong>. You should also create separate Assembly Definition assets inside all your <strong><a href=\"https:\/\/docs.unity3d.com\/Manual\/SpecialFolders.html\">Editor folders<\/a><\/strong> that contain script assets (if you have any).<\/li>\n<li><strong>Select<\/strong> the <strong>assembly definition asset<\/strong> for your script to view it in the inspector.<\/li>\n<li><strong>Click<\/strong> the <strong>+ sign<\/strong> at the bottom of the <strong>Assembly Definition References<\/strong> list.<\/li>\n<li><strong>Click<\/strong> the <strong>circular<\/strong> icon on the new entry that appeared at the bottom of the list to open the Object picker view.<\/li>\n<li>Select <strong>PowerInspector<\/strong> from the list.<\/li>\n<\/ol>\n<h1>POWER_INSPECTOR preprocessor directive<\/h1>\n<p>When Power Inspector is added to a project, the <strong>preprocessor directive POWER_INSPECTOR<\/strong> is automatically added to the Scripting Define Symbols list in your Player Settings.<\/p>\n<p>This makes it possible for you to write code that refers to classes inside the Power Inspector that is only compiled if Power Inspector is installed. This way your extensions won&#8217;t generate any compile errors even if Power Inspector is not installed on the project.<\/p>\n<p>This is especially useful for any code that you are going to publish in the asset store.<\/p>\n<p><strong>Example<\/strong><\/p>\n<pre>#if POWER_INSPECTOR \/\/ Code is only compiled if Power Inspector is installed.\r\nvoid OnGUI()\r\n{\r\n\tif(GUILayout.Button(\"Open In Power Inspector\"))\r\n\t{\r\n\t\tPowerInspectorWindowUtility.OpenNewWindow(this);\r\n\t}\r\n}\r\n#endif<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Assembly Definition Files Power Inspector makes use of assembly definition files to separate its scripts into assemblies that are kept separate from the other scripts in your project. This reduces the compilation times in your project, because Unity does not need to rebuild the Power Inspector assemblies every time you make changes to your own ..<\/p>\n<div class=\"clear-fix\"><\/div>\n<p><a href=\"https:\/\/docs.sisus.co\/power-inspector\/extending-power-inspector\/referencing-code-in-power-inspector\/\" 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\/1035"}],"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=1035"}],"version-history":[{"count":10,"href":"https:\/\/docs.sisus.co\/power-inspector\/wp-json\/wp\/v2\/posts\/1035\/revisions"}],"predecessor-version":[{"id":1854,"href":"https:\/\/docs.sisus.co\/power-inspector\/wp-json\/wp\/v2\/posts\/1035\/revisions\/1854"}],"wp:attachment":[{"href":"https:\/\/docs.sisus.co\/power-inspector\/wp-json\/wp\/v2\/media?parent=1035"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.sisus.co\/power-inspector\/wp-json\/wp\/v2\/categories?post=1035"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.sisus.co\/power-inspector\/wp-json\/wp\/v2\/tags?post=1035"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}