Version: 2022.3
public static int IntField (int value, params GUILayoutOption[] options);
public static int IntField (int value, GUIStyle style, params GUILayoutOption[] options);
public static int IntField (string label, int value, params GUILayoutOption[] options);
public static int IntField (string label, int value, GUIStyle style, params GUILayoutOption[] options);
public static int IntField (GUIContent label, int value, params GUILayoutOption[] options);
public static int IntField (GUIContent label, int value, GUIStyle style, params GUILayoutOption[] options);

参数

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

返回

int 用户输入的值。

描述

创建一个用于输入整数的文本字段。


多次克隆所选的对象。

// Editor Script that clones the selected GameObject a number of times.

using UnityEditor; using UnityEngine;

public class IntFieldExample : EditorWindow { int clones = 1; static int sizeMultiplier;

[MenuItem("Examples/Clone Object")] static void Init() { EditorWindow window = GetWindow(typeof(IntFieldExample)); window.Show(); }

void OnGUI() { sizeMultiplier = EditorGUILayout.IntField("Number of clones:", clones);

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

for (var i = 0; i < sizeMultiplier; i++) Instantiate(Selection.activeGameObject, Vector3.zero, Quaternion.identity); } } }