Logo
Navigation

Selection Box

A visual indicator that automatically follows selected UI objects via EventSystem

Overview

Selection Box is an animated visual indicator that automatically tracks and highlights the currently selected UI element in your canvas. It responds to Unity's EventSystem selection changes, smoothly animating position, size, fade effects, and appearance with customizable curves and override settings.

The component handles automatic detection of selected objects, smooth animated transitions, fade in/out effects, per-object appearance customization via SelectionBoxOverride, and continuous tracking of moving UI elements.

Preview

Usage

Create a UI object in your canvas for the selection box

Add Selection Box component

Configure animation settings:

  • Animation Duration for movement speed
  • Animation Curve for easing
  • Fade Duration for visibility transitions

Set default appearance:

  • Default Offset for padding around selected objects
  • Default Sprite for the box visual
  • Default Color for tinting

Optionally enable Only Override Objects to restrict selection tracking

The selection box will automatically follow EventSystem selection changes


Properties

Animation Settings

FieldTypeDescription
animationDurationfloatDuration of the movement and resize animation
animationCurveAnimationCurveAnimation curve for position and size transitions
fadeDurationfloatDuration of the fade in/out animation

Default Appearance

FieldTypeDescription
defaultOffsetVector2Default offset from the selected object's edges
defaultSpriteSpriteDefault sprite/texture for the selection box
defaultColorColorDefault color for the selection box
pixelsPerUnitMultiplierfloatPixels per unit multiplier for sliced images

Detection Settings

FieldTypeDescription
onlyOverrideObjectsboolIf true, only objects with SelectionBoxOverride component will be selectable

Public Methods

NameParametersDescription
SelectObject(RectTransform target)RectTransformManually select a UI object and move the selection box to it
Deselect()NoneDeselect and hide the selection box
GetCurrentTarget()NoneReturns the currently selected RectTransform
SetOnlyOverrideObjects(bool value)boolSet whether to only select objects with SelectionBoxOverride component

Override Component

Add SelectionBoxOverride component to individual UI elements to customize how the selection box appears when they are selected.

Properties

FieldTypeDescription
OffsetVector2Custom offset for this object
OverrideSpriteSpriteCustom sprite to use when this object is selected
OverrideColorboolWhether to override the color
ColorColorCustom color when overriding
OverridePPUboolWhether to override pixels per unit multiplier
PixelsPerUnitMultiplierfloatCustom PPU multiplier when overriding

Code Example

SelectionBoxExample.cs
using UnityEngine;
using Evo.UI;

public class SelectionBoxExample : MonoBehaviour
{
    public SelectionBox selectionBox;
    public RectTransform customButton;

    void Start()
    {
        // Configure selection box behavior
        selectionBox.SetOnlyOverrideObjects(false);
    }

    public void SelectCustomButton()
    {
        // Manually select a specific UI element
        selectionBox.SelectObject(customButton);
    }

    public void ClearSelection()
    {
        // Hide the selection box
        selectionBox.Deselect();
    }

    public void CheckCurrentSelection()
    {
        // Get the currently selected target
        RectTransform current = selectionBox.GetCurrentTarget();
        
        if (current != null)
        {
            Debug.Log("Currently selected: " + current.name);
        }
        else
        {
            Debug.Log("No object selected");
        }
    }

    void Update()
    {
        // Example: Press Tab to clear selection
        if (Input.GetKeyDown(KeyCode.Tab))
        {
            selectionBox.Deselect();
        }
    }
}

On this page