Version: 2022.1
public static float FloatField (float value, params GUILayoutOption[] options);
public static float FloatField (float value, GUIStyle style, params GUILayoutOption[] options);
public static float FloatField (string label, float value, params GUILayoutOption[] options);
public static float FloatField (string label, float value, GUIStyle style, params GUILayoutOption[] options);
public static float FloatField (GUIContent label, float value, params GUILayoutOption[] options);
public static float FloatField (GUIContent label, float value, GUIStyle style, params GUILayoutOption[] options);

参数

label (可选)显示在浮点字段前的标签。
value 要编辑的值。
style 可选 GUIStyle
options 一个可选的布局选项列表,用于指定额外的布局属性。此处传递的任何值都将覆盖 style 定义的设置。
另请参阅:GUILayout.WidthGUILayout.HeightGUILayout.MinWidthGUILayout.MaxWidthGUILayout.MinHeightGUILayout.MaxHeightGUILayout.ExpandWidthGUILayout.ExpandHeight

返回

float 用户输入的值。

描述

生成一个用于输入浮点值的文本字段。


乘以所选游戏对象的缩放比例。

using UnityEngine;
using UnityEditor;

// Editor Script that multiplies the scale of the current selected GameObject

public class FloatFieldExample : EditorWindow { float sizeMultiplier = 1.0f;

[MenuItem("Examples/Scale selected Object")] static void Init() { var window = (FloatFieldExample)GetWindow(typeof(FloatFieldExample)); window.Show(); }

void OnGUI() { sizeMultiplier = EditorGUILayout.FloatField("Increase scale by:", sizeMultiplier);

if (GUILayout.Button("Scale")) { if (!Selection.activeGameObject) { Debug.Log("Select a GameObject first"); return; }

Selection.activeTransform.localScale = Selection.activeTransform.localScale * sizeMultiplier; } } }