SebastianLawe

Untitled

Oct 1st, 2015
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.18 KB | None | 0 0
  1.     public void CreateCustomMatch() {
  2.         RoomOptions option = new RoomOptions();
  3.         TypedLobby lobby = new TypedLobby();
  4.         maxPlayers = option.maxPlayers = (byte)((playersDropDown.value + 1) * 4);
  5.         option.customRoomProperties = new ExitGames.Client.Photon.Hashtable();
  6.         option.customRoomProperties.Add("GT", (int)gameType);
  7.         if (PhotonNetwork.room != null) {
  8.             PhotonNetwork.LeaveRoom();
  9.         }
  10.         PhotonNetwork.JoinOrCreateRoom(roomName.ToString(), option, lobby);
  11.         isReadyToStartGame = true;
  12.         DisableMenus();
  13.         if (PageChanged != null) {
  14.             PageChanged(this, EventArgs.Empty);
  15.         }
  16.     }
  17.  
  18.  
  19.     public override void OnConnectedToMaster() {
  20.         if (isMatchMaking && isReadyToStartGame) {
  21.             UnityEngine.Debug.Log("Connected to matchmaking.");
  22.             UnityEngine.Debug.Log(string.Format("Attemting to join game with game type {0}. Attempt {1}", gameType.ToString(), retryAttempts));
  23.             waitingMenuText.text = string.Format("Locating Match, Attempt {0}.", retryAttempts);
  24.             ExitGames.Client.Photon.Hashtable expectedCustomRoomProperties = new ExitGames.Client.Photon.Hashtable() { { "GT", (int)gameType } };
  25.             PhotonNetwork.JoinRandomRoom(expectedCustomRoomProperties, 16);
  26.         }
  27.         if (isCustomGame && isReadyToStartGame) {
  28.             CreateCustomMatch();
  29.         }
  30.     }
  31.  
  32.     void OnPhotonRandomJoinFailed() {
  33.         if (isMatchMaking) {
  34.             if (retryAttempts++ < 5) {
  35.                 OnConnectedToMaster();
  36.             } else {
  37.                 RoomOptions options = new RoomOptions();
  38.                 TypedLobby lobby = new TypedLobby();
  39.                 options.isOpen = true;
  40.                 options.isVisible = true;
  41.                 playersRequiredToStartMatch = maxPlayers = options.maxPlayers = 16;
  42.                 options.customRoomProperties = new ExitGames.Client.Photon.Hashtable();
  43.                 options.customRoomProperties.Add("GT", (int)gameType);
  44.                 PhotonNetwork.CreateRoom(null, options, lobby);
  45.                 UnityEngine.Debug.Log("No rooms found. Creating a new one.");
  46.             }
  47.         }
  48.     }
Advertisement
Add Comment
Please, Sign In to add comment