Version: 2022.1

GUIUtility.ScreenToGUIPoint

切换到手册
public static Vector2 ScreenToGUIPoint (Vector2 screenPoint);

描述

将一个点从屏幕空间位置转换为 GUI 位置。

用于重新转换从 GUIToScreenPoint 计算的值

注意:在 Unity 中,屏幕空间的 y 坐标的取值范围为零(窗口顶部边缘) 到最大值(窗口底部边缘)。 这可能与您的预期不同。

另请参阅:GUIUtility.GUIToScreenPoint

using UnityEngine;

public class Example : MonoBehaviour { // Check the difference between the mouse position (Screen) and // the converted GUI positions because of the group.

void OnGUI() { Vector2 screenPos = Event.current.mousePosition; GUI.BeginGroup(new Rect(10, 10, 100, 100)); Vector2 convertedGUIPos = GUIUtility.ScreenToGUIPoint(screenPos); GUI.EndGroup(); Debug.Log("Screen: " + screenPos + " GUI: " + convertedGUIPos); } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961