StrixConnectUI

You can use a ready-made prefab to try out Strix features or do some quick prototyping.

The StrixConnectUI prefab allows you to instantly connect to the master server and join a room (or create a new room if none exists), all without writing any script codes.

Setting up the prefab

First, you have to add the prefab to the scene. (It is in Assets > Strix > GUI > Scripts folder.)

StrixConnectUI in Assets folder

It has a child object called StrixConnectPanel, which is attached two STRIX script components: StrixConnectGUI and StrixEnterRoom. Focus on the StrixConnectGUI first.

StrixConnectPanel

Before running the game, you have to specify the Host, Port, and Application Id properties of the script to match with your server.

  • The Host is the address of the master server, called Master Hostname on Strix Cloud.

  • The Port is always 9122 when using Strix Cloud, so just use the default value.

  • The Application Id is used to identify your application, which is assigned by Strix Cloud.

You can find your servers’ Master Hostname and Application ID on the Application Dashboard on Strix Cloud.

You can also adjust the log level using this component on Inspector. For more information about log level, see Log Level.

StrixConnectGUI on Inspector

Note

Make sure your scene has an EventSystem, otherwise the UI buttons won’t work. To add an EventSystem, use the menu GameObject > UI > Event System, or right-mouse button click in an empty space of the scene hierarchy and then from the context menu choose UI > Event System.

Using the prefab

You can now run the scene in the Play Mode in the Editor (or from a packaged build).

When the scene is loaded and the prefab is instantiated, it shows the UI with a field to enter a player name and a Connect button. The name will be assigned to your room member. If you leave the name empty, your room member’s name will be empty.

As you press the Connect button, the script will try to connect to the master server. If it succeeds, it will then join a random existing room or create a new one if no suitable room was found. After that, the UI will disappear.

Now, you should be in a STRIX room. If you (or your colleagues) run the same program using the same server, they should be in the same room, too.

Note

If you add the StrixConnectUI prefab to an empty scene and run, nothing interesting happens after the UI disappears. You need to add to the scene more GameObjects, especially replicated ones, to experience the multiplayer gameplay.

Please read other pages of this guide to know how to do it.

Events

The two STRIX scripts in this prefab provide several events that you can use to add your own logic to it. Since all events are implemented using UnityEvents, you can write handlers in your own scripts add them easily.

The following events are available:

Script component

Event

Description

StrixConnectGUI

OnConnect

Called back when connected to the master server.

StrixEnterRoom

OnRoomEntered

Called back when successfully joined a room (possibly after creating it).

StrixEnterRoom

OnRoomEnterFailed

Called back when an attempt to join a room was unsuccessful.

For example, if you want to run some code after joining/creating a room, you can write the handler and then add it to the OnRoomEntered event through the inspector.

OnRoomEntered and OnRoomEnterFailed

Be careful though, if you attach your script to handle StrixConnectUI‘s events to the GameObject of the StrixConnectUI prefab itself or to its child GameObject, your script will get disabled as soon as the master server connection is established (and all the event handlers have been executed). You should attach your script to a separate GameObject in the scene if you start a coroutine in your script, for example.

Please also note that StrixConnectGUI.OnConnect already has a handler, which is StrixEnterRoom.EnterRoom(). That’s why you will join a room immediately after you are connected to the master server. You should keep it unless you are replacing it with an alternative handler (such as the one the StrixRoomList prefab provides).

Using on the WebGL platforms

Beginning with Strix Unity SDK version 1.5.0, you can specify a URL-style string in the Host property of the StrixConnectGUI script. It is useful to use this prefab for WebGL applications.

When you type in a URL-style string in Host on Inspector, the Port field grays out, because the port number is taken from the Host string. If you omit the port number in the URL-style host string, the default for the specified protocol is used.

For example, you can set a string like "wss://000000000000000000000000.game.strixcloud.net:9122" to Host when you are connecting to a master server on Strix Cloud that is configured to use a secure WebSocket connection.

Example Inspector behavior for a URL-style host string

See URL-based connection for the syntax of the URL-style string. Also see How to Create an HTML5 and WebGL Client for the WebGL support.