Welcome,
Guest
. Please
login
or
register
.
May 13, 2026, 09:46:11 PM
Home
Help
Search
Login
Register
Tasharen Entertainment Forum
»
Support
»
NGUI 3 Support
»
How to get UI coordinate in WorldSpace?
« previous
next »
Print
Pages: [
1
]
Author
Topic: How to get UI coordinate in WorldSpace? (Read 8699 times)
Shifty Geezer
Full Member
Thank You
-Given: 7
-Receive: 9
Posts: 226
How to get UI coordinate in WorldSpace?
«
on:
September 07, 2016, 03:00:55 PM »
I'm wanting to measure the worldspace distance between a transform and a dragged NGUI widget.
void
OnDragStart
(
)
{
if
(
CanBeDragged
)
{
dragPos
=
transform
.
localPosition
;
isDragging
=
true
;
}
}
void
OnDrag
(
Vector2 delta
)
{
if
(
isDragging
)
{
dragPos
+=
(
Vector3
)
(
delta
*
uiRoot
.
pixelSizeAdjustment
)
;
dragWorldPos
=
Camera
.
main
.
ScreenToWorldPoint
(
dragPos
)
;
print
(
"dragpos "
+
dragPos
+
" worldposs "
+
dragWorldPos
+
" transpos "
+
targetTrans
.
position
+
" mag "
+
(
targetTrans
.
position
-
dragWorldPos
)
.
sqrMagnitude
)
;
}
}
sqrMagnitude should decrease towards zero as the widget is dragged over towards the target object, but there's an offset. dragWorldPos isn't the correct world coordinates.
Logged
devomage
Sr. Member
Thank You
-Given: 7
-Receive: 67
Posts: 250
Re: How to get UI coordinate in WorldSpace?
«
Reply #1 on:
September 07, 2016, 04:37:24 PM »
try using something like this:
(i use this to calculate the distance of a row in a grid/table)
Vector2 size
=
NGUIMath
.
CalculateRelativeWidgetBounds
(
t,
true
)
.
size
;
Vector3 point
=
scrollview
.
transform
.
InverseTransformPoint
(
t
.
FindChild
(
"Sprite"
)
.
position
)
;
float
amount
=
Mathf
.
Round
(
point
.
y
-
scrollview
.
panel
.
localCorners
[
0
]
.
y
-
size
.
y
-
table
.
padding
.
y
*
2
)
;
Logged
Shifty Geezer
Full Member
Thank You
-Given: 7
-Receive: 9
Posts: 226
Re: How to get UI coordinate in WorldSpace?
«
Reply #2 on:
September 08, 2016, 03:06:47 AM »
Isn't that working in screen space coordinates?
My specific requirement is to see if a drag is within range (world space) of a gameObject's skill, and to cap the distance from the gameObject of the widget based on skill range.
Logged
ArenMook
Administrator
Hero Member
Thank You
-Given: 337
-Receive: 1171
Posts: 22,128
Toronto, Canada
Re: How to get UI coordinate in WorldSpace?
«
Reply #3 on:
September 09, 2016, 02:35:33 PM »
Check UIScrollView.Drag(). A plane is created, a ray is cast into it using the screen point's position. This gets you a 3D position on the plane of the widget.
Logged
Print
Pages: [
1
]
« previous
next »
Tasharen Entertainment Forum
»
Support
»
NGUI 3 Support
»
How to get UI coordinate in WorldSpace?