PhotonNetwork.GetRoomList C# (CSharp) Method

GetRoomList() public static method

Gets an array of (currently) known rooms as RoomInfo. This list is automatically updated every few seconds while this client is in the lobby (on the Master Server). Not available while being in a room.
Creates a new instance of the list each time called. Copied from networkingPeer.mGameList.
public static GetRoomList ( ) : RoomInfo[]
return RoomInfo[]
    public static RoomInfo[] GetRoomList()
    {
        if (offlineMode)
        {
            return new RoomInfo[0];
        }

        if (networkingPeer == null)
        {
            return new RoomInfo[0]; // Surpress erorrs when quitting game
        }

        return networkingPeer.mGameListCopy;
    }

Usage Example

Ejemplo n.º 1
0
    /*
     * Renders the lobby room and player create menu
     */
    void OnGUI()
    {
        // lobby
        if (gameState == GameState.InLobby)
        {
            GUILayout.BeginArea(new Rect(Screen.width / 2 - 150, Screen.height / 2 - 150, 300, 300));

            playerName = GUILayout.TextField(playerName);
            roomName   = GUILayout.TextField(roomName);
            if (GUILayout.Button("Create"))
            {
                PhotonNetwork.JoinOrCreateRoom(roomName, null, null);
            }

            // Display a list of available rooms on the server
            foreach (RoomInfo game in PhotonNetwork.GetRoomList())
            {
                if (GUILayout.Button(game.name + " " + game.playerCount + "/" + game.maxPlayers))
                {
                    PhotonNetwork.JoinOrCreateRoom(game.name, null, null);
                }
            }

            GUILayout.EndArea();
        }

        // room
        if (gameState == GameState.InRoom)
        {
            GUILayout.BeginArea(new Rect(Screen.width / 2 - 150, Screen.height / 2 - 150, 300, 300));
            GUILayout.Box("Your current score: " + PhotonNetwork.player.GetScore());

            // Class selection
            GUILayout.Label("Choose your class");
            if (GUILayout.Button("SWAT"))
            {
                spawnPlayer(SWAT);
            }
            if (GUILayout.Button("Assault"))
            {
                spawnPlayer(Assault);
            }

            GUILayout.Label("");
            if (GUILayout.Button("Quit room"))
            {
                PhotonNetwork.Disconnect();
                SceneManager.LoadScene(0);
            }

            GUILayout.EndArea();
        }

        if (gameState == GameState.Die)
        {
            GUILayout.BeginArea(new Rect(Screen.width / 2 - 150, Screen.height / 2 - 150, 300, 300));
            GUILayout.Box("You Died");

            if (GUILayout.Button("Back to room"))
            {
                PhotonNetwork.Destroy(ragDoll);
                OnJoinedRoom();
            }

            GUILayout.EndArea();
        }
    }
All Usage Examples Of PhotonNetwork::GetRoomList