Unity는 대부분의 경우 GUI 요소에 대한 키보드 입력을 자동으로 처리하지만, 필요 시 스크립트를 통해 간단하게 키보드를 보여줄 수도 있습니다.
사용자가 편집 가능한 GUI 요소를 누를 때 자동으로 키보드가 나타납니다. 키보드를 나타내는 동작은 현재 GUI.TextField, GUI.TextArea, GUI.PasswordField에서 담당합니다. 자세한 내용은 GUI 클래스 문서를 참조하십시오.
TouchScreenKeyboard.Open() 함수를 사용하여 키보드를 열 수 있습니다. 함수의 파라미터에 대해서는 TouchScreenKeyboard 스크립팅 레퍼런스를 참조하십시오.
키보드는 다음 옵션을 지원합니다.
프로퍼티: | 기능: |
---|---|
TouchScreenKeyboardType.Default | 문자 키보드입니다. 숫자 및 기호 키보드로 전환할 수 있습니다. |
TouchScreenKeyboardType.ASCIICapable | 문자 키보드입니다. 숫자 및 기호 키보드로 전환할 수 있습니다. |
TouchScreenKeyboardType.NumbersAndPunctuation | 숫자 및 기호 키보드입니다. 문자 키보드로 전환할 수 있습니다. |
TouchScreenKeyboardType.URL | 슬래시와 .com 버튼이 있는 문자 키보드입니다. 숫자 및 기호 키보드로 전환할 수 있습니다. |
TouchScreenKeyboardType.NumberPad | 0에서 9까지의 숫자만으로 구성된 키보드입니다. |
TouchScreenKeyboardType.PhonePad | 전화번호 입력을 위한 키보드입니다. |
TouchScreenKeyboardType.NamePhonePad | 문자 키보드입니다. 전화번호 키보드로 전환할 수 있습니다. |
TouchScreenKeyboardType.EmailAddress | @ 기호가 있는 문자 키보드입니다. 숫자 및 기호 키보드로 전환할 수 있습니다. |
기본적으로 편집 박스는 키보드가 나타난 후 키보드 상단에 위치합니다. 편집 박스는 사용자가 입력하는 텍스트를 미리보기로 보여주는 역할을 하며, 따라서 텍스트를 입력하는 즉시 사용자에게 표시됩니다. 그러나 TouchScreenKeyboard.hideInput 값을 참(true)으로 설정하여 텍스트 미리보기를 비활성화할 수 있습니다. 이때 주의할 점은 특정 키보드 타입이나 입력 모드에서만 비활성화할 수 있다는 점입니다. 예를 들어, 전화번호 키패드나 여러 줄의 텍스트 입력 모드에서는 작동하지 않습니다. 이러한 경우에는 항상 편집 박스가 나타납니다. TouchScreenKeyboard.hideInput 은 전역 변수이며 모든 키보드에 영향을 미칩니다.
TouchScreenKeyboard에는 3가지 키보드 프로퍼티가 있으며, 각 프로퍼티는 키보드의 표시 여부와 화면의 크기를 결정합니다.
프로퍼티: | 기능: |
---|---|
visible | 키보드가 화면에 완전히 나타나 있고 문자를 입력할 수 있으면 참(true) 을 반환합니다. |
area | 키보드의 포지션과 크기를 반환합니다. |
active | 키보드가 활성화되어 있으면 참(true) 을 반환합니다. 프로퍼티는 정적 프로퍼티가 아닙니다. 프로퍼티를 사용하려면 키보드 인스턴스가 있어야 합니다. |
TouchScreenKeyboard.area 는 키보드가 화면에 완전히 나타나기 전까지는 포지션과 크기가 0으로 설정된 사각형을 반환합니다. TouchScreenKeyboard.Open() 후에 값을 즉시 쿼리해서는 안 됩니다. 키보드 이벤트의 순서는 다음과 같습니다.
키보드로 입력할 때 입력한 문자를 숨기게 설정할 수 있습니다. 사용자가 민감한 정보(예: 비밀번호)를 입력해야 할 때 유용합니다. 보안 텍스트 입력이 적용된 키보드를 수동으로 열려면 다음 코드를 사용해야 합니다.
TouchScreenKeyboard.Open("", TouchScreenKeyboardType.Default, false, false, true);
클래식 불투명 키보드 대신 반투명 검은 색 배경의 키보드를 나타내려면 다음과 같이 TouchScreenKeyboard.Open() 을 호출해야 합니다.
TouchScreenKeyboard.Open("", TouchScreenKeyboardType.Default, false, false, true, true);
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.