0

I am using photon pun and voice for a VR app where I am using Oculus Quest 2. In that app there is 2 group of users. The first group connects from the same place, and they play near each other, and the second group connects from remote places to play with the first group.

So, my requirement here is that the first group must not hear each other but hear and speak with second team. But, the second team must speak with both second team and also with the first team.

Here below is my code that is not working at the moment. I think recorder.InterestGroup might not working.

[ContextMenu("Join Blue Team")]
public void JoinBlueTeam()
{
    var currentTeam = PhotonNetwork.LocalPlayer.GetPhotonTeam();
    if (currentTeam == null)
    {
        PhotonNetwork.LocalPlayer.JoinTeam("Blue");
        ChangeVoiceGroup("Blue");
    }
    else
    {
        if (!string.Equals(currentTeam.Name, "Blue"))
        {
            PhotonNetwork.LocalPlayer.SwitchTeam("Blue");
            ChangeVoiceGroup("Blue");
        }
    }
}



[ContextMenu("Join Red Team")]
public void JoinRedTeam()
{
    var currentTeam = PhotonNetwork.LocalPlayer.GetPhotonTeam();
    if (currentTeam == null)
    {
        PhotonNetwork.LocalPlayer.JoinTeam("Red");
        ChangeVoiceGroup("Red");
    }
    else
    {
        if (!string.Equals(currentTeam.Name, "Red"))
        {
            PhotonNetwork.LocalPlayer.SwitchTeam("Red");
            ChangeVoiceGroup("Red");
        }
    }
}

private void ChangeVoiceGroup(string team)
{
    if (string.Equals(team,"Blue"))
    {
        
        var recorder = FindObjectOfType<Recorder>();
        recorder.InterestGroup = 1;
        byte[] groupsToRemove = new byte[2];
        groupsToRemove[0] = 0; //Here on side team unsubscribe from main voice channel 
        groupsToRemove[1] = 1; //Here on side team unsubscribe from Blue team voice channel that is their voice channel, so they can not hear each other
        byte[] groupsToAdd = new byte[1];
        groupsToAdd[0] = 2; //And here they will only subscribe to the remote team, so they won't be hearing their team mates but gonna be hearing remote voices
        if (!PhotonVoiceNetwork.Instance.Client.OpChangeGroups(groupsToRemove,groupsToAdd))
        {
            Debug.LogError("Couldn't set the voice groups!");
        }
        else
        {
            Debug.Log("Joined On Site Team Voice Channel!");
        }
    }

    if (string.Equals(team,"Red"))
    {
        var recorder = FindObjectOfType<Recorder>();
        recorder.InterestGroup = 2;
        byte[] groupsToRemove = new byte[2];
        groupsToRemove[0] = 0;
        groupsToRemove[1] = 1;
        byte[] groupsToAdd = new byte[2];
        groupsToAdd[0] = 1; //Here remote team will hear the on side team
        groupsToAdd[1] = 2; //Here remote team also will hear their team
        if (!PhotonVoiceNetwork.Instance.Client.OpChangeGroups(groupsToRemove,groupsToAdd))
        {
            Debug.LogError("Couldn't set the voice groups!");
        }
        else
        {
            Debug.Log("Joined Remote Team Voice Channel!");
        }
    } 
}
Akin Erkan
  • 273
  • 3
  • 14

1 Answers1

0

I was joining the blue team when I joined the room. I just don't join any team on OnJoinedRoom, so it is working now. I don't understand the relation between the PhotonNetwork.LocalPlayer.JoinTeam() and PhotonVoiceNetwork.Instance.Client.OpChangeGroups() methods because it looks one of them is about PhotonNetwork and other is PhotonVoiceNetwork but it is working like that.

public override void OnJoinedRoom()
{
    var teams = PhotonTeamsManager.Instance.GetAvailableTeams();
    if(teams.Length < 1)
        print("No Team!");
    foreach (var team in teams)
    {
        print("Team name: " + team.Name);
    }
    Debug.Log($"Joined the Room: {PhotonNetwork.CurrentRoom.Name}");
    this.IsInTheRoom = true;
    //PhotonNetwork.LocalPlayer.JoinTeam("Blue"); //Commented out part
}
Akin Erkan
  • 273
  • 3
  • 14