浏览代码

Correcting how we handle the volume state and UI when users leave and rejoin lobbies, to prevent stale values from persisting and to prevent the initial UI state for a user entering a lobby from being incorrect if they were previously in a lobby.

/main/staging/vivox_polish
nathaniel.buck@unity3d.com 3 年前
当前提交
a101f72d
共有 3 个文件被更改,包括 42 次插入28 次删除
  1. 4
      Assets/Prefabs/UI/UserCardPanel.prefab
  2. 49
      Assets/Scripts/UI/LobbyUserVolumeUI.cs
  3. 17
      Assets/Scripts/Vivox/VivoxUserHandler.cs

4
Assets/Prefabs/UI/UserCardPanel.prefab


m_Name:
m_EditorClassIdentifier:
m_volumeSliderContainer: {fileID: 6299655602247130973}
m_muteButtonContainer: {fileID: 6569968321909521185}
m_muteToggleContainer: {fileID: 6569968321909521185}
m_volumeSlider: {fileID: 774196503220678520}
m_muteToggle: {fileID: 6442186483341508885}
--- !u!114 &6299655602247130973
MonoBehaviour:
m_ObjectHideFlags: 0

49
Assets/Scripts/UI/LobbyUserVolumeUI.cs


using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
namespace LobbyRelaySample.UI
{

private UIPanelBase m_volumeSliderContainer;
[SerializeField]
private UIPanelBase m_muteButtonContainer;
private UIPanelBase m_muteToggleContainer;
[SerializeField]
[Tooltip("This is shown for other players, to mute them.")]
private GameObject m_muteIcon;

public bool IsLocalPlayer { private get; set; }
public void EnableVoice()
[SerializeField]
private Slider m_volumeSlider;
[SerializeField]
private Toggle m_muteToggle;
/// <param name="shouldResetUi">
/// When the user is being added, we want the UI to reset to the default values.
/// (We don't do this if the user is already in the lobby so that the previous values are retained. E.g. If they're too loud and volume was lowered, keep it lowered on reenable.)
/// </param>
public void EnableVoice(bool shouldResetUi)
if (shouldResetUi)
{ m_volumeSlider.SetValueWithoutNotify(vivox.VivoxUserHandler.NormalizedVolumeDefault);
m_muteToggle.SetIsOnWithoutNotify(false);
}
m_muteButtonContainer.Show();
m_muteToggleContainer.Show();
m_muteIcon.SetActive(false);
m_micMuteIcon.SetActive(true);
}

m_muteButtonContainer.Show();
m_muteToggleContainer.Show();
public void DisableVoice()
/// <param name="shouldResetUi">
/// When the user leaves the lobby (but not if they just lose voice access for some reason, e.g. device disconnect), reset state to the default values.
/// (We can't just do this during Enable since it could cause Vivox to have a state conflict during participant add.)
/// </param>
public void DisableVoice(bool shouldResetUi)
if (shouldResetUi)
{ m_volumeSlider.value = vivox.VivoxUserHandler.NormalizedVolumeDefault;
m_muteToggle.isOn = false;
}
m_muteButtonContainer.Hide(0.4f);
m_muteToggleContainer.Hide(0.4f);
/* TODO : If we can hook in the volume from a user, we can plug it in here.
/// <summary>
/// Controls the visibility of the volume rings to show activity levels of the voice channel on this user.
/// </summary>
/// <param name="normalizedVolume"></param>
public void OnSoundDetected(float normalizedVolume)
{
m_voiceRings.alpha = normalizedVolume;
}
*/
}
}

17
Assets/Scripts/Vivox/VivoxUserHandler.cs


private string m_vivoxId;
private const int k_volumeMin = -50, k_volumeMax = 20; // From the Vivox docs, the valid range is [-50, 50] but anything above 25 risks being painfully loud.
public static float NormalizedVolumeDefault { get { return (0f - k_volumeMin) / (k_volumeMax - k_volumeMin); } }
m_lobbyUserVolumeUI.DisableVoice();
m_lobbyUserVolumeUI.DisableVoice(true);
}
public void SetId(string id)

{
m_vivoxId = participant.Key;
m_lobbyUserVolumeUI.IsLocalPlayer = participant.IsSelf;
m_lobbyUserVolumeUI.EnableVoice();
m_lobbyUserVolumeUI.EnableVoice(true);
break;
}
}

if (isThisUser)
{ m_vivoxId = keyEventArg.Key; // Since we couldn't construct the Vivox ID earlier, retrieve it here.
m_lobbyUserVolumeUI.IsLocalPlayer = participant.IsSelf;
m_lobbyUserVolumeUI.EnableVoice();
m_lobbyUserVolumeUI.EnableVoice(true);
}
}
private void BeforeParticipantRemoved(object sender, KeyEventArg<string> keyEventArg)

bool isThisUser = username == m_id;
if (isThisUser)
{ m_lobbyUserVolumeUI.DisableVoice();
{ m_lobbyUserVolumeUI.DisableVoice(true);
}
}
private void OnParticipantValueUpdated(object sender, ValueEventArg<string, IParticipant> valueEventArg)

if (property == "UnavailableCaptureDevice")
{
if (participant.UnavailableCaptureDevice)
{ m_lobbyUserVolumeUI.DisableVoice();
{ m_lobbyUserVolumeUI.DisableVoice(false);
{ m_lobbyUserVolumeUI.EnableVoice();
{ m_lobbyUserVolumeUI.EnableVoice(false);
participant.SetIsMuteForAll(m_vivoxId, false, null);
}
}

m_lobbyUserVolumeUI.DisableVoice();
m_lobbyUserVolumeUI.DisableVoice(false);
m_lobbyUserVolumeUI.EnableVoice();
m_lobbyUserVolumeUI.EnableVoice(false);
}
}
}

正在加载...
取消
保存