{"id":1553,"date":"2019-11-25T19:54:19","date_gmt":"2019-11-25T19:54:19","guid":{"rendered":"https:\/\/docs.sisus.co\/power-inspector\/?p=1553"},"modified":"2021-03-24T17:52:21","modified_gmt":"2021-03-24T17:52:21","slug":"showif","status":"publish","type":"post","link":"https:\/\/docs.sisus.co\/power-inspector\/attributes\/showif\/","title":{"rendered":"ShowIf"},"content":{"rendered":"<p>Attribute that can be used to make class member that follows the attribute only be shown in the inspector when a predicate statement is true.<\/p>\n<h2>ShowIf(string classMemberName, object requiredValue)<\/h2>\n<p>When this constructor is used, the target is only shown if the class member with the given name has the specified value.<\/p>\n<h2>ShowIf(string classMemberName, Is comparison, object requiredValue)<\/h2>\n<p>When this constructor is used, the target is only shown if the class member with the given name passes the comparison check against the specified value.<\/p>\n<h2>ShowIf(string classMemberName, string comparison, object requiredValue)<\/h2>\n<p>When this constructor is used, the target is only shown if the class member with the given name passes the comparison check against the specified value.<br \/>\nAccepted comparison values are: <strong>==<\/strong>, <strong>!=<\/strong>, <strong>&lt;<\/strong>, <strong>&gt;<\/strong>, <strong>&lt;=<\/strong> and <strong>&gt;=<\/strong>. They mean <strong>equal<\/strong>, <strong>not<\/strong> <strong>equal<\/strong>, <strong>smaller than<\/strong>, <strong>larger than<\/strong>, <strong>smaller than or equal to<\/strong> and <strong>larger than or equal to<\/strong> respectively.<\/p>\n<h2>ShowIf(string booleanExpression)<\/h2>\n<p>When this constructor is used, the target is only shown if the boolean expression is true.<br \/>\nWith this constructor it is possible to evaluate expressions containing multiple parts and containing conjunctions and parentheses.<br \/>\nSupported conjunctions are <strong>&amp;<\/strong> (<strong>and<\/strong>) and <strong>|<\/strong> (<strong>or<\/strong>).<\/p>\n<h2>Attribute Target<\/h2>\n<p>Field, property, method or indexer.<\/p>\n<h2>Example 1<\/h2>\n<pre>using UnityEngine;\r\nusing Sisus.Attributes;\r\n\r\npublic class HideAndSeek : MonoBehaviour\r\n{\r\n\tpublic bool foundYou;\r\n\t\t\r\n\t[ShowIf(nameof(foundYou), true)]\r\n\tprivate void Hide()\r\n\t{\r\n\t\tfoundYou = false;\r\n\t}\r\n}<\/pre>\n<h2>Example 1 Result<\/h2>\n<p><img loading=\"lazy\" class=\"alignnone size-full wp-image-1555\" src=\"https:\/\/docs.sisus.co\/power-inspector\/wp-content\/uploads\/2019\/11\/Inspector-ShowIf-attribute-not-shown.png\" alt=\"\" width=\"291\" height=\"44\" \/> \u00a0 <img loading=\"lazy\" class=\"alignnone size-full wp-image-1554\" src=\"https:\/\/docs.sisus.co\/power-inspector\/wp-content\/uploads\/2019\/11\/Inspector-ShowIf-attribute.png\" alt=\"\" width=\"291\" height=\"62\" \/><\/p>\n<h2>Example 2<\/h2>\n<pre>using UnityEngine;\r\nusing Sisus.Attributes;\r\n\r\npublic class NothingToSeeHere : MonoBehaviour\r\n{\r\n\tpublic bool f;\r\n\tpublic bool u;\r\n\tpublic bool n;\r\n\tpublic bool c;\r\n\tpublic bool k;\r\n\tpublic bool y;\r\n\tpublic bool h;\r\n\tpublic bool o;\r\n\tpublic bool v;\r\n\tpublic bool e;\r\n\tpublic bool r;\r\n\r\n\t[ReadOnly, ShowIf(\"f|u|n|c|k|y|h|o|v|e|r\")]\r\n\tprivate string selectedLetters;\r\n\r\n\t[ReadOnly, ShowIf(\"u &amp; n &amp; c &amp; o &amp; v &amp; e &amp; r &amp; !f &amp; !k &amp; !y &amp; !h\")]\r\n\tprivate void SecretButton()\r\n\t{\r\n\t\tDebug.Log(\"Congratulations! You found the secret button!\");\r\n\t}\r\n\r\n\tprivate void OnValidate()\r\n\t{\r\n\t\tselectedLetters = \"\";\r\n\t\tforeach(var field in GetType().GetFields())\r\n\t\t{\r\n\t\t\tif((bool)field.GetValue(this))\r\n\t\t\t{\r\n\t\t\t\tselectedLetters += char.ToUpper(field.Name[0]);\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}<\/pre>\n<h2>Example 2 Result<\/h2>\n<p><img loading=\"lazy\" class=\"alignnone size-full wp-image-1560\" src=\"https:\/\/docs.sisus.co\/power-inspector\/wp-content\/uploads\/2019\/11\/unity-showif-multiple-expression-not-shown.png\" alt=\"\" width=\"282\" height=\"224\" \/>\u00a0 \u00a0<img loading=\"lazy\" class=\"alignnone size-full wp-image-1559\" src=\"https:\/\/docs.sisus.co\/power-inspector\/wp-content\/uploads\/2019\/11\/unity-showif-multiple-expression.png\" alt=\"\" width=\"282\" height=\"260\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Attribute that can be used to make class member that follows the attribute only be shown in the inspector when a predicate statement is true. ShowIf(string classMemberName, object requiredValue) When this constructor is used, the target is only shown if the class member with the given name has the specified value. ShowIf(string classMemberName, Is comparison, ..<\/p>\n<div class=\"clear-fix\"><\/div>\n<p><a href=\"https:\/\/docs.sisus.co\/power-inspector\/attributes\/showif\/\" 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\/1553"}],"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=1553"}],"version-history":[{"count":7,"href":"https:\/\/docs.sisus.co\/power-inspector\/wp-json\/wp\/v2\/posts\/1553\/revisions"}],"predecessor-version":[{"id":1842,"href":"https:\/\/docs.sisus.co\/power-inspector\/wp-json\/wp\/v2\/posts\/1553\/revisions\/1842"}],"wp:attachment":[{"href":"https:\/\/docs.sisus.co\/power-inspector\/wp-json\/wp\/v2\/media?parent=1553"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.sisus.co\/power-inspector\/wp-json\/wp\/v2\/categories?post=1553"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.sisus.co\/power-inspector\/wp-json\/wp\/v2\/tags?post=1553"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}