UI Element는 유니티의 에디터를 확장하거나 바꿀 수 있는 기능이다.
예시)
UI Element 생성
Create - UI ToolKit - Editor Window
UXML 체크 해제 후 Confirm을 누른다.
그러면 Editor 폴더에 파일이 추가되고 창 하나가 생기는 것을 볼 수 있다.
UI Element 편집
UIElement를 사용하기 위해서는 두가지 네임스페이스가 있어야 한다. 생성시에 자동으로 추가된다.
using UnityEngine.UIElements;
using UnityEditor.UIElements;
VisualElement.Add
VisualElement.Insert
public void CreateGUI()
{
VisualElement container = new VisualElement();
rootVisualElement.Add(container);
Label title = new Label("Color Picker");
ColorField colorField = new ColorField();
container.Add(title);
container.Add(colorField);
VisualElement buttonsContainer = new VisualElement();
rootVisualElement.Add(buttonsContainer);
Button randomColorButton = (Button)CreateButton("Random Color");
Button resetColorButton = (Button)CreateButton("Reset Color");
Button copyColorButton = (Button)CreateButton("Copy Color");
Button pasteColorButton = (Button)CreateButton("Paste Color");
buttonsContainer.Add(randomColorButton);
buttonsContainer.Add(resetColorButton);
buttonsContainer.Add(copyColorButton);
buttonsContainer.Add(pasteColorButton);
container.Add(buttonsContainer);
}
public VisualElement CreateButton(string text)
{
return new Button() { text = text };
}
'Unity' 카테고리의 다른 글
URP Asset Settings (1) | 2022.12.22 |
---|---|
URP 설정하기 (0) | 2022.12.22 |
Playfab - 4 가상화폐, 상점, 아이템, 인벤토리 (0) | 2022.10.31 |
Playfab - 3 statistics(통계), int | Data(플레이어 데이터), string 저장 (0) | 2022.10.28 |
Playfab - 2 playfab 로그인 회원가입 기능 (0) | 2022.10.23 |