public static Bounds BoundsField (Rect position, Bounds value);
public static Bounds BoundsField (Rect position, GUIContent label, Bounds value);

参数

position屏幕上用于字段的矩形。
label(可选)显示在字段上方的标签。
value要编辑的值。

返回

Bounds 用户输入的值。

描述

创建用于输入 Bounds 的 Center 和 Extents 字段。


编辑器窗口中的 Bounds 字段。

另请参阅扩展编辑器 (Extending the editor)。

using UnityEngine;
using UnityEditor;

// Simple script that shows radius of bounds of selected MeshFilter

class EditorGUILayoutBoundsField : EditorWindow { float radius = 0; Bounds bounds;

[MenuItem("Examples/Show Radius of mesh bounds")] static void Init() { var window = GetWindow<EditorGUILayoutBoundsField>(); window.Show(); }

void 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") &amp;&amp; Selection.activeTransform) { 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(); } } }