UGTK / Toolkit / Ui Module / Area Handles System Completed
Area Handles System
Summary
The Area Handles System is a rectangle the player can move and resize by dragging its corner handles,
with an optional locked aspect ratio and a live readout of its width and height.
It is the crop tool: pick an area of a photo, frame a screenshot, choose the portion of an image to upload. Everything happens at runtime, in the built game — this is not an editor gizmo.
Content
Modules Dependencies
None. Two components that only use UnityEngine.EventSystems.
Setup
- Place the
AreaHandlerprefab under the canvas, over what has to be framed. - Set its starting position and size from the
RectTransform— the area starts exactly there. - If the selection has to keep a fixed shape, turn on the aspect lock and set the ratio.
There is no GIF for the setup: it is a single prefab drop with no configuration beyond the RectTransform.
How To Use
- Move: drag the body of the area. It needs something raycastable underneath — a fully transparent
Image still works as long as
Raycast Targetis on, but an area with no Graphic at all cannot be grabbed. This is the most common reason "the area does not move". - Resize: drag one of the corner handles.
From code:
area.SetCanEdit(false); // freeze the selection once confirmed
area.SetKeepAspect(true);
area.SetLockedAspectRatio(16f / 9f); // width / height
string w = area.GetWidthText(); // already formatted for a label
string h = area.GetHeightText();
Good to know:
SetCanEdit(false)is the way to lock it, not disabling the component: the area keeps its look and its readout, it simply stops responding to drags.- The ratio is width / height:
1is a square,1.777…is 16:9,0.5625is 9:16. Setting it while the lock is off changes nothing until you turn the lock on. - It needs an
EventSystemin the scene and aGraphic Raycasteron the canvas, like any draggable UI. Without them nothing responds and nothing warns you. - The size readout is a string, already formatted: use it for the label, and read the
RectTransformif you need the numbers. - The area is not clamped to its parent: it can be dragged partly outside. Constrain it yourself if the selection must stay inside the image.
Testing Scene
Open Debug/AreaHandlesTest.unity and press Play: the area can be moved and resized, with and without
the aspect lock.
Technical Info
| Path | Content |
|---|---|
Scripts/Runtime/Mn_ResizableArea.cs |
The area: move and resize, aspect lock, size readout, SetCanEdit |
Scripts/Runtime/Mn_AnchorHandles.cs |
One corner handle: reports its index and the drag delta to the area |
Scripts/Editor/Mn_ResizableArea_Editor.cs |
Custom inspector |
Prefabs/AreaHandler.prefab |
The ready-made area with its four handles |
Debug/AreaHandlesTest.unity |
Test scene |
© 2026 Marcello De Bonis. All rights reserved
UGTKengine within an engine


