语言英语
  • C#

EditorGUI.PasswordField

声明

public static string PasswordField(Rect position, string password, GUIStyle style = EditorStyles.textField);

声明

public static string PasswordField(Rect position, string label, string password, GUIStyle style = EditorStyles.textField);

声明

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

参数

position 屏幕上用于密码字段的矩形。
label 可选标签,显示在密码字段前面。
password 要编辑的密码。
style 可选的 GUIStyle

返回值

string 用户输入的密码。

描述

创建一个文本字段,用户可以在其中输入密码。

这与 GUI.PasswordField 的工作方式相同,但在编辑器中对全选等操作做出正确的响应,并且可以在前面有一个可选的标签。


编辑器窗口中的密码字段。

using UnityEngine;
using UnityEditor;

// Editor Script that creates a password field and lets you visualize what have you // typed in a label.

class EditorGUIPasswordField : EditorWindow { string text = "Some text here";

[MenuItem("Examples/Editor Password field usage")] static void Init() { EditorWindow window = GetWindow<EditorGUIPasswordField>(); window.Show(); }

void OnGUI() { text = EditorGUI.PasswordField( new Rect(3, 3, position.width - 6, 20), "Type Something:", text);

EditorGUI.LabelField( new Rect(3, 25, position.width - 5, 20), "Written Text:", text); } }

Did you find this page useful? Please give it a rating: