Skip to content

VixCore Inspector Attributes

Namespace: VixCore.Inspector

These attributes are small editor helpers for MonoBehaviours and ScriptableObjects.

Button

Draws a button in the inspector that calls a parameterless method.

using UnityEngine;
using VixCore.Inspector;

public class DoorTester : MonoBehaviour
{
    [Button("Open Door")]
    private void OpenDoor()
    {
        Debug.Log("Opening door");
    }
}

The method must be parameterless and non-generic. Instance and static methods are supported.

Constructor:

ButtonAttribute(
    string label = null,
    ButtonVisibility visibility = ButtonVisibility.Always,
    ButtonPosition position = ButtonPosition.Bottom,
    int order = 0)

Visibility modes:

  • ButtonVisibility.Always
  • ButtonVisibility.EditorOnly
  • ButtonVisibility.PlayModeOnly
[Button("Respawn", ButtonVisibility.PlayModeOnly)]
private void Respawn()
{
}

Button positions:

  • ButtonPosition.Top
  • ButtonPosition.Bottom

Buttons are drawn at the bottom of the inspector by default. Use ButtonPosition.Top to draw a button before the default inspector fields.

[Button("Reset State", position: ButtonPosition.Top)]
private void ResetState()
{
}

Use order to sort buttons within the same position. Lower values are drawn first.

[Button("Bake", position: ButtonPosition.Top, order: -10)]
private void Bake()
{
}

[Button("Clear", position: ButtonPosition.Top, order: 10)]
private void Clear()
{
}

InspectorButtonAttribute still exists for old code, but it is obsolete. Use ButtonAttribute for new code.

Required

Shows an error when a field is null or empty.

[Required("Player transform is required.")]
[SerializeField] private Transform player;

Options:

  • AllowEmptyString
  • AllowEmptyCollection

ShowIf

Shows a field only when a bool field, property, or parameterless method returns true.

[SerializeField] private bool useCustomSpeed;

[ShowIf(nameof(useCustomSpeed))]
[SerializeField] private float customSpeed = 5f;

Use invert: true to show the field when the condition is false.

[ShowIf(nameof(useCustomSpeed), invert: true)]
[SerializeField] private float defaultSpeed = 3f;

ShowInEditMode and ShowInPlayMode

Shows a field only in the matching Unity mode.

[ShowInEditMode]
[SerializeField] private string editorOnlyNote;

[ShowInPlayMode]
[SerializeField] private float runtimeHealth;

InspectorReadOnly

Shows a field but prevents editing.

[InspectorReadOnly]
[SerializeField] private string generatedId;

Read-only modes:

  • ReadOnlyMode.Always
  • ReadOnlyMode.EditorOnly
  • ReadOnlyMode.PlayModeOnly

ProgressBar

Draws a progress bar for a float or int field.

With no constructor arguments, ProgressBar uses percentage style. The expected value range is 0 to 1.

[ProgressBar]
[SerializeField] private float healthPercent = 1f;

Use fixed min and max values for ranged values.

[ProgressBar(0f, 100f)]
[SerializeField] private int health = 75;

If the minimum value is 0, you can pass only the max value.

[ProgressBar(100f)]
[SerializeField] private int armor = 40;

The min and max values can also be read from named fields, properties, or parameterless methods on the same object.

[SerializeField] private int minHealth = 0;
[SerializeField] private int maxHealth = 100;

[ProgressBar(nameof(minHealth), nameof(maxHealth))]
[SerializeField] private int health = 75;

When the minimum is 0, pass only the max reference.

[SerializeField] private int maxAmmo = 30;

[ProgressBar(nameof(maxAmmo))]
[SerializeField] private int ammo = 12;

You can mix fixed values and references.

[SerializeField] private float staminaMax = 150f;

[ProgressBar(0f, nameof(staminaMax))]
[SerializeField] private float stamina = 90f;

Set Color to a basic color name or HTML color string to customize the progress bar fill.

[ProgressBar(100f, Color = "green")]
[SerializeField] private int health = 75;

[ProgressBar(100f, Color = "#4caf50")]
[SerializeField] private int stamina = 60;

InlineEditor

Draws an inline inspector for an assigned object reference.

[InlineEditor]
[SerializeField] private ScriptableObject settings;

The optional constructor argument controls the default foldout state.

[InlineEditor(defaultExpanded: false)]
[SerializeField] private ScriptableObject settings;

InlineEditor only works on object reference fields. The inline inspector is hidden when the reference is missing or mixed across multiple selected objects.

PathPicker

Draws a string field with a file or folder picker button.

[PathPicker]
[SerializeField] private string inputFile;

Modes:

  • PathPickerMode.OpenFile
  • PathPickerMode.SaveFile
  • PathPickerMode.Folder
[PathPicker(PathPickerMode.OpenFile, title: "Select Config", extension: "json", relativeToProject: true)]
[SerializeField] private string configPath;

[PathPicker(PathPickerMode.SaveFile, title: "Save Report", extension: "zip", defaultName: "report")]
[SerializeField] private string reportPath;

By default, selected paths are stored as absolute paths. Set relativeToProject: true to store paths inside the project folder relative to the project root.

FolderPicker

Shortcut for PathPickerMode.Folder.

[FolderPicker]
[SerializeField] private string outputFolder;

[FolderPicker(relativeToProject: true)]
[SerializeField] private string projectFolder;

Password

Draws a string field as a masked password field.

[Password]
[SerializeField] private string apiKey;

The value is still serialized as a normal string. This is for inspector display only, not secure secret storage.