# Useful Attributes

## **ConditionalHide**

This attribute allows to make your class field visible or invisible in inspector depending on value of another field.

### How to use:

Add ConditionalHide attribute in the next format:

`[ConditionalHide("conditionFieldName", hideInInspector, neededFieldValue)]`

The first parameter (conditionFieldName) is the name of class field that will be checked.

If second parameter is true, your conditional field will be hidden from inspector in case if checked field value equals to `neededFieldValue.` Otherwise, your field will be visible, but not editable in inspector.

#### Example #1:

```csharp
public class MyClass : MonoBehaviour
{
    [SerializeField] private bool firstField = false;
    [ConditionalHide("firstField", true, true)]
    [SerializeField] private int secondField;
}
```

In this case, `secondField` will be visible in inspector only if `firstField` value will be **true**.

<figure><img src="https://1131436974-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9rEHd0nHFvWCSkMEfAjl%2Fuploads%2FiOB2FKXtbH0FV5cdf78B%2Fimage.png?alt=media&#x26;token=b5db750f-031c-447e-b450-5474d6fd9e20" alt=""><figcaption><p>First field is false</p></figcaption></figure>

<figure><img src="https://1131436974-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9rEHd0nHFvWCSkMEfAjl%2Fuploads%2FJFzjmH7PGpAg6BjucnQV%2Fimage.png?alt=media&#x26;token=030ed38a-2b6b-43d2-b019-177a3e0488bb" alt=""><figcaption><p>First field is true</p></figcaption></figure>

#### Example #2

Let's change the second parameter in ConditionalHide attribute and see what happens.

```csharp
public class MyClass : MonoBehaviour
{
    [SerializeField] private bool firstField = false;
    //This time we just disable editing for secondField field
    [ConditionalHide("firstField", false, true)]
    [SerializeField] private int secondField;
}
```

As result, we can always see secondField in inspector, but it can be editable or not:

<figure><img src="https://1131436974-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9rEHd0nHFvWCSkMEfAjl%2Fuploads%2F6gCN0tOaugarZVSzGjrm%2Fimage.png?alt=media&#x26;token=a2334fa3-c671-4677-97d0-f679578d19d3" alt=""><figcaption><p>Second Field is locked for editing</p></figcaption></figure>

<figure><img src="https://1131436974-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9rEHd0nHFvWCSkMEfAjl%2Fuploads%2FnRZIZ524yXkrhlYDv62Q%2Fimage.png?alt=media&#x26;token=478368cc-0d73-4646-b218-2264b8ea8198" alt=""><figcaption><p>Second Field is unlocked for editing</p></figcaption></figure>

***

## ReadonlyField

This attribute makes class field not editable, but visible in inspector.

### How to use:

Add \[ReadonlyField] attribute to your class field. Good job, that's all!

#### Example:

```csharp
public class MyClass : MonoBehaviour
{
    //id field will be visible in inspector, but not editable
    [SerializeField] [ReadonlyField] private string id = "0123";
    [SerializeField] private int someNumber;
}
```

<figure><img src="https://1131436974-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F9rEHd0nHFvWCSkMEfAjl%2Fuploads%2FIsTP6jZYATcUjrwxyffd%2Fimage.png?alt=media&#x26;token=a3a5cfd9-9021-4fd7-af91-913c52b71116" alt=""><figcaption><p>[ReadonlyField] attribute blocks field editing in inspector</p></figcaption></figure>
