public static string TextField (Rect position, string text, GUIStyle style= EditorStyles.textField);
public static string TextField (Rect position, string label, string text, GUIStyle style= EditorStyles.textField);
public static string TextField (Rect position, GUIContent label, string text, GUIStyle style= EditorStyles.textField);

参数

position屏幕上用于文本字段的矩形。
label(可选)显示在文本字段前的标签。
text要编辑的文本。
style可选 GUIStyle

返回

string 用户输入的文本。

描述

创建一个文本字段。

此方法的运行方式与 GUI.TextField 类似,但能够正确响应编辑器中的 Select All、Copy、Paste 等操作, 并可在前面提供一个可选标签。


编辑器窗口中的 Text 字段。

// Changes the name of the selected Objects to the one typed in the text field

class EditorGUITextField extends EditorWindow {

var objNames : String = "";

@MenuItem("Examples/Bulk Name change") static function Init() { var window = GetWindow(EditorGUITextField); window.Show(); }

function OnGUI() { EditorGUI.DropShadowLabel(Rect(0, 0, position.width, 20), "Select the objects to rename."); objNames = EditorGUI.TextField(Rect(10,25,position.width - 20, 20), "New Names:", objNames); if(Selection.activeTransform) if(GUI.Button(Rect(0, 50, position.width, 30), "Bulk rename!")) for(var t : Transform in Selection.transforms) t.name = objNames; }

function OnInspectorUpdate() { Repaint(); } }