이 페이지에는 UI 툴킷을 통한 이벤트 시스템 및 입력 시스템 사용에 대해 자주 묻는 질문이 있습니다.
두 가지 방법을 통해 이를 알 수 있습니다.
첫 번째 방법
com.unity.uGUI
패키지에서 게임 오브젝트 기반 UI 콘텐츠를 생성하는 것과 동일한 방식으로 씬에서 Event System 컴포넌트를 추가합니다.
uGUI나 UI 툴킷에서 포인터가 UI 콘텐츠 위에 있을 경우 true
를 반환하는 EventSystem.current.IsPointerOverGameObject
메서드를 사용합니다.
EventSystem.current.RaycastAll
메서드를 사용하여 마우스 아래에 있는 시각적 요소를 확인합니다.
교차된 UI 툴킷 패널은 게임 오브젝트를 통해 이벤트 시스템의 환경에 나타납니다.
PanelRaycaster
및 PanelEventHandler
)가 있습니다.두 컴포넌트에는 타겟이 되는 Ipanel
을 반환하는 panel
프로퍼티가 있습니다.포인터 아래에서 패널을 찾은 후 panel.Pick
메서드를 호출하여 포인터의 포지션에 있는 시각적 요소를 찾습니다.
RuntimePanelUtils.ScreenToPanel
메서드를 사용하여 포인터의 화면 좌표를 패널 좌표로 변환합니다.
uGUI의 화면 좌표 시스템은 왼쪽 하단 원점을 사용하는 반면, UI 툴킷 화면 좌표는 왼쪽 상단에서 표현됩니다.두 시스템 간에 전환하려면 yTopLeft = Screen.height - yBottomLeft
로 Y 좌표를 미러링해야 하며, 그 반대의 경우도 마찬가지입니다.
두 번째 방법
UIDocument.rootVisualElement
프로퍼티를 사용하여 포인터 아래에 있을 수 있는 모든 런타임 패널 리스트를 가져올 수 있으며, 이를 수집할 수 있습니다.panel.Pick
을 연속적으로 호출합니다.기본 UI 동작을 다시 매핑하려면 다음과 같이 하십시오.
com.unity.uGUI
패키지에서 게임 오브젝트 기반 UI 콘텐츠를 생성하는 것과 동일한 방식으로 씬에서 Event System 컴포넌트를 추가합니다.참고:Tab 및 Shift+Tab 입력에 매핑된 동작은 Event System 입력 모듈을 통해 노출되지 않으므로 다시 매핑할 수 없습니다.
방향 내비게이션을 설정하여 기본 타겟이 아닌 다른 타겟을 지정할 수 있습니다.
다음 코드 예시를 사용하면 요소 A가 위, 아래, 왼쪽, 오른쪽으로 각각 탐색할 때 U, D, L, R 요소로 탐색할 수 있습니다.
A.RegisterCallback <NavigationMoveEvent>(e =>
{
switch(e.direction)
{
case NavigationMoveEvent.Direction.Up:U.Focus(); break;
case NavigationMoveEvent.Direction.Down:D.Focus(); break;
case NavigationMoveEvent.Direction.Left:L.Focus(); break;
case NavigationMoveEvent.Direction.Right:R.Focus(); break;
}
e.PreventDefault();
});
네.EventSystem StandaloneInputModule
또는 InputSystemUIInputModule
인스펙터 필드를 사용하여 각 동작에 매핑할 입력을 컨트롤할 수 있습니다.그러나 이러한 동작은 uGUI 입력과 공유되기 때문에 uGUI 컨트롤도 변경됩니다.
uGUI 컨트롤에 영향을 주지 않고 UI 툴킷 입력을 다시 매핑하려면 UI 툴킷의 런타임 이벤트 처리를 비활성화하고 모든 이벤트를 패널에 수동으로 전송합니다.
게임 씬을 처음 로드할 때와 같이 특정 시점에 포커스가 맞춰진 요소나 패널이 없을 수 있습니다.이 경우 키보드 내비게이션은 예측 가능한 첫 번째 요소에서 시작하지 않습니다.이는 마우스 없이 플레이하는 게임에서 문제가 될 수 있습니다.
처음부터 예측 가능한 내비게이션 동작이 가능하도록 C# 스크립트를 추가하고, 초기 포커스를 가져오도록 선택한 요소를 담당하는 UIDocument와 동일한 게임 오브젝트에 스크립트를 연결합니다.
스크립트의 이름이 FirstFocus
이고 초기에 포커스가 맞춰진 요소의 이름이 first-focused
라고 가정합니다.스크립트의 Start()
메서드에서 다음과 같이 해당 요소에 포커스를 맞추는 줄을 추가합니다.
public class FirstFocus :MonoBehaviour
{
void Start()
{
FocusFirstElement();
}
public void FocusFirstElement()
{
GetComponent<UIDocument>().rootVisualElement.
Q<VisualElement>("first-focused").Focus();
}
}
참고:UIDocument의 게임 오브젝트를 비활성화하면 모든 기본 계층 구조가 처음부터 다시 생성됩니다.따라서 게임 오브젝트를 다시 활성화한 후에는 커스텀 FocusFirstElement()
메서드를 다시 실행해야 합니다.
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.