Logo
Layout

Rect Dragger

Drag a UI rectangle within optional bounds

Overview

Rect Dragger makes a UI rectangle movable. It can constrain movement to one axis and return the object to its original position.


Usage

Add Rect Dragger to the object you want to move.

Choose the allowed axes.

Select no bounds, screen bounds, or a specific rectangle.

Add drag sources when only part of the object, such as a title bar, should start dragging.


Tips

  • Allow Out Of Bounds and boundary settings control movement limits.
  • A parent layout group can reposition children and conflict with manual dragging. Use a separate draggable container when layout needs to remain in control of the content.

Public API

Use RectDragger in the Evo.UI namespace.

Fields

NameTypeDescription
isDraggableboolEnables dragging.
axisConstraintAxisConstraintFree, HorizontalOnly, or VerticalOnly movement.
boundaryTypeBoundaryTypeNoBounds, ScreenBounds, or RectBounds.
boundaryRectRectTransformReference for RectBounds.
dragSourcesList<RectTransform>Additional RectTransforms that initiate dragging.

Methods

NameParametersDescription
ResetToOriginalPosition()NoneAnimates back to the captured position.
StopDrag()NoneEnds an active drag.

Events

NameTypeDescription
OnDragUpdateAction<Vector2>C# callback carrying the drag position.
OnDragEndActionC# callback when dragging ends.

Example

RectDraggerExample.cs
using UnityEngine;
using Evo.UI;

public class RectDraggerExample : MonoBehaviour
{
    [SerializeField] private RectDragger target;

    private void Start()
    {
        target.axisConstraint = RectDragger.AxisConstraint.HorizontalOnly;
        target.OnDragEnd += () => Debug.Log("Drag finished");
    }
}

On this page