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

static function ScreenToGUIPoint (screenPoint : Vector2) : Vector2

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

参考:GUIUtility.GUIToScreenPoint.

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
	void OnGUI() {
		Vector2 gPos = new Vector2(10, 10);
		GUI.BeginGroup(new Rect(10, 10, 100, 100));
		Vector2 convertedGUIPos = GUIUtility.GUIToScreenPoint(gPos);
		GUI.EndGroup();
		Debug.Log("GUI: " + gPos + " Screen: " + convertedGUIPos);
	}
}
// Converts a GUICoordinate (afected by a group) to a Screen coordinate.
//转换GUI坐标到屏幕坐标 (影响组)
function OnGUI () {
	var gPos : Vector2 = Vector2(10,10);
	GUI.BeginGroup (Rect (10,10,100,100));
	var convertedGUIPos : Vector2 = GUIUtility.GUIToScreenPoint(gPos);
	GUI.EndGroup ();
	Debug.Log("GUI: " + gPos + " Screen: " + convertedGUIPos);
}
Page last updated: 2011-1-5