Unity实现在Android或IOS端点击【InputField】输入框弹出键盘上的内容默认处于选中状态
最终效果如:
上代码
using UnityEngine.EventSystems;
/// <summary>
/// 该脚本挂在InputField上
/// </summary>
public class Test : MonoBehaviour, IPointerClickHandler
{
private InputField inputField;
private bool isClick;
private void Awake()
{
inputField = GetComponent<InputField>();
inputField.onEndEdit.AddListener(content => isClick = false);
}
private void LateUpdate()
{
if (isClick)
inputField.touchScreenKeyboard.selection = new RangeInt(0, inputField.touchScreenKeyboard.text.Length);
}
public void OnPointerClick(PointerEventData eventData)
{
isClick = true;
}
}
以上代码即可实现该功能,目前能想到的方法就只有这一种,有更好办法的大佬欢迎指正