{"id":1525,"date":"2019-11-20T13:40:35","date_gmt":"2019-11-20T13:40:35","guid":{"rendered":"https:\/\/docs.sisus.co\/power-inspector\/?p=1525"},"modified":"2021-03-24T17:47:50","modified_gmt":"2021-03-24T17:47:50","slug":"button","status":"publish","type":"post","link":"https:\/\/docs.sisus.co\/power-inspector\/attributes\/button\/","title":{"rendered":"Button"},"content":{"rendered":"<p>When added before a method causes the <strong>method<\/strong> to be <strong>shown<\/strong> inside the <a href=\"https:\/\/docs.sisus.co\/power-inspector\/terminology\/inspector-view\/\"><strong>inspector view<\/strong><\/a>\u00a0<strong>as a button<\/strong>.<\/p>\n<p>By default the button is shown expanded to the full width of the inspector view with no prefix label, and with the button text auto-generated from the method name.<\/p>\n<p>You can customize the button text by using the constructor with a single parameter.<\/p>\n<p>You can customize the prefix label and the button text by using the constructor with two parameters.<\/p>\n<p>You can also specify the name of a <strong><a href=\"https:\/\/docs.unity3d.com\/Manual\/class-GUIStyle.html\">GUIStyle<\/a><\/strong> to use for drawing the button by using the constructor with three parameters.<\/p>\n<h2>Attribute Target<\/h2>\n<p>Method<\/p>\n<h2>Example<\/h2>\n<pre>using Sisus.Attributes;\r\nusing UnityEngine;\r\n\r\npublic class Calculator : MonoBehaviour\r\n{\r\n\tpublic int input1;\r\n\tpublic int input2;\r\n\r\n\t[PSpace(8f)]\r\n\t[ShowInInspector]\r\n\tpublic float Result\r\n\t{\r\n\t\tget;\r\n\t\tprivate set;\r\n\t}\r\n\r\n\t[PSpace(8f)]\r\n\t[Button]\r\n\tpublic void Sum()\r\n\t{\r\n\t\tResult = input1 + input2;\r\n\t}\r\n\r\n\t[Button]\r\n\tpublic void Multiply()\r\n\t{\r\n\t\tResult = input1 * input2;\r\n\t}\r\n\r\n\t[Button]\r\n\tpublic void Divide()\r\n\t{\r\n\t\tResult = (float)input1 \/ input2;\r\n\t}\r\n}<\/pre>\n<h2>Example Result<\/h2>\n<p><img loading=\"lazy\" class=\"alignnone size-full wp-image-1527\" src=\"https:\/\/docs.sisus.co\/power-inspector\/wp-content\/uploads\/2019\/11\/Unity-ButtonAttribute-example.png\" alt=\"\" width=\"282\" height=\"150\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>When added before a method causes the method to be shown inside the inspector view\u00a0as a button. By default the button is shown expanded to the full width of the inspector view with no prefix label, and with the button text auto-generated from the method name. You can customize the button text by using the ..<\/p>\n<div class=\"clear-fix\"><\/div>\n<p><a href=\"https:\/\/docs.sisus.co\/power-inspector\/attributes\/button\/\" 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":[26],"tags":[],"_links":{"self":[{"href":"https:\/\/docs.sisus.co\/power-inspector\/wp-json\/wp\/v2\/posts\/1525"}],"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=1525"}],"version-history":[{"count":3,"href":"https:\/\/docs.sisus.co\/power-inspector\/wp-json\/wp\/v2\/posts\/1525\/revisions"}],"predecessor-version":[{"id":1828,"href":"https:\/\/docs.sisus.co\/power-inspector\/wp-json\/wp\/v2\/posts\/1525\/revisions\/1828"}],"wp:attachment":[{"href":"https:\/\/docs.sisus.co\/power-inspector\/wp-json\/wp\/v2\/media?parent=1525"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.sisus.co\/power-inspector\/wp-json\/wp\/v2\/categories?post=1525"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.sisus.co\/power-inspector\/wp-json\/wp\/v2\/tags?post=1525"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}