Unity UI Builder / UIElements

Windows >> UI Toolkit >> UI Builder

Zapisz layout
Dodaj nowy stylesheet, dodaj klasę
Stwórz elementy UI (Visual Element jako parent + dodatkowe elementy)

W oknie Unity Hierarchy >> Create >> UI Toolkit >> UI Document
W polu Source Asset dodaj stworzony wcześniej layout

Dodaj nowy skrypt cs:

using UnityEngine;
using UnityEngine.UIElements;

public class MyUI : MonoBehaviour
{
    void OnEnable()
    {
        VisualElement root = GetComponent<UIDocument>().rootVisualElement;
        Button buttonOne = root.Q<Button>("ButtonOne");
        buttonOne.clicked += () => BtnOne();
    }

    void BtnOne()
    {
        Debug.Log("Button one clicked");
    }

}
Scroll to Top