Logo
UI Elements

Button

Buttons with text, icons, adaptive sizing, and interaction feedback

Overview

Button combines a text label and an optional icon with Interactive feedback. Use it for menu actions, toolbar items, and any control that needs a click or submit event.

Preview

Usage

Create a Button from Evo UI’s Create menu. The prefab includes the content and layout references.

Set Text and Icon, then choose which parts to display.

Add your action to On Click. Keyboard and controller submit use the same action.

Enable Allow Double Click only when you need a separate double-click response.


Customization

Content and Layout

Dynamic Scale sizes the button around its content. Turn it off when a parent layout group owns the button’s size. Padding, Spacing, and Reverse Arrangement control the icon and text layout.

Content controls edit the referenced Image, text, and layout components directly. The label can use any text provider.

Effects

Ripple, spotlight, border glow, sound, and cursor feedback are provided through Interactive. All of these can be enabled, disabled, or customized through the Inspector or the public API.

Double Clicks

Allow Double Click adds a response to two left clicks within Double Click Duration. Each click still invokes On Click; the second also invokes On Double Click. Keep this in mind when assigning actions to both events. Timing uses unscaled time.


Public API

Use Button in the Evo.UI namespace.

Properties

NameTypeDescription
TextstringDisplayed label. Setting it shows the label; an empty or blank value hides it.
IconSpriteSprite displayed beside the label. Setting it shows the icon; null hides it.
EnableTextboolShows or hides the label.
EnableIconboolShows or hides the icon.
TextSizefloatLabel font size, clamped to zero or greater.
IconSizefloatPreferred icon width and height, clamped to zero or greater.
DynamicScaleboolLets the content determine the button size.
ReverseArrangementboolReverses the icon and text order.
SpacingintSpace between the icon and label.
PaddingRectOffsetPadding applied to the content layout.
AllowDoubleClickboolEnables double-click detection.
DoubleClickDurationfloatTime window for the second click, clamped to 0.1–1 seconds.

Fields

NameTypeDescription
imageObjectUnityEngine.UI.ImageImage used for the icon.
textObjectGraphicText component used for the label, from any text provider.

Inherited API

onClick, onDoubleClick, SetInteractable(bool), and SetState(InteractionState, bool) come from Interactive.

Example

ButtonExample.cs
using UnityEngine;
using Evo.UI;

public class ButtonExample : MonoBehaviour
{
    [SerializeField] private Button target;
    [SerializeField] private Sprite playIcon;

    private void Start()
    {
        target.Text = "Play";
        target.Icon = playIcon; // Hidden when playIcon is null.
        target.Padding = new RectOffset(24, 24, 12, 12);
        target.onClick.AddListener(Play);
    }

    private void Play()
    {
        target.Text = "Loading...";
        target.SetInteractable(false); // Prevent another click while loading.
        Debug.Log("Start loading the game here.");
    }

    private void OnDestroy()
    {
        if (target != null)
            target.onClick.RemoveListener(Play);
    }
}

On this page