EditorGUI.BoundsField 边界盒字段

static function BoundsField (position : Rect, value : Bounds) : Bounds
static function BoundsField (position : Rect, label : GUIContent, value : Bounds) : Bounds

Parameters参数

Returns

Bounds - The value entered by the user.

返回Bounds - 用户输入的值。

Description描述

Make Center & Extents field for entering a Bounds.

制作Center 和 Extents字段,用来输入一个Bounds

EditorGUI.BoundsField 边界盒字段

Bounds field in an Editor Window.

在编辑器窗口中的边界盒字段。

// Simple script that shows radius of bounds of selected MeshFilter
//显示选择的MeshFilter的边界盒半径
class EditorGUILayoutBoundsField extends EditorWindow {

	var radius : float = 0;
	var bounds : Bounds;

	@MenuItem("Examples/Show Radius of mesh bounds")
	static function Init() {
		var window = GetWindow(EditorGUILayoutBoundsField);
		window.Show();
	}
	function OnGUI() {
		GUILayout.Label("Select a mesh in the Hierarchy view and click 'Capture Bounds'");
		EditorGUILayout.BeginHorizontal();
		bounds = EditorGUILayout.BoundsField("Mesh bounds:", bounds);
		if(GUILayout.Button("Capture Bounds") && Selection.activeTransform)
		{
			var meshFilter : MeshFilter = Selection.activeTransform.GetComponentInChildren(MeshFilter);
			if (meshFilter)
				bounds = meshFilter.sharedMesh.bounds;
		}
		EditorGUILayout.EndHorizontal();

		EditorGUILayout.LabelField("Radius:", bounds.size.magnitude.ToString());
		if(GUILayout.Button("Close"))
			this.Close();
	}
}
最后修改:2011年10月4日 Tuesday 10:09

本脚本参考基于Unity 3.4.1f5

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