当前位置:网站首页>[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 ~
边栏推荐
- ROS learning (24) plugin
- Analyze "C language" [advanced] paid knowledge [i]
- 2022/0524/bookstrap
- 张平安:加快云上数字创新,共建产业智慧生态
- Introduction to RC oscillator and crystal oscillator
- Data connection mode in low code platform (Part 1)
- UC伯克利助理教授Jacob Steinhardt预测AI基准性能:AI在数学等领域的进展比预想要快,但鲁棒性基准性能进展较慢
- Analyze "C language" [advanced] paid knowledge [II]
- leetcode:736. Lisp 语法解析【花里胡哨 + 栈 + 状态enumaotu + slots】
- How do I dump SoapClient requests for debugging- How to dump SoapClient request for debug?
猜你喜欢
leetcode:5. 最长回文子串【dp + 抓着超时的尾巴】
MySQL execution process and sequence
Twenty or thirty thousand a leaf? "Yang Mou" behind the explosion of plant consumption
如何从0到1构建32Core树莓派集群
机器人队伍学习方法,实现8.8倍的人力回报
猿桌派第三季开播在即,打开出海浪潮下的开发者新视野
FLIR blackfly s usb3 industrial camera: how to use counters and timers
【论文阅读|深读】RolNE: Improving the Quality of Network Embedding with Structural Role Proximity
张平安:加快云上数字创新,共建产业智慧生态
FLIR blackfly s industrial camera: auto exposure configuration and code
随机推荐
FLIR blackfly s industrial camera: synchronous shooting of multiple cameras through external trigger
ROS learning (22) TF transformation
centos8 用yum 安装MySQL 8.0.x
UC伯克利助理教授Jacob Steinhardt预测AI基准性能:AI在数学等领域的进展比预想要快,但鲁棒性基准性能进展较慢
Infrared camera: juge infrared mag32 product introduction
FLIR blackfly s industrial camera: explanation and configuration of color correction and code setting method
传感器:土壤湿度传感器(XH-M214)介绍及stm32驱动代码
Input and output of C language pointer to two-dimensional array
Time synchronization of livox lidar hardware -- PPS method
[unity] upgraded version · Excel data analysis, automatically create corresponding C classes, automatically create scriptableobject generation classes, and automatically serialize asset files
【LeetCode】Day97-移除链表元素
Yyds dry goods inventory # solve the real problem of famous enterprises: maximum difference
使用Ceres进行slam必须要弄清楚的几个类和函数
FLIR blackfly s usb3 industrial camera: white balance setting method
Freeswitch dials extension number source code tracking
centos8安装mysql报错:The GPG keys listed for the “MySQL 8.0 Community Server“ repository are already ins
低代码平台中的数据连接方式(上)
CISP-PTE之命令注入篇
张平安:加快云上数字创新,共建产业智慧生态
【Unity】升级版·Excel数据解析,自动创建对应C#类,自动创建ScriptableObject生成类,自动序列化Asset文件