GUI.FocusControl 焦点控件

static function FocusControl (name : String) : void

Description描述

Move keyboard focus to a named control.

移动键盘焦点到被命名的控件。

参考:SetNextControlName, GetNameOfFocusedControl.

using UnityEngine;
using System.Collections;

public class example : MonoBehaviour {
	public string username = "username";
	public string pwd = "a pwd";
	void OnGUI() {
		GUI.SetNextControlName("MyTextField");
		username = GUI.TextField(new Rect(10, 10, 100, 20), username);
		pwd = GUI.TextField(new Rect(10, 40, 100, 20), pwd);
		if (GUI.Button(new Rect(10, 70, 80, 20), "Move Focus"))
			GUI.FocusControl("MyTextField");

	}
}
//当按下按钮,选择"username"文本字段,也就是获得焦点
var username : String = "username";
var pwd : String = "a pwd";
function OnGUI () {
	//设置文本字段一个内部名字
	GUI.SetNextControlName ("MyTextField");

	//创建用户名和密码文本字段
	username = GUI.TextField (Rect (10,10,100,20), username);
	pwd = GUI.TextField (Rect (10,40,100,20), pwd);

	// 如果按下按钮键盘焦点将移动到用户名文本字段
	if (GUI.Button (Rect (10,70,80,20), "Move Focus"))
		GUI.FocusControl ("MyTextField");
}
Page last updated: 2011-1-14