Sample UI

The coherence Sample UI is a prefab that you can add to your scene that handles interaction with coherence services. It is made up of a Unity UI Canvas and includes everything needed to handle connection to coherence.

The Connect Dialog Selector component on the root of the prefab allows us to switch between using Rooms or Worlds each of these methods has a dedicated dialog for connection.

The Auto Reconnect components are used by Simulator builds. The relevant Auto Reconnect component is also enabled when switching between Rooms and Worlds.

To learn more about simulators see Simulators

The Rooms Connect Dialog has a few components that facilitate usage of Rooms.

At the top of the dialog is a dropdown for region selection. This dropdown is populated when regions are fetched and automatically selects the first one available.

Due to current limitations the local server is fetched only if it's started before you enter play mode. The Allow local checkbox must also be checked.

This effects the local region for Rooms and the local worlds for Worlds.

Next the dialog holds an input field for the players name.

Beneath these elements is a tab group with two sections.

The first section holds a list of rooms fetched from the currently selected region. The user can select one of these rooms and connect to it using the join button. On the left of this tab is a button to refresh the rooms list, fetching them again. This refresh is also triggered whenever the selected region is changed.

The second section is used for room creation. Two input fields allow us to specify a room name and a maximal number of players.

The buttons at the bottom of this section then allow the creation of a room with the specified parameters. The Create and Join button allows the user to automatically connect to the room that was created by the request right away.

The Worlds Connect Dialog is much simpler. It holds a dropdown for world selection, an input field for the players name, and a connect button.

The dropdown is populated when worlds are fetched and automatically selects the first one available.

The connect button tells the client to connect to the selected world.

Note: You can also build your own interface to connect players to the server using thePlayResolverAPI to learn more about the API see PlayResolver, Rooms or Worlds according to what your project needs.

Last updated