using UnityEngine;
using System.Collections;
public class SetConFocus : MonoBehaviour {
public string username = "username";
public string pwd = "a pwd";
public string pwds = "a pwds";
int count = 1;
private bool isopen = false;
void OnGUI()
{ /***********设置下一个控件的名字****************/
GUI.SetNextControlName("MyTextField");
GUI.Button(new Rect(10, 10, 100, 20), username);
GUI.SetNextControlName("TEXT2");
GUI.Button(new Rect(10, 40, 100, 20), pwd);
GUI.SetNextControlName("TEXT3");
GUI.Button(new Rect(10, 70, 100, 20), pwds);
/*************按一下button的时候,名字为MyTextField的控件获得焦点*******************/
if (GUI.Button(new Rect(10, 100, 80, 20), "Move Focus"))
{
Debug.Log(count);
if (count % 3 == 0)
{
GUI.FocusControl("MyTextField");
isopen = true;
}
else if (count % 3 == 1)
{
GUI.FocusControl("TEXT2");
}
else
{
GUI.FocusControl("TEXT3");
}
count++;
}
}
void Update(){
/*********焦点在上面的时候,就响应一些事件************/
if (isopen)
{
if (Input.GetKeyDown(KeyCode.Return))
{
isopen = false;
Debug.Log("the t button is pressed");
Debug.Log("the MyTextField is pressed");
}
}
}
using System.Collections;
public class SetConFocus : MonoBehaviour {
public string username = "username";
public string pwd = "a pwd";
public string pwds = "a pwds";
int count = 1;
private bool isopen = false;
void OnGUI()
{ /***********设置下一个控件的名字****************/
GUI.SetNextControlName("MyTextField");
GUI.Button(new Rect(10, 10, 100, 20), username);
GUI.SetNextControlName("TEXT2");
GUI.Button(new Rect(10, 40, 100, 20), pwd);
GUI.SetNextControlName("TEXT3");
GUI.Button(new Rect(10, 70, 100, 20), pwds);
/*************按一下button的时候,名字为MyTextField的控件获得焦点*******************/
if (GUI.Button(new Rect(10, 100, 80, 20), "Move Focus"))
{
Debug.Log(count);
if (count % 3 == 0)
{
GUI.FocusControl("MyTextField");
isopen = true;
}
else if (count % 3 == 1)
{
GUI.FocusControl("TEXT2");
}
else
{
GUI.FocusControl("TEXT3");
}
count++;
}
}
void Update(){
/*********焦点在上面的时候,就响应一些事件************/
if (isopen)
{
if (Input.GetKeyDown(KeyCode.Return))
{
isopen = false;
Debug.Log("the t button is pressed");
Debug.Log("the MyTextField is pressed");
}
}
}
}
效果图: