UI Toolkit Demos repo

Hey all! I decided to start a demo project that will include the things I’m learning about UI Toolkit from this forum and elsewhere. I have an easier time looking learning an API by looking at sample code than I do reading docs. I imagine there are others out there like me, so I hope this will be helpful to someone.

Unity UI Toolkit Demos

It currently includes just one thing: A custom button that loads a uxml template and allows the user to insert child elements.

I’ll be adding a few more things this week.

I have a LOT to learn about UI Toolkit and best practices for it. So, please, if you have time take a look and let me know what might be wrong with the way I’m doing things.

Anyway, hope you all like it.

(And big thanks to Kenney Assets for the sprites used)

1 Like

This is a great idea. It would be great if there was a place with a list of helpful tutorials and demos. Unfortunately many of the beginner tutorials that I have found are out of date.

I agree. I’ll start a new thread where people can post links to resources that have been helpful and whether they are still relevant.

[EDIT] - here’s the thread. Please post if you have something. https://discussions.unity.com/t/882507

Tonight I added a simple Message Box dialog, the the kind used in Windows for “are you sure?” type interactions. It’s not exactly modal like in Windows as it requires you to subscribe to a Closed event.

Setup is fairly easy, add the MessageBoxController script to your UIDocument game object (I used that one to also attach my UiManager):

Grab the component:

_messageBox = GetComponent<MessageBoxController>();

Subscribe to it’s Close event:

_messageBox.Closed += OnMessageBoxClosed;

Call _messageBox.Show();

_messageBox.Show("Help, help, I'm bring repressed!", text, MessageBoxButtons.OkCancel, MessageBoxIcon.Information);

Evaluate the result:

private void OnMessageBoxClosed(bool isOk)
{
    _messageBox.Closed -= OnMessageBoxClosed;
    Debug.Log($"{this.GetType().Name} - OnMessageBoxClosed, isOk={isOk}");
}