Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question UI toolkit and new input system - programatically select visual element and improve navigation

Discussion in 'UI Toolkit' started by g-t, Apr 24, 2023.

  1. g-t

    g-t

    Joined:
    Jun 5, 2020
    Posts:
    3
    Hey guys,
    I've been struggling a little bit with UI toolkit + new input system.

    I have a simple main menu and one of its items is Levels.
    upload_2023-4-24_1-14-11.png

    Play, levels, settings and quit are children of LeftSection. When you click Levels I want user to select a level - grid of icons inside scroll view in RightSection.

    Basically playButton.clicked sets display to flex for the scroll:
    levelsScroll.style.display = DisplayStyle.Flex

    so the following right section is being shown:
    upload_2023-4-24_1-19-59.png

    Game controls are based on gamepad / keyboard and not the mouse. My problem is that I have no idea how to programatically navigate to the first level icon (button).

    After levels are being shown keyboard only navigates through main buttons and I can only access levels via TAB button.

    So I have two questions:
    1. How to select first level so the user can only navigate through levels until back button is clicked (not added yet but you can imagine what I mean).
    2. After levels are shown how to disable navigation for main menu buttons.

    It works fine when I set display style for #Buttons to None
    doc.rootVisualElement.Q<VisualElement>("Buttons").style.display = DisplayStyle.None;

    but I just don't want to hide it.

    Any help will be appreciated
     

    Attached Files:

  2. g-t

    g-t

    Joined:
    Jun 5, 2020
    Posts:
    3
    I think I found a solution. It's clumsy but it works. Levels are now being shown in rows (three level / each row). After choosing Levels button I'm simply calling .Focus() on first level:
    upload_2023-4-26_1-43-4.png
    Then I had to override navigation for the button:
    upload_2023-4-26_1-44-39.png

    Overriding of the navigation buttons was necessary because it wasn't logical at all. For example Right wasn't going from first to second level and so on.