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
| Name | Type | Description |
|---|---|---|
isDraggable | bool | Enables dragging. |
axisConstraint | AxisConstraint | Free, HorizontalOnly, or VerticalOnly movement. |
boundaryType | BoundaryType | NoBounds, ScreenBounds, or RectBounds. |
boundaryRect | RectTransform | Reference for RectBounds. |
dragSources | List<RectTransform> | Additional RectTransforms that initiate dragging. |
Methods
| Name | Parameters | Description |
|---|---|---|
ResetToOriginalPosition() | None | Animates back to the captured position. |
StopDrag() | None | Ends an active drag. |
Events
| Name | Type | Description |
|---|---|---|
OnDragUpdate | Action<Vector2> | C# callback carrying the drag position. |
OnDragEnd | Action | C# callback when dragging ends. |
Example
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");
}
}