ServerConnection¶
The core of the plugin is the ServerConnection component. This component handles all aspects of connection and communication with the PlayReal Scalable Server
You can only use the ServerConnection component or you can build your game upon the game architecture proposed in the sample.
Access to the documentation of Scalable Server: http://ssdoc.asmodee.net
Integration¶
Create an object in the hierarchy containing the PlayReal Manager script. This is the script that hosts the unique instance of ServerConnection.
We wish that this component is unique throughout the lifetime of the game. It is then necessary to ensure that the object containing the PlayReal Manager script is never destroyed during the scene change
- Create the object which we call Manager
Renaming the object to Manager
- Add PlayReal Manager component to the Manager object
- Select the setting by clicking the circle to the right of the parameter Network Parameters
In the Assets tab, select the desired parameter
- Add the component Singleton in the Manager object
Singleton component visible under the PlayReal Manager :
Use¶
Communication with the Scalable Server is done asynchronously. A request is sent to the server and the component waits for a response. When it receives the response, it raises an event.
Connection and authentication of a user :
- Subscribe to the events
ConnectedToServerEvent.AsyncConnectedEvent
NetworkManager.Instance.ServerConnection.ConnectedToServerEvent += ServerConnection_ConnectedToServerEvent;
NetworkManager.Instance.ServerConnection.AsyncConnectedEvent += ServerConnection_AsyncConnectedEvent;
- Creation of methods called when events are fired
private void ServerConnection_ConnectedToServerEvent()
{
NetworkManager.Instance.ServerConnection.AuthenticateUser("login", "password");
}
private void ServerConnection_AsyncConnectedEvent(AsyncConnectedRequest asyncConnectedRequest)
{
Debug.Log(string.Format("User {0} is authenticated", asyncConnectedRequest.player.name));
}
- Deleting events
private void Dispose()
{
NetworkManager.Instance.ServerConnection.ConnectedToServerEvent -= ServerConnection_ConnectedToServerEvent;
NetworkManager.Instance.ServerConnection.AsyncConnectedEvent -= ServerConnection_AsyncConnectedEvent;
}