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

static function GUIToScreenPoint (guiPoint : Vector2) : Vector2

Description描述

Convert a point from GUI position to screen space.

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

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在窗口的顶边到最大在窗口的底边。这不同于其他坐标。

参考:GUIUtility.ScreenToGUIPoint.

using UnityEngine;
using System.Collections;

public class example : 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);
	}
}
// Check the difference between the mouse position (Screen) and
// the converted GUI positions because of the group.
//检查鼠标的位置和转换的GUI位置有什么不同

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);
}
最后修改:2011年1月5日 Wednesday 0:09

本脚本参考基于Unity 3.4.1f5

英文部分版权属©Unity公司所有,中文部分© Unity圣典 版权所有,未经许可,严禁转载 。