返回介绍

GUIUtility.ScreenToGUIPoint 转换点从屏幕到GUI坐标

发布于 2019-12-18 15:37:50 字数 2196 浏览 1022 评论 0 收藏 0

JavaScript =>public static function ScreenToGUIPoint(screenPoint: Vector2): Vector2;
C# => public static Vector2 ScreenToGUIPoint(Vector2 screenPoint);

Parameters 参数

Description 描述

Convert a point from screen space to GUI position.

转换一个点从屏幕坐标空间位置到GUI位置。

Used for reconverting values calculated from GUIToScreenPoint

再转换值回来用GUIToScreenPoint。

Note: In Unity the screen space y coordinate varies from zero at the top edge of the window to a maximum at the bottom edge of the window. This is different from what you might expect.

注意:在Unity屏幕空间y坐标变化从0在窗口的顶边到最大在窗口的底边。这不同于其他坐标。

JavaScript:

	// Check the difference between the mouse position (Screen) and
	// the converted GUI positions because of the group.
 
	function OnGUI () {
		var screenPos : Vector2 = Event.current.mousePosition;
		GUI.BeginGroup (Rect (10,10,100,100));
		var convertedGUIPos : Vector2 = GUIUtility.ScreenToGUIPoint(screenPos);
		GUI.EndGroup ();
		Debug.Log("Screen: " + screenPos + " GUI: " + convertedGUIPos);
	}

C#:

using UnityEngine;
using System.Collections;
 
public class ExampleClass : MonoBehaviour {
    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);
    }
}

guiutility

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文