RectTransformUtility.ScreenPointToWorldPointInRectangle

切换到手册
public static bool ScreenPointToWorldPointInRectangle (RectTransform rect, Vector2 screenPoint, Camera cam, out Vector3 worldPoint);

参数

rect要在其中查找点的 RectTransform。
cam与屏幕空间位置关联的摄像机。
screenPoint屏幕空间位置。
worldPoint世界空间中的点。

返回

bool 如果点击 RectTransform 平面,则无论点是否在矩形内,都返回 true。

描述

将一个屏幕空间点转换为世界空间中位于给定 RectTransform 平面上的一个位置。

cam 参数应为与此屏幕点关联的摄像机。对于设置为 Screen Space - Overlay 模式的 Canvas 中的 RectTransform,cam 参数应为 null。

当从提供 PointerEventData 对象的事件处理程序中使用 ScreenPointToWorldPointInRectangle 时,可以通过使用 PointerEventData.enterEventData(对于悬停功能)或 PointerEventData.pressEventCamera(对于单击功能)获取正确的摄像机。这会为给定事件自动使用正确的摄像机(或 null)。

Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961