当前位置:网站首页>[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 ~
边栏推荐
- 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
- Stm32f4 --- general timer update interrupt
- Several classes and functions that must be clarified when using Ceres to slam
- 组合导航:中海达iNAV2产品描述及接口描述
- Robot team learning method to achieve 8.8 times human return
- 传感器:DS1302时钟芯片及驱动代码
- 张平安:加快云上数字创新,共建产业智慧生态
- XML to map tool class xmlmaputils (tool class V)
- 真实项目,用微信小程序开门编码实现(完结)
猜你喜欢
Correct use of BigDecimal
FLIR blackfly s usb3 industrial camera: how to use counters and timers
Robot team learning method to achieve 8.8 times human return
The mega version model of dall-e MINI has been released and is open for download
Word wrap when flex exceeds width
How can reinforcement learning be used in medical imaging? A review of Emory University's latest "reinforcement learning medical image analysis", which expounds the latest RL medical image analysis co
Several classes and functions that must be clarified when using Ceres to slam
The GPG keys listed for the "MySQL 8.0 community server" repository are already ins
Zhang Ping'an: accelerate cloud digital innovation and jointly build an industrial smart ecosystem
Tiflash source code reading (IV) design and implementation analysis of tiflash DDL module
随机推荐
The foreground downloads network pictures without background processing
Metaforce force meta universe development and construction - fossage 2.0 system development
企业中台建设新路径——低代码平台
Tips for web development: skillfully use ThreadLocal to avoid layer by layer value transmission
Lombok同时使⽤@Data和@Builder 的坑
MySQL execution process and sequence
go swagger使用
张平安:加快云上数字创新,共建产业智慧生态
MetaForce原力元宇宙开发搭建丨佛萨奇2.0系统开发
ROS learning (26) dynamic parameter configuration
ROS learning (24) plugin
Introduction to microservice architecture
遇到慢SQL该怎么办?(下)
Centos8 install MySQL 8.0 using yum x
FLIR blackfly s usb3 industrial camera: how to use counters and timers
pgpool-II和pgpoolAdmin的使用
ZABBIX 5.0: automatically monitor Alibaba cloud RDS through LLD
新一代云原生消息队列(一)
长安链学习笔记-证书研究之证书模式
Zhang Ping'an: accelerate cloud digital innovation and jointly build an industrial smart ecosystem