Interfaces (UI)
A panel of your world is a Unity canvas with uGUI controls and TextMeshPro texts, built in the editor as usual. Your script reads and changes them, and listens to their events.
The canvas
Make it World Space, with a Tracked Device Graphic Raycaster (players click it with their controller's ray in VR) and a Graphic Raycaster (with the mouse pointer), as the panels of the example world. Players click it as they click the menu (controls). A canvas drawn on the screen (Screen Space - Overlay) stays under NodeWorld's own interface (what a script cannot block).
Listen to a control
using NodeWorld.Flux;
namespace MyWorld
{
[ClientOnly]
public class LightPanel : FluxScript
{
public Light lamp;
public Slider brightness;
public Toggle on;
public Text label;
protected override void Start()
{
brightness.onValueChanged.AddListener(value => lamp.intensity = value);
on.onValueChanged.AddListener(value => lamp.enabled = value);
label.text = "Lamp";
}
}
}A listener runs in the script that added it. One that throws stops its script, as a callback does. RemoveListener and RemoveAllListeners take them off.
These listeners run on the game of the player who clicks: to change the world for everyone, sync it (synced objects and values).
The components
| Component | What a script uses |
|---|---|
Text (TextMeshPro, 3D or UI, or a UI Text) | text, color, fontSize |
Image (an Image with a sprite, or a Raw Image with a texture) | sprite, texture, color, fillAmount |
Button | onClick |
Slider | value, minValue, maxValue, wholeNumbers, SetValueWithoutNotify, onValueChanged |
Toggle | isOn, SetIsOnWithoutNotify, onValueChanged |
Dropdown (uGUI or TextMeshPro) | value, optionCount, GetOption, SetOption, AddOption, ClearOptions, SetValueWithoutNotify, onValueChanged |
InputField (uGUI or TextMeshPro) | text, placeholder, isFocused, onValueChanged, onEndEdit, onSubmit |
Scrollbar | value, size, onValueChanged |
ScrollRect | normalizedPosition, horizontalNormalizedPosition, verticalNormalizedPosition, onValueChanged |
CanvasGroup | alpha, interactable, blocksRaycasts |
RectTransform | anchoredPosition, sizeDelta, anchorMin, anchorMax, pivot, GetWorldCorners, ForceRebuildLayout |
Canvas | enabled |
Every control (Button, Slider, Toggle, Dropdown, InputField, Scrollbar) has interactable and Select(). The …WithoutNotify methods change a value without running its listeners: use them to show a value that came from the network.
Text fields
A player who selects an Input Field types in it with the NodeWorld keyboard in VR, or their keyboard on a computer; Select() gives it the keyboard from a script. Read text, and listen to onSubmit (the player pressed Enter, or the blue key of the VR keyboard) or onEndEdit (they left the field). While a player types, your scripts get no key. See text fields.
A text above an object
The small text a player sees when pointing at an object ("Sit", "Ring") is not a canvas: it is Interaction.SetText (interaction and input).
