본문 바로가기
Unity3D/Unity & C#

Unity & C# ~ InputField가 선택 되었을 때, 커서 위치

by 캬캬백곰 2022. 11. 17.
728x90

보통 InputField가 선택 되었을 때, 텍스트가 전체 선택된 상태입니다.

전체 선택된 focus를 커서를 처음 또는 중간, 마지막으로 옮기는 방법입니다.

TMP_InputField inputField;

    // Start is called before the first frame update
    void Start()
    {
        inputField = GetComponent<TMP_InputField>();

        inputField.onSelect.AddListener(x =>
        {
        	#if
            inputField.selectionAnchorPosition = 0;	// 커서의 처음 위치
            inputField.selectionFocusPosition = 0;	// 커서의 마지막 위치
            #esleif
            inputField.selectionAnchorPosition = inputField.text.Length;	// 커서의 처음 위치
            inputField.selectionFocusPosition = inputField.text.Length;	// 커서의 마지막 위치
        });
    }
728x90
반응형