我正在使用Oculus Quest 2的VR应用程序中使用光子双关语和语音。在该应用程序中有2组用户。第一组从同一个地方连接,他们在彼此附近玩,第二组从远程连接到第一组。
所以,我的要求是第一组不能听到对方的声音,而要听到第二组的声音,但第二组必须同时和第二组和第一组说话。
下面是我的代码,目前无法工作。我认为recorder.interestgroup可能无法工作。
[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!");
}
}
}
1条答案
按热度按时间sczxawaw1#
我加入房间时加入了蓝色团队。我只是没有加入OnJoinedRoom上的任何团队,所以它现在正在工作。我不明白PhotonNetwork.LocalPlayer.JoinTeam()和PhotonVoiceNetwork.Instance.Client.OpChangeGroups()方法之间的关系,因为看起来其中一个是关于PhotonNetwork的,另一个是PhotonVoiceNetwork,但它是这样工作的。