Walkthrough: your own menu in UI Toolkit
Shipready's own menus are built with uGUI. If your game's UI is built with UI Toolkit (UXML layouts and USS style sheets), keep it that way: build the save menu in UI Toolkit on Shipready's public API, and keep everything else (slots, autosaves, backups, pictures and world saving). The Own Menu (UI Toolkit) demo does exactly that with one layout, one style sheet and one short script. UI Toolkit is part of Unity, so no package is needed.
1. Try it #
Open Samples/Demos/Scenes/OwnMenuUIToolkitDemo.unity and press Play. A list shows five slots, each with a picture frame and Save, Load and Delete; a used slot also shows its name, date and playtime. Click +1 coin three times, then Save on a slot: the row shows the date, the playtime, "3 coins" and a picture of the scene. Continue loads the newest save; it is greyed out until there is one. Delete empties a slot.
It shares the Own Menu demo's settings and save folder (SaveKitDemos/OwnMenu), so the uGUI and UI Toolkit versions show the same saves, and neither touches your game's saves.
2. The three files #
| File | What it is |
|---|---|
Samples/Demos/UIToolkit/OwnMenuUIToolkit.uxml |
The layout: a panel with a title, the coin count, +1 coin, Continue, a scroll view for the slots and a status line. Open it in UI Builder to move things around. |
Samples/Demos/UIToolkit/OwnMenuUIToolkit.uss |
The look: every colour, size and corner. Change a class here and every row follows. |
Samples/Demos/Scripts/OwnMenu/OwnMenuToolkitDemo.cs |
The script on the scene's UIDocument: it finds the parts by name, adds one row per slot, and calls Shipready. |
OwnMenuUIToolkitPanelSettings.asset and OwnMenuUIToolkitTheme.tss beside them are the panel settings (scaled for 1920 by 1080) and Unity's default runtime theme.
3. Read the script #
The parts that use Shipready are marked 1 to 5, as in the uGUI version:
- List the slots.
SaveKit.GetSlotInfos(list); one row (VisualElementwith theslot-rowclass) per entry. The picture is anImagefilled fromThumbnails.Read(SaveKit.Storage, info.FileName); destroy the texture withThumbnails.DestroyTexturewhen the rows are rebuilt. - Save.
SaveKit.SetSummary(...), a picture fromThumbnailCapture.Capture(Camera.main)withSaveKit.SetNextThumbnail, thenSaveKit.Save(slot). - Load.
SaveKit.Load(slot). - Delete.
SaveKit.Delete(slot). - Continue.
SaveKit.LoadMostRecent()loads the newest slot, autosave or quicksave;SaveKit.HasAnySavedecides whether the button is enabled.
Buttons are hooked up with button.clicked += ... and their state with SetEnabled. Every call returns a result with Success and a plain-English Message for the status line.
4. Make it your own #
Copy the three files into your project and rename them (the script's class too). Then:
- Point the layout at your style sheet: in UI Builder, StyleSheets > Add Existing USS, or change the
<Style src="...">line in the UXML. A layout still naming the old file shows unstyled. - Give the UIDocument a Panel Settings: reuse
OwnMenuUIToolkitPanelSettings, or make one with Create > UI Toolkit > Panel Settings Asset. A UIDocument without one shows nothing. - Keep five names: the script finds
coins,add-coin,continue,slotsandstatus. Rename one in UI Builder and the script says in the Console which it cannot find.
Then change the USS, or design the layout in UI Builder. Everything the uGUI walkthrough lists (confirmations, autosaves, damaged saves, newer versions) works the same way here.
Back to: All walkthroughs.