Search Unity

Question Sample Menu system using UI Toolkit

Discussion in 'UI Toolkit' started by Ruchir, Oct 23, 2021.

  1. Ruchir

    Ruchir

    Joined:
    May 26, 2015
    Posts:
    934
    I'm really struggling with creating anything beyond the most basic custom UI editors and runtime UI when using UI elements.

    Could some share some sample Menu created using UI toolkit that I could use as a reference to learn about using it at runtime.

    My current way of creating a menu system is too crude to be the manageable:(. I have to create new UI document and script for each of the menu panel and I activate/Deactivate gameObjects (with UIDocument component) based on which Panel (say audio or display setting) is enabled. There must be a better to do all these generic system for sure. (Should I create a custom element for each panel?)
    Any help is appreciated. :)
     
  2. burningmime

    burningmime

    Joined:
    Jan 25, 2014
    Posts:
    845
    I have different pages, each of which has a UXML and a code-behind C# file. When I switch to a different page, I add in that page and remove the old one (after some animations). The source code isn't really commented, but if you want to see...

    Folder with everything UI-related: https://gitlab.com/burningmime/urpg/-/tree/master/Assets/main/ui
    The menu "host" which controls switching pages: https://gitlab.com/burningmime/urpg/-/blob/master/Assets/main/ui/MenuHost.cs
    Base class for all menu pages: https://gitlab.com/burningmime/urpg/-/blob/master/Assets/main/ui/MenuPageBase.cs
    Settings page: https://gitlab.com/burningmime/urpg/-/blob/master/Assets/main/ui/SettingsPage.cs
     
    Ruchir likes this.