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!");
}
}
}