unity3d Unity Photon Pun Voice -静音您的团队频道并订阅所有其他频道

kiz8lqtg  于 2023-04-07  发布在  其他
关注(0)|答案(1)|浏览(165)

我正在使用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!");
        }
    } 
}
sczxawaw

sczxawaw1#

我加入房间时加入了蓝色团队。我只是没有加入OnJoinedRoom上的任何团队,所以它现在正在工作。我不明白PhotonNetwork.LocalPlayer.JoinTeam()和PhotonVoiceNetwork.Instance.Client.OpChangeGroups()方法之间的关系,因为看起来其中一个是关于PhotonNetwork的,另一个是PhotonVoiceNetwork,但它是这样工作的。

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

相关问题