Version: 2023.2+
탭 메뉴는 비디오 게임과 애플리케이션 UI에서 콘텐츠를 구성하고 표시하는 데 널리 사용됩니다. 탭 및 TabView는 탭 메뉴를 생성하는 프로세스를 간소화하는 강력한 컨트롤입니다.
이 예시에서는 샘플 씬과 커스텀 에디터 창에서 탭 메뉴를 생성하는 방법을 보여 줍니다. 메뉴에는 3개의 탭이 있습니다. 각 탭에는 특정 콘텐츠가 표시됩니다. 특정 탭을 선택하면 해당 탭과 연결된 콘텐츠가 표시됩니다. 또한 이 예시에서는 뷰 데이터 키를 사용하여 에디터 창의 탭 순서를 유지합니다.
이 예시에서 생성하는 완성된 파일은 GitHub 저장소에서 찾을 수 있습니다.
이 가이드는 Unity 에디터, UI 툴킷, C# 스크립팅에 익숙한 개발자용입니다.시작하기 전에 먼저 다음을 숙지하십시오.
UI 문서를 생성하고 TabView를 추가합니다.
템플릿을 사용하여 Unity에서 프로젝트를 생성합니다.
Assets
폴더에서 TabbedMenu.uxml
이라는 UI 문서를 생성합니다.
TabbedMenu.uxml
을 더블 클릭하여 UI 빌더에서 엽니다.
계층 구조 패널의 Library에서 TabView를 드래그합니다.
TabView의 인스펙터 패널에서 다음을 수행합니다.
TabbedMenu
로 설정합니다.TabView에 3개의 탭을 추가합니다. 각 탭에 대해 탭 콘텐츠를 표시하는 자식 요소로 레이블을 추가합니다.
TabView 아래에 3개의 탭을 추가합니다.
각 탭의 인스펙터 패널에서 Label을 다음 값으로 설정합니다.
London
Paris
Ottawa
View Data Key를 다음 값으로 설정합니다.
LondonTab
ParisTab
OttawaTab
계층 구조 패널에서 각 탭에 레이블을 추가합니다.
각 레이블의 인스펙터 패널에서 Text를 다음 값으로 설정합니다.
London is the capital city of England
Paris is the capital of France
Ottawa is the capital of Canada
USS를 사용하여 탭과 탭 콘텐츠의 레이아웃을 정의합니다. 원하는 대로 탭과 탭 콘텐츠의 스타일을 지정할 수 있습니다. 이 예시에서는 선택한 탭에 대한 배경 컬러를 추가하고 탭 헤더 밑줄을 숨깁니다.
Assets
폴더에서 TabbedMenu.uss
라는 스타일시트를 생성합니다.
TabbedMenu.uss
를 열고 다음 스타일 규칙을 추가합니다.
[!code-css[(Modules/UIElements/Tests/UIElementsExamples/Assets/ui-toolkit-manual-code-examples/create-tabbed-menu/TabbedMenu.uss)]]
TabbedMenu.uxml
을 더블 클릭하여 UI 빌더에서 엽니다.
StyleSheets 패널에서 + > Add Existing USS를 선택합니다.
이전에 생성한 USS 파일을 선택합니다.
탭 아래 각 레이블에 .tab-content
를 적용합니다.
완료된 TabbedMenu.uxml
은 다음과 같이 표시됩니다.
[!code-xml[(Modules/UIElements/Tests/UIElementsExamples/Assets/ui-toolkit-manual-code-examples/create-tabbed-menu/TabbedMenu.uxml)]]
SampleScene에서 UIDocument 게임 오브젝트를 생성하고 UI 문서를 소스 에셋으로 추가합니다. 게임에 탭 메뉴를 연결하는 MonoBehaviour 스크립트를 생성합니다.
SampleScene에서 GameObject > UI Toolkit > UI Document를 선택합니다.
Assets
폴더에서 다음 콘텐츠가 포함된 TabbedMenu.cs
라는 C# 스크립트를 생성합니다.
[!code-cs[(Modules/UIElements/Tests/UIElementsExamples/Assets/ui-toolkit-manual-code-examples/create-tabbed-menu/TabbedMenu.cs)]]
SampleScene에서 UIDocument를 선택합니다.
인스펙터 창의 Source Asset 목록에서 TabbedMenu.uxml을 선택합니다.
Add Component 목록에서 TabbedMenu.cs
를 선택합니다.
플레이 모드를 시작합니다.
여러 콘텐츠를 볼 수 있도록 여러 탭을 선택합니다.
탭을 드래그하여 순서를 변경합니다.
커스텀 에디터 창을 생성하고 탭 메뉴를 추가합니다. 탭을 드래그하여 순서를 변경할 수 있습니다. 에디터 창을 닫고 다시 열면 탭 순서가 저장됩니다.
Assets
폴더에서 Editor
라는 폴더를 생성합니다.
Editor
폴더에서 다음 콘텐츠가 포함된 TabbedMenuEditorWindow.cs
라는 C# 스크립트를 생성합니다.
[!code-cs[(Modules/UIElements/Tests/UIElementsExamples/Assets/ui-toolkit-manual-code-examples/create-tabbed-menu/Editor/TabbedMenuEditorWindow.cs)]]
에디터에서 Window > Tabbed Menu를 선택합니다.
여러 콘텐츠를 볼 수 있도록 여러 탭을 선택합니다.
탭을 드래그하여 순서를 변경합니다.
에디터 창을 닫고 다시 엽니다. 탭 순서가 저장되었습니다.
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.