UE5 小知识点 —— 10 - 鼠标操作
目录
一、获取鼠标位置
1.1 Get Mouse Position on Platform
1.2 Get Mouse Position on Viewport(使用较多)
1.3 Get Player Controller —— Get Mouse Position
1.4 Get Player Controller —— Get Mouse Position Scaled by DPI
二、鼠标进入/离开/移动(控件)
2.1 On Mouse Move 函数
2.2 On Mouse Enter 事件
2.3 On Mouse Leave 事件
三、鼠标点击/拖拽/释放(控件)
一、获取鼠标位置
本人电脑的屏幕分辨率为(2560,1600),下面介绍四种方法:
1.1 Get Mouse Position on Platform
返回整个屏幕的鼠标坐标,单位为屏幕像素。
屏幕左上角为(0,0),屏幕右下角为(2560,1600)。
1.2 Get Mouse Position on Viewport(使用较多)
返回整个屏幕的鼠标坐标,单位为屏幕像素 / DPI Scale。
游戏窗口左上角为(0,0)。
1.3 Get Player Controller —— Get Mouse Position
返回游戏窗口的鼠标坐标,单位为屏幕像素。
在 On Drag Cancelled 事件下是获取不到鼠标坐标的。
1.4 Get Player Controller —— Get Mouse Position Scaled by DPI
返回游戏窗口的鼠标坐标,单位为屏幕像素 / DPI Scale。
在 On Drag Cancelled 事件下是获取不到鼠标坐标的。
二、鼠标进入/离开/移动(控件)
2.1 On Mouse Move 函数
鼠标在控件上移动时,每帧都会触发。
2.2 On Mouse Enter 事件
鼠标进入控件时,触发一次。
2.3 On Mouse Leave 事件
鼠标离开控件时,触发一次。
三、鼠标点击/拖拽/释放(控件)
On Mouse Button Down 函数
On Drag Detected 函数
On Drop 函数、On Drag Cancelled 事件
https://blog.csdn.net/CandyU2/article/details/150997061?sharetype=blogdetail&sharerId=150997061&sharerefer=PC&sharesource=CandyU2&spm=1011.2480.3001.8118
详见案例十四、十五。