The UI InputField when it gets focus highlights all text inside. I would like to move the caret to the end of the text so the user can keep writing the text within. Currently I have a hack solution, which works, however there it is still a short moment when the text is highlighted. Here is my hack:
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;
public class TextFieldBehaviour : MonoBehaviour, ISelectHandler
{
private InputField inputField;
private bool isCaretPositionReset = false;
void Start()
{
inputField = gameObject.GetComponent<InputField>();
}
public void OnSelect (BaseEventData eventData)
{
isCaretPositionReset = false;
}
void Update()
{
if(inputField.isFocused == true && isCaretPositionReset == false)
{
inputField.caretPosition = inputField.text.Length;
isCaretPositionReset = true;
}
}
}
I was also checking out the source code of InputField. But I have trouble trouble creating a custom one without the SelectAll() function. I am getting a bunch of errors due to the protection level of the UnityEngine.UI.SetPropertyUtility
.