Unity3D TextField 和 PasswordField控件(文本框)

TextField控件

TextField控件主要用于监听用户输入的信息,使用GUI.TextField()方法显示输入框,该方法的返回值为用户输入的字符串信息

常见形式:

GUI.TextField(位置, 显示内容, 字符串最大长度);

 

如:GUI.TextField (new Rect(60,40,200,30),"请输入用户名",15);

将在界面Rect(60,40,200,30)的位置显示一个文本框,文本框中显示着“请输入用户名”,其返回值为用户输入进文本框中的内容(可将其赋值给变量以供后面使用),最多输入15个字符。

函数原型(JavaScript)如下:

  1. public static function TextField(position:Rect, text:string):string;
  2. public static function TextField(position:Rect, text:string, maxLength:int):string;
  3. public static function TextField(position:Rect, text:string, style:GUIStyle):string;
  4. public static function TextField(position:Rect, text:string, maxLength:int,style:GUIStyle):string;

 

TextField 控件的具体参数如下表所示。
 

参 数 功 能 参 数 功 能
position 设置控件在屏幕上的位置及大小 text 设置控件上默认显示的文本
maxLength 设置输入的字符串的最大长度 style 设置控件使用的样式

 

PasswordField控件

输入密码常用的控件,与TextField控件用法大致相同,增加了一个 可将用户输入的字符串显示为任意字符的功能,一般在输入密码时会将密码以“ ***** ”形式显示。

常见形式:

GUI.PasswordField(位置, 显示内容,替换显示内容, 字符串最大长度);

 

如:GUI.PasswordField(new Rect(60,40,200,30), "请输入密码", '*' , 15);

将在界面Rect(60,40,200,30)的位置显示一个文本框,文本框中显示着“*****”,其返回值为用户输入进文本框中的内容(可将其赋值给变量以供后面使用),最多输入15个字符。

函数原型(JavaScript)如下:

1. static function PasswordField ((position : Rect, password : String, maskChar : char) : String
2. static function PasswordField (position : Rect, password : String, maskChar : char, maxLength : int) : String
3. static function PasswordField (position : Rect, password : String, maskChar : char, style : GUIStyle) : String
4. static function PasswordField (position : Rect, password : String, maskChar : char, maxLength : int, style : GUIStyle) : String

PasswordField 控件的具体参数如下表所示。

参 数 功 能 参 数 功 能
position 设置控件在屏幕上的位置及大小 password 设置控件上默认显示的文本,一般会被maskChar改变显示为其它内容(例如: * )
maxLength 设置输入的字符串的最大长度 style

设置控件使用的样式

如果不设置,密码字段的样式将应用当前的GUISkin皮肤

maskChar 设置将用户输入的信息显示为任意内容    

 

 

你可能感兴趣的:(Unity3D,Unity3D,TextField控件)