druu55
druu55

Reputation: 35

How to Gender Filtering with Photon?

I'm developing a multiplayer game with unity. I am using playfab and photon plugin in the game. Players choose gender when logging in and I save this selection to player data in playfab. Also, I am making a simple match system with photon. (The player presses the "match" button, joins a room randomly, if there is no room to join, player sets up a room for 2 people and waits for the other player, when the number of players joining the room is 2, they switch to the room screen.) Here is the code file where I make the players choose their gender:

  public void choosemale()
{
    eseç.SetActive(true);
    kseç.SetActive(false);
}
public void choosefemale()
{
    eseç.SetActive(false);
    kseç.SetActive(true);
}
 public void SetUserDataMale()
{
    PlayFabClientAPI.UpdateUserData(new UpdateUserDataRequest()
    {
        Data = new Dictionary<string, string>() {
        {"Gender", "Male"},
        
    },
        Permission = UserDataPermission.Public
    },
    result => Debug.Log("Successfully updated user data"),
    error => {
        Debug.Log("Got error setting user data Ancestor to Male");
        Debug.Log(error.GenerateErrorReport());
    });

}
public void SetUserDataFemale()
{
    PlayFabClientAPI.UpdateUserData(new UpdateUserDataRequest()
    {
        Data = new Dictionary<string, string>() {
        {"Gender", "Female"},

    },
             Permission = UserDataPermission.Public
},
   
    result => Debug.Log("Successfully updated user data"),
    error => {
        Debug.Log("Got error setting user data Ancestor to Female");
        Debug.Log(error.GenerateErrorReport());
    }
    ) ;


}     void OnLoginSuccess(LoginResult result)
{
    if (eseç.activeSelf == true)
     SetUserDataMale(); 
  
    if (kseç.activeSelf == true) 
     SetUserDataFemale(); 
}

The code file I used for the matching:

 public void FindMatch()
{

    PhotonNetwork.JoinRandomRoom();
    Debug.Log("Eşleşme Aranıyor");
}

public void StopSearch()
{

    PhotonNetwork.LeaveRoom();
}

public override void OnJoinRandomFailed(short returnCode, string message)
{
    Debug.Log("Fail");
    MakeRoom();
}


void MakeRoom()
{
    RoomOptions roomOptions = new RoomOptions()
    {    
        IsVisible = true,
        IsOpen = true,
        MaxPlayers = 2
                  
    };
    PhotonNetwork.CreateRoom("Room", roomOptions, EslesLobby);
    Debug.Log("oda oluşturuldu, diğer oyuncu bekleniyor");

}
public override void OnJoinedRoom()
{
    if (PhotonNetwork.CurrentRoom.PlayerCount == 2 && PhotonNetwork.IsMasterClient)
    {
        Debug.Log(PhotonNetwork.CurrentRoom.PlayerCount + "/2 Start Watch");
        onlinep.SetActive(true);
        _roomsCanvases.CurrentRoomCanvas.Show();
    
    }
   
}
public override void OnCreatedRoom()
{
    Debug.Log("OdaKurma Başarılı");
}

public override void OnPlayerEnteredRoom(Player newPlayer)
{

   if(PhotonNetwork.CurrentRoom.PlayerCount ==2 && PhotonNetwork.IsMasterClient)
    {
        Debug.Log(PhotonNetwork.CurrentRoom.PlayerCount+"/2 Start Watch");
        onlinep.SetActive(true);
        _roomsCanvases.CurrentRoomCanvas.Show();
       
    }
}

What I want to ask is this: I have a simple filtering bar. In this bar, when the player presses the male button, I want player to randomly join one of the rooms with only male players.How can I do that. I would be very happy if you help me. Initially I find out the gender of the player using this code:

    void GetUserData(string myPlayFabeId)
{
    PlayFabClientAPI.GetUserData(new GetUserDataRequest()
    {
        PlayFabId = myPlayFabeId,
        Keys = null
    }, result => {
        Debug.Log("Got user data:");
        if (result.Data == null || !result.Data.ContainsKey("Gender")) Debug.Log("No Gender");
        else Debug.Log("Ancestor: " + result.Data["Gender"].Value);
    }, (error) => {
        Debug.Log("Got error retrieving user data:");
        Debug.Log(error.GenerateErrorReport());
    });
}

Upvotes: 1

Views: 112

Answers (1)

Tobias
Tobias

Reputation: 174

You could simply split rooms into separate lists by using Photon's lobbies.

Upvotes: 0

Related Questions