Newb, Architecture CheckList/Confirmation Thread

Options
Hi there,
I am building out my first Multiplayer game and I want to make sure my architecture is correct.

In my game, I load the home level (non - photon). I present the option of solo, offline play or multi, online.

If player selects multi, online, I take them to the lobby scene.

The lobby scene manager, is a Photo.PunBehavior. It's code is very simple. It must do two things... a) if not connected to the network, connect. b) wait for 2 players to be in room. If true, loadlevel.
using UnityEngine;
using System.Collections;
using Photon;


namespace Com.YahManGames.GolfyWorld{

	public class LobbyManager : Photon.PunBehaviour {


        #region Private Variables
		/// <summary>
        /// This client's version number. Users are separated from each other by gameversion (which allows you to make breaking changes).
        /// </summary>
        string _gameVersion = "1";
		#endregion



		// Use this for initialization
		void Start () {
			///here, we have a player who has entered this lobby. He must wait for one competitor.
			Connect();

		}

		void Connect(){

            // we check if we are connected or not, we join if we are , else we initiate the connection to the server.
            if (PhotonNetwork.connected)
            {
          		//do nothing, we wait for a 2 player count in room.
            }else{
                // #Critical, we must first and foremost connect to Photon Online Server.
                PhotonNetwork.ConnectUsingSettings(_gameVersion);
            }
		}



		void Update(){
			int count = PhotonNetwork.playerList.Length;
			if(count == 2){
				int rdmRoom = Random.Range(0, 10);
				PhotonNetwork.LoadLevel(rdmRoom);
			}
		}
	}

}



Can someone conform that this makes sense?

Thanks

Comments

  • Hi Renman3000, again I guess,

    nope, the above posted code doesn't work, because you are never joining any room and the client stays in the lobby.

    You told that the player can choose between offline and online mode. Maybe it is a good idea to connect to Photon, when the player decides to play in multiplayer mode. When going this way you can implement the OnConnectedToPhoton() or OnJoinedLobby() callback, to load another scene, the lobby scene in this case. Now if I guess things right, the player doesn't have any choice for selecting a room on his own, but he is automatically assigned to a room (if one is available he joins it, otherwise he creates a room and joins it afterwards). When inside the a room, the Master Client can wait for the OnPhotonPlayerConnected(PhotonPlayer other) callback and start the game, if a certain number of players is in the room.

    If you don't have already, I recommend you take a look at the PUN Basics Tutorial, because it has some good hints and some comparable behaviours to your scenario.