InlineButton Attribute
Attribute to add a button next to a property.
- Parameters:
stringfunctionName: The name of the function the button activatesboolisRepetable: Makes the button repeat logic on holdoptional,
longpressDelay: How many milliseconds to wait before the logic is repeatedoptional,
longrepetitionInterval: The interval in milliseconds the logic will repeatoptional,
stringbuttonLabel: The label displayed on the buttonoptional,
floatbuttonWidth: The width of the button in pixelsoptional,
boolmakeDirty: Whether to mark the object as dirty after invoking the function
Example:
using UnityEngine;
using EditorAttributes;
public class AttributesExample : MonoBehaviour
{
[InlineButton(nameof(PrintString))]
[SerializeField] private string stringField;
[InlineButton(nameof(IncreaseValue), "+", 30f), InlineButton(nameof(DecreaseValue), "-", 30f)]
[SerializeField] private int intField;
private void IncreaseValue() => intField++;
private void DecreaseValue() => intField--;
private void PrintString() => print(stringField);
}
You can make a button to keep executing on hold by marking it as repetable:
using System;
using UnityEngine;
using EditorAttributes;
public class AttributesExample : MonoBehaviour
{
[InlineButton(nameof(Add10), true, buttonLabel: "+10")]
[SerializeField] private int intField;
[InlineButton(nameof(GenerateGUID), true, 100, 500)]
[SerializeField] private string stringField;
public void Add10() => intField += 10;
public void GenerateGUID() => stringField = Guid.NewGuid().ToString();
}
Note
The attribute won’t work well inside data tables