
使用 RectTransformUtilityScreenPointToLocalPointInRectangle 方法。
public Vector2 CurrMousePosition(Transform thisTrans)
{
Vector2 vecMouse;
RectTransform parentRectTrans = thisTransparentGetComponent<RectTransform>();
RectTransformUtilityScreenPointToLocalPointInRectangle(parentRectTrans, InputmousePosition, UICamera, out vecMouse);
return vecMouse;
}
Unity 是实时3D互动内容创作和运营平台 。包括游戏开发、美术、建筑、汽车设计、影视在内的所有创作者,借助Unity将创意变成现实。 Unity平台提供一整套完善的软件解决方案,可用于创作、运营和变现任何实时互动的2D和3D内容,支持平台包括手机、平板电脑、PC、游戏主机、增强现实和虚拟现实设备。
看到你的问题补充就不知道你想要写成什么样子的了。
给你两段代码把。
'坐标显示在Text1,Text2
'建一个Timer1,Text1,Text2
'代码如下。
'============
Private Type POINTAPI
x As Long
y As Long
End Type
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Dim p As POINTAPI
Private Sub Form_Load()
Timer1Interval = 10
End Sub
Private Sub Timer1_Timer()
GetCursorPos p
Text1Text = px
Text2Text = py
End Sub
二、获取鼠标在窗体内的坐标
'坐标显示在标题上
'运行此程序需要再窗体添加控件Timer
Option Explicit
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private Declare Function ScreenToClient Lib "user32" (ByVal hwnd As Long, lpPoint As POINTAPI) As Long
Private Type POINTAPI
x As Long
y As Long
End Type
Private Sub Form_Load()
Timer1Interval = 10 '设置获取鼠标坐标间隔
End Sub
Private Sub Timer1_Timer()
Dim P As POINTAPI
GetCursorPos P '获取鼠标在屏幕中的位置
ScreenToClient Mehwnd, P '转换为本窗体的坐标
Dim t As Boolean
t = Px >= 0 And Py >= 0 And Px < MeWidth / ScreenTwipsPerPixelX And Py <= MeHeight / ScreenTwipsPerPixelY
If t Then MeCaption = "x=" & Px & "y=" & Py '按像素显示坐标
'If t Then MeCaption = "x=" & Px ScreenTwipsPerPixelX & "y=" & Py ScreenTwipsPerPixelY '按缇显示坐标
End Sub
Point p = CursorPosition;
pX; //当前X坐标
pY; //当前Y坐标
以上代码在任意地方执行,就可取得鼠标在屏幕上的X Y坐标。
以上就是关于Unity UGUI怎么样获得UI在屏幕上的位置坐标全部的内容,包括:Unity UGUI怎么样获得UI在屏幕上的位置坐标、vb 获取鼠标在窗口内的屏幕坐标、如何获得当前鼠标的屏幕坐标(c#)等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)