Beispiel #1
0
        /// <summary>
        /// Joins a random Photon room that matches with the given options. The matchmaker's state must be <see cref="ConnectionState.Connected"/>.
        /// </summary>
        /// Note that Photon will be connected to any found room instantly.
        /// See <see cref="LoadBalancingClient.OpJoinRoom"/> for more information.
        ///
        /// <inheritdoc cref="IMatchmaker.FindRandomGame"/>
        /// <param name="options">The <see cref="PhotonJoinRandomGameOptions"/> used to find a random game</param>
        /// <returns>An observable resolving with the <see cref="PhotonAlreadyJoinedGame"/> that was joined.</returns>
        /// <exception cref="ArgumentException">If <see cref="options"/> is not of type <see cref="PhotonJoinRandomGameOptions"/></exception>
        public virtual IObservable <IGame> FindRandomGame(IJoinRandomGameOptions options)
        {
            var photonOptions = options as PhotonJoinRandomGameOptions;

            if (photonOptions == null)
            {
                throw new ArgumentException($"{nameof(options)} must be of type {nameof(PhotonJoinRandomGameOptions)}.", nameof(options));
            }

            if (_photonClient.State != ClientState.ConnectedToMasterserver && _photonClient.State != ClientState.JoinedLobby)
            {
                return(Observable.Throw <IGame>(new InvalidOperationException($"Operation failed: Invalid state '{_photonClient.State}'." +
                                                                              " Please make sure you are connected to Photon.")));
            }

            var observable = PhotonUtils.CreateObservableForExpectedStateChange <IGame>(_photonClient,
                                                                                        expectedState: ClientState.Joined, returnValue: new PhotonAlreadyJoinedGame(_photonClient));

            State = ConnectionState.JoiningRoom;

            _photonClient.OpJoinRandomRoom(new OpJoinRandomRoomParams
            {
                ExpectedCustomRoomProperties = photonOptions.ExpectedCustomRoomProperties,
                ExpectedMaxPlayers           = photonOptions.ExpectedMaxPlayers,
                ExpectedUsers  = photonOptions.ExpectedUsers,
                MatchingType   = photonOptions.MatchmakingMode,
                TypedLobby     = photonOptions.Lobby,
                SqlLobbyFilter = photonOptions.SqlLobbyFilter
            });

            return(observable);
        }
    public void Join()
    {
        var roomProperties = GetExpectedRoomProperties(Connecting.GameType.OneVsOne, BET_MINIMAL);
        var lobby          = LobbyMain;

        //_loadBalancingClient.OpJoinRoom(_roomName);
        _loadBalancingClient.OpJoinRandomRoom(roomProperties, MAX_PLAYERS, MatchmakingMode.FillRoom, lobby, null);
    }
    private void JoinRankedRoom(byte maxPlayerCount, byte rank)
    {
        OpJoinRandomRoomParams opJoinRandomRoomParams = new OpJoinRandomRoomParams();

        opJoinRandomRoomParams.ExpectedMaxPlayers           = maxPlayerCount;
        opJoinRandomRoomParams.ExpectedCustomRoomProperties = new ExitGames.Client.Photon.Hashtable {
            { "Rank", rank }
        };

        loadBalancingClient.OpJoinRandomRoom(opJoinRandomRoomParams);
    }
 public void QuickStart()
 {
     if (roomSize == 0) // if quickstart button is pressed
     {
         PhotonNetwork.JoinRandomRoom();
     }
     else
     {
         quickStartButton.SetActive(false);
         quickCancelButton.SetActive(true);
         OpJoinRandomRoomParams opJoinRandomRoomParams = new OpJoinRandomRoomParams();
         opJoinRandomRoomParams.ExpectedMaxPlayers = roomSize;
         lbc.OpJoinRandomRoom();
     }
     Debug.Log("Quick start"); // Tries to join an existing room
 }