Logo
UI Elements

Quantity Selector

An interactive numeric input with animated transitions

Overview

Quantity Selector provides an intuitive way to adjust numeric values with increment and decrement buttons. It features smooth slide animations when values change, automatic button state management based on min/max bounds, and supports both button clicks and direct text input for maximum flexibility.

Preview

Properties

Settings

NameTypeDescription
startQuantityintInitial value when component starts
minQuantityintMinimum allowed value
maxQuantityintMaximum allowed value

Animation

NameTypeDescription
slideOffsetfloatDistance text slides during transitions
animationDurationfloatTotal time for slide animation
animationCurveAnimationCurveCurve for easing transitions

References

NameTypeDescription
inputFieldTMP_InputFieldText input for displaying and editing quantity
increaseButtonButtonButton for incrementing value
decreaseButtonButtonButton for decrementing value

Events

NameTypeDescription
onValueChangedUnityEvent<int>Fired when quantity changes

Public Methods

NameParametersDescription
Increase()NoneIncrements value by 1 with animation
Decrease()NoneDecrements value by 1 with animation
SetQuantity(value, animate)int, boolSets quantity with optional animation
SetQuantity(value)intSets quantity with animation

Code Example

QuantitySelectorExample.cs
using UnityEngine;
using Evo.UI;

public class QuantitySelectorExample : MonoBehaviour
{
    public QuantitySelector productQuantity;

    void Start()
    {
        // Configure range
        productQuantity.minQuantity = 1;
        productQuantity.maxQuantity = 99;

        // Listen for changes
        productQuantity.onValueChanged.AddListener(quantity =>
        {
            Debug.Log($"Quantity changed to: {quantity}");
            UpdatePrice(quantity);
        });

        // Set quantity programmatically
        productQuantity.SetQuantity(5);

        // Get current value
        int currentQty = productQuantity.CurrentQuantity;
        Debug.Log($"Current quantity: {currentQty}");

        // Control without animation
        productQuantity.SetQuantity(10, false);
    }

    void UpdatePrice(int quantity)
    {
        float pricePerUnit = 9.99f;
        float totalPrice = quantity * pricePerUnit;
        Debug.Log($"Total: ${totalPrice:F2}");
    }
}

On this page