Exemplo n.º 1
0
        /// <summary>
        /// Sets up matchmaking values for connecting to a room and then tries connecting to one
        /// </summary>
        private void SetConnectingToRoom()
        {
            connectingToRoom = true;

            LobbyUI lobbyUI = (LobbyUI)UI;

            lobbyUI.SetCreateRoomToggleActiveState(false);

            bool creatingRoom = lobbyUI.GetStateOfCreateRoomToggle();

            if (creatingRoom)
            {
                lobbyUI.SetMaxPlayersInputFieldActiveState(true);
                lobbyUI.WaitForMaxPlayerInput(() =>
                {
                    //setup room options and join or create room
                    RoomOptions options = new RoomOptions();
                    options.IsVisible   = false;
                    //get max players choosen by user
                    options.MaxPlayers = (byte)lobbyUI.GetMaxPlayersInput();
                    //create or join room with options
                    PhotonNetwork.CreateRoom(ROOM_NAME, options, TypedLobby.Default);
                });
            }
            else
            {
                PhotonNetwork.JoinRoom(ROOM_NAME);
            }
        }
Exemplo n.º 2
0
        public override void OnJoinRoomFailed(short returnCode, string message)
        {
            base.OnJoinRoomFailed(returnCode, message);
            LobbyUI lobbyUI = (LobbyUI)UI;

            lobbyUI.SetConnectButtonInteractability(true);
            lobbyUI.SetCreateRoomToggleActiveState(true);
            connectingToRoom = false;
            Debug.LogError($"Joining room failed with message: {message}");
        }
Exemplo n.º 3
0
        /// <summary>
        /// should be called when connect to room button is clicked
        /// </summary>
        private void OnConnectToRoom()
        {
            LobbyUI lobbyUI = (LobbyUI)UI;

            //connect only if we can actually connect to the room
            if (lobbyUI.ConnectDestination() == "Room" && !connectingToRoom && PhotonNetwork.IsConnectedAndReady)
            {
                SetConnectingToRoom();
                lobbyUI.SetConnectButtonInteractability(false);
            }
        }
Exemplo n.º 4
0
        public override void OnConnectedToMaster()
        {
            base.OnConnectedToMaster();

            //if we where connecting to master we set up values and ui accordingly
            if (connectingToMaster)
            {
                SetConnectedToMaster();
                LobbyUI lobbyUI = (LobbyUI)UI;
                lobbyUI.UpdateConnectStatus(true);
                lobbyUI.UpdateConnectColor(true);
                lobbyUI.SetConnectButtonInteractability(true);
                lobbyUI.SetCreateRoomToggleActiveState(true);
            }
        }
Exemplo n.º 5
0
        public override void OnDisconnected(DisconnectCause cause)
        {
            base.OnDisconnected(cause);
            //try reattaching the UI for when we where inside another scene
            AttachUI(MultiplayerRacerScenes.LOBBY);
            //update lobby ui after having tried reattaching it
            LobbyUI lobbyUI = (LobbyUI)UI;

            lobbyUI.UpdateConnectStatus(false);
            lobbyUI.UpdateConnectColor(false);
            lobbyUI.ResetPlayerInfo();
            lobbyUI.SetConnectButtonInteractability(true);
            Application.quitting -= OnQuitEvent;

            print(cause);
        }
Exemplo n.º 6
0
        public override void OnJoinedRoom()
        {
            base.OnJoinedRoom();
            //define first in room as the max player count being 0
            bool firstInRoom = PhotonNetwork.CurrentRoom.MaxPlayers == 0;

            //if we where connecting to a room and are not the first, we setup values and ui accordingly
            if (connectingToRoom && !firstInRoom)
            {
                LobbyUI lobbyUI = (LobbyUI)UI;
                Room    room    = PhotonNetwork.CurrentRoom;
                SetConnectedToRoom(room);
                lobbyUI.SetupRoomInfo(MakeNickname(), room);
                lobbyUI.UpdatePlayerInfo(room.PlayerCount);
                lobbyUI.SetupExitButton(LeaveRoom);
                lobbyUI.SetCarSelectActiveState(true);
                lobbyUI.UpdateConnectColor(false);   //reset color of connect button.
                lobbyUI.UpdateCarsSelectedWithPlayerProperties();
                FullRoomCheck();                     //client can be the one filling up the room.
                Application.quitting += OnQuitEvent; //setup quitting event with leaving master check
            }
        }
Exemplo n.º 7
0
        public void OnPlayerEnteredRoom(Player newPlayer)
        {
            /*since players can only join the room when in the lobby scene
            *  we dont do anything if a player joins when in an other scene*/
            if (CurrentScene != MultiplayerRacerScenes.LOBBY)
            {
                return;
            }

            if (UI == null)
            {
                Debug.LogError("Wont update room :: UI is null");
                return;
            }

            Room    room    = PhotonNetwork.CurrentRoom;
            LobbyUI lobbyUI = (LobbyUI)UI;

            lobbyUI.UpdateRoomInfo(room);
            lobbyUI.UpdatePlayerInfo(room.PlayerCount);
            FullRoomCheck(); //entering player can be the one to fill the lobby
        }
Exemplo n.º 8
0
        public void OnPlayerLeftRoom(Player otherPlayer)
        {
            //Update our number in room since
            UpdateNumberInRoom();
            //master needs to deal with player leaving the room/him
            OnPlayerLeftMaster();
            //invoke shared functions
            Room room = PhotonNetwork.CurrentRoom;

            UI.UpdateRoomInfo(room);
            UI.UpdateNickname(MatchMakingManager.Instance.MakeNickname());
            //Update Room status based on current scene
            switch (CurrentScene)
            {
            case MultiplayerRacerScenes.LOBBY:
                //reset all player related info, then update it again
                LobbyUI lobbyUI = (LobbyUI)UI;
                lobbyUI.ResetPlayerInfo();
                lobbyUI.OnPlayerLeftSelectedCar(otherPlayer);
                lobbyUI.UpdatePlayerInfo(room.PlayerCount);
                break;

            case MultiplayerRacerScenes.GAME:
                ((GameUI)UI).ShowText($"{otherPlayer.NickName} left the game");
                break;
            }

            /*if resetable, set ourselfs to unready status, exit button and room status is shown
             * and on scene reset gets fired*/
            if (IsResetAble)
            {
                SetReady(false);
                UI.ShowExitButton();
                UI.SetButtonInfoActiveState(true);
                OnSceneReset?.Invoke(CurrentScene);
            }
        }