Legacy Documentation: Version 5.0
Language: English
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

EditorGUI.BoundsField

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Sumbission failed

For some reason your suggested change could not be submitted. Please try again in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Switch to Manual
public static function BoundsField(position: Rect, value: Bounds): Bounds;
public static Bounds BoundsField(Rect position, Bounds value);
public static function BoundsField(position: Rect, label: GUIContent, value: Bounds): Bounds;
public static Bounds BoundsField(Rect position, GUIContent label, Bounds value);

Parameters

positionRectangle on the screen to use for the field.
labelOptional label to display above the field.
valueThe value to edit.

Returns

Bounds The value entered by the user.

Description

Make Center & Extents field for entering a Bounds.


Bounds field in an Editor Window.

	// Simple script that shows radius of bounds of selected 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(); } }