Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


BoundsField

Makes Center and Extents field for entering a Bounds.
Read time 3 minutesLast updated 4 days ago

Definition

  • Type: Method
  • Namespace: UnityEditor
  • Assembly: UnityEditor

BoundsField(Rect, Bounds)

Makes Center and Extents field for entering a Bounds.
public static Bounds BoundsField(Rect position, Bounds value)

Parameters

position

Rectangle on the screen to use for the field.

value

The value to edit.

Returns

Type

Description

BoundsThe value entered by the user.

Remarks

EditorGUIBoundsField (BoundsField)
Bounds field in an Editor Window.

Examples

using UnityEngine;using UnityEditor;// Simple script that shows radius of bounds of selected MeshFilterclass 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") && 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(); } }}

BoundsField(Rect, string, Bounds)

Makes Center and Extents field for entering a Bounds.
public static Bounds BoundsField(Rect position, string label, Bounds value)

Parameters

position

Rectangle on the screen to use for the field.

label

Optional label to display above the field.

value

The value to edit.

Returns

Type

Description

BoundsThe value entered by the user.

Remarks

EditorGUIBoundsField (BoundsField)
Bounds field in an Editor Window.

Examples

using UnityEngine;using UnityEditor;// Simple script that shows radius of bounds of selected MeshFilterclass 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") && 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(); } }}

BoundsField(Rect, GUIContent, Bounds)

Makes Center and Extents field for entering a Bounds.
public static Bounds BoundsField(Rect position, GUIContent label, Bounds value)

Parameters

position

Rectangle on the screen to use for the field.

Optional label to display above the field.

value

The value to edit.

Returns

Type

Description

BoundsThe value entered by the user.

Remarks

EditorGUIBoundsField (BoundsField)
Bounds field in an Editor Window.

Examples

using UnityEngine;using UnityEditor;// Simple script that shows radius of bounds of selected MeshFilterclass 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") && 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(); } }}