Logo
UI Elements

Button

A feature rich button built on top of Interactive base

Overview

Button extends Interactive and provides a complete UI button solution with icon support, text rendering, adaptive layout, and double click handling. It manages Sprite + Text combinations, dynamic layout sizing, and integrates fully with Interactive's ripple, trail, audio, and state systems.

Preview


Customization

Content

By default, the icon and text are set through the inspector so you can edit them easily. If you want to manage the content manually, enable the Use Custom Content option in the button settings.

Dynamic Scale

Buttons automatically adjust their size based on the content. If you prefer to control the size yourself, you can disable the Dynamic Scale option.

Transition Effects

Interactive components support state based transitions through the Styler Object system. This includes color changes on hover, click, and other interactions. For more information, see the Styler page.

Interactive Features

As a child of Interactive, Button supports:

  • Interaction states
  • Ripple and trail effects
  • Audio styling
  • Highlight, pressed, and selected transitions

For more information, see the Interactive page.


Properties

Content

NameTypeDescription
enableIconboolShows or hides the icon
iconSpriteSprite used for the icon
iconSizefloatPreferred size for the icon
enableTextboolEnables or disables the text label
textstringDisplayed button label
textSizefloatFont size of the label

Layout

NameTypeDescription
dynamicScaleboolUses ContentSizeFitter and LayoutGroup to auto size
reverseArrangementboolFlips the order of icon and text
spacingintSpace between icon and text
paddingRectOffsetPadding applied by the layout group

Settings

NameTypeDescription
interactableboolEnables or disables Selectable interaction
interactionStateInteractionStateCurrent visual interaction state of the button
transitionDurationfloatTime used when fading between CanvasGroup states
customContentboolEnables manual setup, skipping automatic icon/text logic
allowDoubleClickboolEnables double click event
doubleClickDurationfloatTime window for second click detection

References

NameTypeDescription
imageObjectImageIcon renderer
iconElementLayoutElementLayout sizing for icon
textObjectTMP_TextLabel text
textContainerRectTransformParent container for text
contentFitterContentSizeFitterAutomatic layout scaling
contentLayoutHorizontalLayoutGroupManages icon/text horizontal layout

Visual Effects

NameTypeDescription
enableRippleboolEnables ripple feedback on pointer down or submit
rippleParentRectTransformParent used when spawning ripple instances
ripplePresetRipple.PresetPreset that defines ripple shape, color, size, and timing
enableTrailboolEnables pointer trail while hovering the button
trailParentRectTransformParent used when spawning trail handlers
trailPresetPointerTrail.PresetPreset that defines trail shape, color, scale, and fade settings

Sound Effects

NameTypeDescription
sfxSourceStylingSourceDefines how audio clips are resolved (for example from Styler presets)
stylerPresetStylerPresetPreset used by Styler to fetch audio and styling data
highlightedSFXAudioMappingAudio mapping used when the button becomes highlighted or hovered
pressedSFXAudioMappingAudio mapping used when the button is pressed or submitted
selectedSFXAudioMappingAudio mapping used when entering the Selected state

Events

NameTypeDescription
onClickUnityEventFired on pointer click or submit
onPointerDownUnityEventFired when pointer is pressed
onPointerUpUnityEventFired when pointer is released
onDoubleClickUnityEventFired when double click logic is triggered
onPointerEnterUnityEventFired on hover start
onPointerExitUnityEventFired on hover exit
onSelectUnityEventFired when element is selected
onDeselectUnityEventFired when element is deselected
onSubmitUnityEventFired when submit is performed (keyboard/controllers)

Public Methods

NameParametersDescription
UpdateUI()NoneRefreshes icon, text, and layout
UpdateLayout()NoneRefreshes layout group values
SetIcon(newIcon)SpriteUpdates icon sprite and layout behavior
SetText(newText)stringUpdates label text and font size
SetState(state, instant)InteractionState, boolSets new interaction state with optional instant transition
SetInteractable(value)boolToggles interactable and updates visuals

Code Example

ButtonExample.cs
using UnityEngine;
using Evo.UI;

public class ButtonExample : MonoBehaviour
{
    public Button myButton;

    void Start()
    {
        // Button visuals
        myButton.enableIcon = true;
        myButton.iconSize = 32f;
        myButton.SetIcon(someSprite);

        myButton.enableText = true;
        myButton.textSize = 26f;
        myButton.SetText("Play");

        // Layout settings
        myButton.dynamicScale = true;
        myButton.spacing = 10;
        myButton.reverseArrangement = false;

        // Update layout changes
        myButton.UpdateLayout();

        // Force update UI changes - no need to be called with SetIcon, SetText
        myButton.UpdateUI();

        // Double click optional
        myButton.allowDoubleClick = true;

        // Interactive effects
        myButton.enableRipple = true;
        myButton.enableTrail = true;

        // Add event listeners
        myButton.onClick.AddListener(() =>
        {
            Debug.Log("Button clicked!");
        });

        myButton.onDoubleClick.AddListener(() =>
        {
            Debug.Log("Button double clicked!");
        });

        // Set button state
        myButton.SetState(InteractionState.Normal);

        // Set interactable state
        myButton.SetInteractable(true);
    }
}

On this page