当前位置:网站首页>[unity notes] screen coordinates to ugui coordinates
[unity notes] screen coordinates to ugui coordinates
2022-07-07 02:20:00 【Start()】
API :
RectTransformUtility Static functions under class ScreenPointToLocalPointInRectangle
You need to pass in four parameters ,
① RectTransform:
This parameter is equivalent to indicating A canvas , The screen coordinate point is the position of the canvas . Under the canvas UI Coordinate changes are shown in the figure :

② Vector2
Screen coordinates , From bottom left to top right , Use " Input.mousePosition " Can be judged

③ Camera
Canvas The rendering mode is Camera Of , The camera needs to be filled in this parameter ;Overlay Can be filled directly null
④ out Vector2
Output conversion completed UGUI coordinate
The following implementation UI As the mouse moves :

Implementation code :
public RectTransform rect;// Based on which Rect Transform
public RectTransform targetRect;// Following the movement of the mouse UI
void Update()
{
RectTransformUtility.ScreenPointToLocalPointInRectangle(rect, Input.mousePosition, null, out Vector2 v2);
targetRect.localPosition = v2;
}
What we use here is Recttransform.localPosition instead of anchoredPosition,anchoredPosition Is based on the current UI Anchor point to get the coordinate position , If the anchor point is in the center, it is and localPosition equal , Make a note of ~
边栏推荐
- FLIR blackfly s industrial camera: synchronous shooting of multiple cameras through external trigger
- Recent applet development records
- [paper reading | deep reading] graphsage:inductive representation learning on large graphs
- Centos8 install MySQL 8.0 using yum x
- CISP-PTE实操练习讲解(二)
- Tiflash source code reading (IV) design and implementation analysis of tiflash DDL module
- Metaforce force meta universe development and construction - fossage 2.0 system development
- 6 seconds to understand the book to the Kindle
- FLIR blackfly s usb3 industrial camera: white balance setting method
- Time synchronization of livox lidar hardware -- PPS method
猜你喜欢

BigDecimal 的正确使用方式

leetcode:736. Lisp 语法解析【花里胡哨 + 栈 + 状态enumaotu + slots】

本周 火火火火 的开源项目!

FLIR blackfly s usb3 industrial camera: white balance setting method
![[paper reading | deep reading] rolne: improving the quality of network embedding with structural role proximity](/img/21/59c4d61b22e7d021b7a72a64a16b48.png)
[paper reading | deep reading] rolne: improving the quality of network embedding with structural role proximity

ROS learning (26) dynamic parameter configuration

STM32F4---PWM输出

How did partydao turn a tweet into a $200million product Dao in one year
![[paper reading | deep reading] dngr:deep neural networks for learning graph representations](/img/8e/41a80131c6ec7a7cdffe4a77012fed.png)
[paper reading | deep reading] dngr:deep neural networks for learning graph representations

ROS learning (XX) robot slam function package -- installation and testing of rgbdslam
随机推荐
企业中台建设新路径——低代码平台
Sensor: DS1302 clock chip and driver code
[paper reading | deep reading] rolne: improving the quality of network embedding with structural role proximity
[unity] upgraded version · Excel data analysis, automatically create corresponding C classes, automatically create scriptableobject generation classes, and automatically serialize asset files
NPM install compilation times "cannot read properties of null (reading 'pickalgorithm')“
长安链学习笔记-证书研究之证书模式
New generation cloud native message queue (I)
[paper reading | deep reading] graphsage:inductive representation learning on large graphs
XML to map tool class xmlmaputils (tool class V)
Command injection of cisp-pte
机器人队伍学习方法,实现8.8倍的人力回报
Yyds dry goods inventory # solve the real problem of famous enterprises: maximum difference
企业中台建设新路径——低代码平台
建议收藏!!Flutter状态管理插件哪家强?请看岛上码农的排行榜!
Tiflash source code reading (IV) design and implementation analysis of tiflash DDL module
The boss is quarantined
Redis tool class redisutil (tool class III)
Errors made in the development of merging the quantity of data in the set according to attributes
建議收藏!!Flutter狀態管理插件哪家强?請看島上碼農的排行榜!
Jacob Steinhardt, assistant professor of UC Berkeley, predicts AI benchmark performance: AI has made faster progress in fields such as mathematics than expected, but the progress of robustness benchma