EditorGUILayout.BoundsField 是 Unity 编辑器中用于绘制和编辑 Bounds 类型字段的控件。Bounds 表示一个三维空间中的包围盒,包含中心点和尺寸。
using UnityEditor;
using UnityEngine;
public class BoundsFieldExample : EditorWindow
{
private Bounds boundsValue = new Bounds(Vector3.zero, Vector3.one);
[MenuItem("Window/Bounds Field Example")]
public static void ShowWindow()
{
GetWindow<BoundsFieldExample>("Bounds Field Example");
}
private void OnGUI()
{
GUILayout.Label("Bounds Field Example", EditorStyles.boldLabel);
boundsValue = EditorGUILayout.BoundsField("Bounds", boundsValue);
GUILayout.Label($"Center: {boundsValue.center}");
GUILayout.Label($"Size: {boundsValue.size}");
}
}
运行效果