(Unity coord system appears to be extraordinarily complicated and documentation is ineffective.)
For instance, I wish to implement a easy drag in 2D UI.
- So I wish to deal with the drag in ancestor coord, after which convert again to dragging object.
The issue is, what positional information ought to I get/set from the dragging object?
// If utilizing anchorPosition is improper, then what ought to I exploit?
startObjectPositionInAncestor = dragRectT.anchorPosition;
...
// The place in ancestor works as anticipated.
RectTransformUtility.ScreenPointToLocalPointInRectangle(ancestorRectT, screenInputPoint, canvas.worldCamera, out Vector2 pointInAncestor);
var newPositionInAncestor = (pointInAncestor - startPointInAncestor) + startObjectPositionInAncestor;
// Now the way to map the place to youngster object underneath drag?
// Beneath doesn't work: place is flickering.
// dragRectT.anchorPosition = dragRectT.InverseTransformPoint(ancestorRectT.TransformPoint(newPositionInAncestor)));
dragRectT.anchorPosition = ???
// Or utilizing anchorPosition is improper, then what ought to I exploit?
- What’s the appropriate option to contrain drag place?
e.g. I wish to clamp drag area to ancestor rectangular sure. (In order that mouse can transfer past sure, however drag object stops at sure)
// Beneath doesn't work: the clamp area is displaced from the visible area.
// newPoint.x = Mathf.Clamp(pointInAncestor.x, ancestorRectT.rect.xMin, ancestorRectT.rect.xMax);
// newPoint.y = Mathf.Clamp(pointInAncestor.y, ancestorRectT.rect.yMin, ancestorRectT.rect.yMax);
Notice:
I’m modding so I can’t reproduce it in editor or present screenshot of object properties in editor.