前言:
登录或者注册界面需要鼠标点一下文本,鼠标光标才会移动到下一个。但不少用户已经习惯性点Shift来进行切换。
功能实现
1,InputField.isFocused bool类型,用来得知光标是否在InputField上。
2,InputField.Select() 方法,用来选中InputField。
代码
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Test : MonoBehaviour
{
int index = 0;
public InputField[] inputFields;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.LeftShift))
{
for (int i = 0; i < inputFields.Length; i++)
{
if (inputFields[i].isFocused)
{
index = i;
}
}
index++;
if (index > inputFields.Length - 1)
index = 0;
inputFields[index].Select();
}
}
}
后续:好像都是Tab键切换鼠标光标,哈哈哈哈。