> For the complete documentation index, see [llms.txt](https://kubacho-lab.gitbook.io/vinspector2/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kubacho-lab.gitbook.io/vinspector2/attributes.md).

# Attributes

Attributes allow you to create and group UI elements in script inspector with a few lines of code<br>

Add this line to your script to use attributes:

```csharp
using VInspector;
```

## Buttons

Add \[Button] attribute before any function to create a button

{% code fullWidth="false" %}

```csharp
[Button]
public void SayHelloWorld()
{
    Debug.Log("Hello World!");
}
```

{% endcode %}

<div align="left"><figure><img src="/files/e7PMw4pMYDwoZlg4fltV" alt="" width="315"><figcaption></figcaption></figure></div>

You can customize button name, size and color:

```csharp
[Button("Custom name")]
public void RenamedButton() { }

[Button(size = 50, color = "red")]
public void BigRedButton() { }

```

## Foldouts

Add \[Foldout] before variables to group them into foldouts

```csharp
[Foldout("Floats")]
public float float1;
public float float2;
public float float3;

[Foldout("Ints")]
public int int1;
public int int2;
public int int3;

[Foldout("Strings")]
public string string1;
public string string2;
public string string3;

```

<div align="left"><figure><img src="/files/pPPG2HHeyJl6KUU8z9BL" alt=""><figcaption></figcaption></figure></div>

Use \[EndFoldout] to end foldout sections

```csharp
[Foldout("Floats")]
public float float1;
public float float2;
public float float3;

[Foldout("Ints")]
public int int1;
public int int2;
public int int3;

[Foldout("Strings")]
public string string1;
public string string2;
public string string3;
[EndFoldout]

public string string4;
public string string5;

```

<div align="left"><figure><img src="/files/zyjzgIyfNcpVomxoeZYD" alt=""><figcaption></figcaption></figure></div>

Foldouts can be nested

```csharp
[Foldout("Floats/Subfoldout 1")]
public float float1;

[Foldout("Floats/Subfoldout 2")]
public float float2;

[Foldout("Floats/Subfoldout 3")]
public float float3;

```

<div align="left"><figure><img src="/files/GLwuk3uByGCkMr8vMxUR" alt="" width="315"><figcaption></figcaption></figure></div>

<br>

And buttons can be put into foldouts

```csharp
[Foldout("Floats")]
[Button]
public void FloatsButton() { }
```

<div align="left"><figure><img src="/files/MWx0udSLMOo6oO7gEhhj" alt="" width="315"><figcaption></figcaption></figure></div>

## Tabs

Use \[Tab] to create tabs

```csharp
[Tab("Floats")]
public float float1;
public float float2;
public float float3;
public float float4;

[Tab("Ints")]
public int int1;
public int int2;
public int int3;

[Tab("Strings")]
public string string1;
public string string2;
public string string3;

```

<div align="left"><figure><img src="/files/hWJnrJTJifsFzX7bnMjh" alt=""><figcaption></figcaption></figure></div>

Use \[EndTab] to end tab sections, like \[EndFoldout] for foldouts\
\
Like foldouts, tabs can be nested and can contain buttons<br>

\
Show hidden variables
---------------------

Use \[ShowInInspector] to show any variable

```csharp
[ShowInInspector]
private float privateFloat;

[ShowInInspector]
static float staticFloat;

[ShowInInspector]
private float propertyFloat { get; }

```

<div align="left"><figure><img src="/files/b3uJGtURViHAHnOuXdP0" alt="" width="315"><figcaption></figcaption></figure></div>

\
Hide and disable variables
--------------------------

Use \[HideIf] and \[ShowIf] to hide variables depending on other variables

```csharp
public bool isBossLevel;

[HideIf("isBossLevel")]
public int waveCount;
public int enemyCount;
public int enemyStrength;

[ShowIf("isBossLevel")]
public float bossStrength;
public float bossStamina;
public float bossSpeed;
public float bossRegen;

```

<div align="center"><figure><img src="/files/0MVzH3JJJwIfZvRkkGsO" alt=""><figcaption></figcaption></figure></div>

Similarly, use \[DisableIf] and \[EnableIf] to disable variables

```csharp
public bool isBossLevel;

[DisableIf("isBossLevel")]
public int waveCount;
public int enemyCount;
public int enemyStrength;

[EnableIf("isBossLevel")]
public float bossStrength;
public float bossStamina;
public float bossSpeed;
public float bossRegen;

```

<div align="center"><figure><img src="/files/y6yQmhucT1LkXzjT4U5V" alt=""><figcaption></figcaption></figure></div>

Use \[EndIf] to end sections

```csharp
public bool isBossLevel;
    
[DisableIf("isBossLevel")]
public int waveCount;
public int enemyCount;
public int enemyStrength;

[EnableIf("isBossLevel")]
public float bossStrength;
public float bossStamina;
public float bossSpeed;
public float bossRegen;
[EndIf]

public float foo;
public float bar;

```

<div align="left"><figure><img src="/files/7IT12EOUqoKTBhdrvff8" alt="" width="319"><figcaption></figcaption></figure></div>

Variable types other than bool can also be used as conditions

```csharp
public enum LevelType { Normal, Boss }

public LevelType levelType;
    
[DisableIf("levelType", LevelType.Boss)]
public int waveCount;
public int enemyCount;
public int enemyStrength;

```

\
Range sliders
-------------

Use \[MinMaxSlider] on Vector2 or Vector2Int to create range sliders

```csharp
[MinMaxSlider(0, 2)]
public Vector2 widthRange;

[MinMaxSlider(0, 2)]
public Vector2 heightRange;

[MinMaxSlider(-180, 180)]
public Vector2 rotationRange;

```

<div align="left"><figure><img src="/files/dzdu3bq4KDadn5NbJbhd" alt="" width="316"><figcaption></figcaption></figure></div>

\
Variants
--------

Use \[Variants] to create variant selectors

```csharp
[Variants(512, 1024, 2048)]
public int resolution;

[Variants("png", "jpg", "raw")]
public string extension;

```

<div align="center"><figure><img src="/files/CGgJU0XOoY54XVWqf3lk" alt=""><figcaption></figcaption></figure></div>

\
Callback on change
------------------

Use \[OnValueChanged] to call a function when a variable is edited

```csharp
public int level;

[OnValueChanged("level")]
public void OnLevelChanged() { }

```

Multiple variables can be subscribed to at once

```csharp
public int level_player1;
public int level_player2;
public int level_player3;

[OnValueChanged("level_player1", "level_player2", "level_player3")]
public void OnLevelChanged() { }

```

\
Read-only variables
-------------------

Use \[ReadOnly] to make variables non-editable

```csharp
public int level;

[ReadOnly]
public int score;

[ReadOnly]
public int enemyCount;

```

<div align="left"><figure><img src="/files/TJdYH6bzXc4LQnANmAF7" alt="" width="315"><figcaption></figcaption></figure></div>

\
Static inspector
----------------

Static buttons and static variables with \[ShowInInspector] attribute will also appear on script asset

```csharp
[ShowInInspector]
static float staticFloat1;

[ShowInInspector]
static float staticFloat2;

[Button]
static void StaticButton() { }
```

![](/files/nHeRkS6Q9coL3e3m1Wc2)\
\
\
\
\ <br>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://kubacho-lab.gitbook.io/vinspector2/attributes.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
