Skip to main content

Network Events

For listening network events such as player connections, leave, etc, you should implement IRagonListener interface, also you can implement only partial of interface:

  • IRagonAuthorizationListener
  • IRagonConnectionListener
  • IRagonFailedListener
  • IRagonJoinListener
  • IRagonLeftListener
  • IRagonOwnerhshipChangedListener
  • IRagonPlayerJoinListener
  • IRagonPlayerLeftListener

Example setup:

public class GameNetwork : MonoBehaviour, IRagonListener
{
private void Start()
{
RagonNetwork.AddListener(this);
RagonNetwork.Connect();
}
}

Connected to Relay Server

public void OnConnected()
{

}

Disconnected from Ragon Relay

public void OnDisconnected()
{
Debug.Log("Disconnected");
}

Authorized on Relay Server, received server assigned playerId and playerName, and we can join/create room in lobby.

public void OnAuthorized(string playerId, string playerName)
{
Debug.Log("Authorized");
RagonNetwork.Session.CreateOrJoin("Example", 1, 20);
}

Joined successfully to room

public void OnJoined()
{
Debug.Log("Joined");
}

Failed to join to room with the error message

public void OnFailed(string message)
{
Debug.LogError("Failed with " + message);
}

Left successfully from the current room

public void OnLeft()
{
Debug.Log("Left");
}

Another player joined to current room

public void OnPlayerJoined(RagonPlayer player)
{
Debug.Log("On Joined " + player.Name);
}

Another player left the current room

public void OnPlayerLeft(RagonPlayer player)
{
Debug.Log("On Left " + player.Name);
}

New player become owner of room

public void OnOwnershipChanged(RagonPlayer player)
{
Debug.Log("New room owner " + player.Name);
}

The server requested to load a new map, you should load a new scene and call RagonNetwork.Room.SceneLoaded()

public void OnLevel(string sceneName)
{
Debug.Log("Level " + sceneName);
RagonNetwork.Room.SceneLoaded() // Ready to receive updates
}