The SDK of this version is still being tested, and these pages are being updated with it: names, menus and procedures may still change before the release. If you build content for a platform already in production, follow the documentation of that version — pick it from the version menu at the top right.
UI panels
The SDK ships a set of UI Toolkit panels for environments: a text panel with buttons, a list, a check mark, a label, a choice, a HUD, and the host of toasts and popups. They are scene prefabs, in Packages > Virtuademy-SDK-Environments > Common > Prefabs > UI > Toolkit. They wear the Virtuademy theme, so they follow the tenant's colours, and every text takes a localization key.
They are the successors of the uGUI prefabs of Common > Prefabs > UI:
| Panel | Replaces | Use it for |
|---|---|---|
| Virtuademy Panel | DescriptionCanvas, DescriptionWarningCanvas, Wrong_DescriptionCanvas, WelcomePanel, ConfirmPopup, Default_Canvas | A description, a hint, a warning, a right or wrong answer, a welcome, a confirmation |
| Virtuademy List Panel | ListItemCanvas | A checklist: "find these four things" |
| Virtuademy Check Mark | CheckCompleted | A check mark or a cross at a point of the world |
| Virtuademy Label | Hover_DescriptionCanvas | A short text on what the pointer is on |
| Virtuademy Choice Panel | none | "What do you do next?": one question, a column of options |
| Virtuademy HUD | AnimatedScreenCanvas | A counter with a progress bar, and a hint |
| Notification Host | none | The toasts and popups of IUIApi |
The uGUI prefabs still work and published environments keep them. For new work, use these.
How a panel works
- Drag the prefab into your scene.
- Write its texts in the Inspector. Each text has a Key (a key of the Localization File) and a Text. With a key, the panel shows its translation and follows language changes; when the key is empty, or the file has no translation for it, it shows the text as written.
- Wire its events (the Events foldout) to the rest of your scene, for example On Primary to a task or to an object's method. A panel holds no logic of the step it belongs to.
- Show and hide it. Visible On Start says whether it shows when the scene starts; otherwise call its
Show(). A hidden panel takes no clicks and no rays.
All of them can also be driven from a script, through IUIApi, and from a graph through the component's methods.
Where they are drawn
| Panel | Desktop and WebGL | Mobile | VR |
|---|---|---|---|
| Panel, List, Choice | In the world, where you place it | In the world | In the world |
| Check Mark, Label | In the world | In the world | In the world |
| HUD, Notification Host | Over the screen, inside the safe frame | Over the screen, inside the safe frame | A panel floating in front of the player (see In VR) |
World panels are objects of the scene, on layer 0: a wall in front of them hides them like any geometry, and the mouse, the finger and the VR ray click their buttons. Screen panels are drawn over the view, under the application's own UI Toolkit panels.
Sizes. In the world, one UI pixel is one millimetre. A Virtuademy Panel is 640, 960 or 1280 px wide (S, M and L, the classes vd-panel--s, --m, --l): the default M panel is 0.96 m wide, and its 28 px body text is 28 mm high. Place a panel where it is read from 1.2 to 2 m. On a screen the panels are laid out for a 1920 x 1080 reference and scaled to the real screen.
Only the controls are clickable. The surface, the texts and the icons of a panel let the click through: only its buttons (and a choice's options) catch it.
Virtuademy Panel
Virtuademy Panel (Virtuademy > UI > Virtuademy Panel). An optional round icon, a title, a text and up to two buttons.
The prefab VirtuademyPanel comes with six variants, which differ only by their role, their texts and their buttons:
| Prefab | Variant | Default texts |
|---|---|---|
VirtuademyPanel | Default | A description |
VirtuademyPanel_Hint | Hint | "A tip for this step." and a button OK |
VirtuademyPanel_Warning | Warning | "Something needs your attention." and OK |
VirtuademyPanel_Error | Error | "That is not the right choice." and Try again |
VirtuademyPanel_Success | Success | "That is right." and Continue |
VirtuademyPanel_Welcome | Default | "What you will do in this training." and Start |
VirtuademyPanel_Confirm | Default | "Confirm your choice." with Back and Confirm |
The Variant picks the colour of the accent bar and of the icon (the roles Info, Warning, Error and Success): Default, Hint, Warning, Error, Success. Show Icon draws the icon.
| Field | What it does |
|---|---|
| Title, Body | The texts |
| Primary Button | The button on the right, in the action colour. Empty text and key: no button |
| Secondary Button | The outlined button on the left. Empty: no button |
| Visible On Start | Shown when the scene starts |
| Hide On Button | Hide the panel when either button is pressed (on by default) |
Events: On Shown, On Hidden, On Primary (Continue, Confirm, Start), On Secondary (Back, Cancel).
Methods: Show, Hide, SetTitle, SetText (each with the text as written, or with a key and a fallback), SetPrimaryLabel, SetSecondaryLabel, and the property Variant.
In VR the panel catches the ray only while it is shown and has a button: a panel with only a title and a text lets the ray through to what is behind it.
Virtuademy List Panel
Virtuademy List Panel. A title and a list of items, each with a marker that fills when the item is done, and an optional accent on the current one. For a step such as "find the four hazards".
| Field | What it does |
|---|---|
| Title | The heading |
| Items | The rows: a text each, and whether it starts done |
| Current Index | The row accented as the current one; -1 for none |
| Visible On Start | Shown when the scene starts |
Events: On Item Done (with the row's index) and On All Done. Methods: Show, Hide, SetDone(index, done), MarkDone(index), SetCurrent(index), SetItems(texts) (texts as written, all not done), ResetItems().
On All Done is raised when marking a row done completes the list.
Virtuademy Check Mark
Virtuademy Check Mark. A round check mark (right) or a cross (wrong) that pops in at a point of the world, for the answer to an action.
| Field | What it does |
|---|---|
| State On Start | Hidden, Correct or Wrong |
| Auto Hide Seconds | Seconds before it hides by itself; 0 keeps it shown |
Events: On Shown Correct, On Shown Wrong, On Hidden. Methods: ShowCorrect, ShowWrong, ShowResult(correct), Hide.
It has no collider, so it never catches a click or a ray.
Virtuademy Label
Virtuademy Label. A short text on a dark pill in the world. It is meant for what the pointer is on: show it from the hover events of an Interactable and hide it on hover exit.
| Field | What it does |
|---|---|
| Text | The text |
| Visible On Start | Off by default: call Show |
| Face Camera | Turn to the user, upright, around the vertical axis (on by default) |
Methods: Show, Hide, SetText. It has no collider.
Virtuademy Choice Panel
Virtuademy Choice Panel. A question with a column of options. It is for branching ("What do you do next?") and for select-and-confirm steps. A scored question with right and wrong answers is the Quiz.
| Field | What it does |
|---|---|
| Title, Prompt | The question and an optional line under it |
| Options | One text per option |
| Confirm Choice | Off: a press chooses. On: a press selects, and the confirm button chooses |
| Confirm Label | The text of the confirm button |
| Hide On Choice | Hide the panel once an option is chosen (on by default) |
| Visible On Start | Shown when the scene starts |
Events: On Option Selected (with the index, in confirm mode) and On Option Chosen (with the index). Methods: Show, Hide, SetOptions(texts), Confirm(); SelectedIndex is -1 until something is selected.
Virtuademy HUD
Virtuademy HUD. A counter ("Found 2/5") with a progress bar, a hint box and a hint button. It stays on the screen, at the top right of the safe frame; in VR it floats at the lower right of the view.
| Field | What it does |
|---|---|
| Counter Label | The label left of the counter |
| Hint Button Label | The text of the button; empty text and key: no button |
| Hint On Request | The hint the button shows (a second press hides it). Empty: the button only raises On Hint Requested, and you show the hint yourself |
| Max Count, Count | The counter |
| Visible On Start | Shown when the scene starts |
Events: On Hint Requested, On Count Changed (with the new value), On Completed (the count reached the maximum). Methods: Show, Hide (it slides in and out), SetMaxCount, UpdateCount, Increment, DisplayHint(text), HideHint, RequestHint (the same as pressing the button), SetHintOnRequest.
The prefab carries a Safe Frame set to Edges and an Overlay Panel Placement.
Notification Host
Notification Host. It draws the toasts and the popup that scripts and graphs ask for. You do not need one in your scene: the application provides its own. Place the prefab only to restyle them. See Toasts and popups.
In VR
The HUD and the Notification Host are overlays. With Overlay Panel Placement (on their prefabs), in VR each becomes a world panel in front of the player, placed when it is enabled:
| Overlay | Size | Position |
|---|---|---|
| Notification Host | 1.4 x 0.9 m | 1.4 m in front, 0.1 m below the eyes, centred |
| HUD | 0.52 x 0.38 m | 1.6 m in front, 0.55 m below the eyes, 0.9 m to the right |
The panel is placed in front of the head when it appears and then goes with the player's body, not with the head: walking, teleporting and turning with the controller carry it along, and turning the head does not move it. The method RecentreNow() of the component brings it in front of the player again (call it from a UnityEvent or a graph). Its settings are on the component: Vr Size, Vr Distance, Vr Height Offset, Vr Side Offset, Vr Follow Head (off: it stays where it was placed) and Vr Hide While Help Open.
The panels let the ray through where nothing is shown. A world document gets a collider the size of the whole panel, and a controller ray stops at it, so the SDK turns the collider off whenever the panel has nothing to press:
- the Notification Host catches the ray only while a popup is open (toasts take no clicks);
- the HUD catches it only while it is shown with its hint button;
- a Virtuademy Panel only while shown with a button; a list or a choice only while shown; the label and the check mark never.
While the application's tutorial (help) panel is open, Vr Hide While Help Open (on by default) hides the overlays and lets the ray through, because that panel is where the user must point. A script can read the same state: see IHelpApi.IsOpen.
The controller ray hits the collider of any panel that is shown. A world panel with a button that stands in front of the tablet, the tutorial or another panel of the application takes the ray meant for them. Keep your panels out of the way of where the user opens the tablet, and hide them while Help.IsOpen or Tablet.IsOpen are true.
From a script
A script cannot reference the panel components (they belong to assemblies the security rules do not allow), so it drives them through their GameObject with IVirtuademyGameplay.Current.UI. Each call returns false when the object has no panel it applies to.
| Call | What it does |
|---|---|
ShowPanel(go), HidePanel(go) | Show or hide the panel on go |
SetPanelText(go, title, text) | Set the texts as written. A panel: title and body. A choice: title and prompt. A list: title. A label: the text. A null argument leaves that text alone |
SetPanelVariant(go, variant) | The variant of a Virtuademy Panel (EPanelVariant: Default, Hint, Warning, Error, Success) |
SetHudCount(go, count, max = -1) | The counter of a HUD; a negative max keeps the maximum |
SetHudHint(go, hint) | The hint of a HUD; empty hides it |
SetListItemDone(go, index, done) | Mark a row of a list done or not |
ShowCheckResult(go, correct) | The check mark or the cross |
PanelButtonPressed | Event (GameObject panel, int index), for a button of any SDK panel of the scene. The index is 0 for the primary button, 1 for the secondary, the option's index on a choice panel, and 0 for the HUD's hint button |
PanelButtonHandler is a type of the SDK: write a method with the same shape and subscribe it, with no delegate declaration of your own.
using UnityEngine;
using Virtuademy.Environments.ScriptingApi;
public class HazardCounter : MonoBehaviour
{
[SerializeField] private GameObject hud;
[SerializeField] private GameObject confirmPanel;
private int found;
private void Start()
{
if (!IVirtuademyGameplay.IsAvailable)
{
return;
}
IVirtuademyGameplay.Current.UI.PanelButtonPressed += OnPanelButton;
}
private void OnDestroy()
{
if (IVirtuademyGameplay.IsAvailable)
{
IVirtuademyGameplay.Current.UI.PanelButtonPressed -= OnPanelButton;
}
}
// Hook this to the On Interact of each hazard.
public void HazardFound()
{
found++;
IVirtuademyGameplay.Current.UI.SetHudCount(hud, found);
}
private void OnPanelButton(GameObject panel, int index)
{
if (panel == confirmPanel && index == 0)
{
IVirtuademyGameplay.Current.UI.ShowPanel(hud);
}
}
}
What not to do
- Do not put your logic in a panel. Its events say that something was pressed; the step that reacts is in the scene, a task or a graph.
- Do not set a localized text from a script with
SetPanelTextif it must follow the language: it is shown as written. Use the Key field, or translate it again onLanguageChanged(see Texts and languages). - Do not colour a panel with a value. Use the theme's roles (see Theme), or the tenant's colours do not reach it.
- Do not leave a world panel in front of what must be clicked. A panel with a button catches the click and the ray over its whole area.