浏览代码
Adding volume controls and muting, though the actual cross-muting isn't yet working since the Vivox IDs aren't being mapped correctly to our Auth IDs yet.
/main/staging/vivox_package_integration
Adding volume controls and muting, though the actual cross-muting isn't yet working since the Vivox IDs aren't being mapped correctly to our Auth IDs yet.
/main/staging/vivox_package_integration
nathaniel.buck@unity3d.com
3 年前
当前提交
a685cb09
共有 17 个文件被更改,包括 297 次插入 和 125 次删除
-
14Assets/Art/Crown/Crown.png.meta
-
14Assets/Art/Volume/volumeMuted.png.meta
-
14Assets/Art/Volume/volumeRings.png.meta
-
14Assets/Art/Volume/volumeSpeaker.png.meta
-
50Assets/Prefabs/UI/UserCardPanel.prefab
-
64Assets/Scenes/mainScene.unity
-
14Assets/Scripts/Game/GameManager.cs
-
32Assets/Scripts/Game/LobbyUser.cs
-
35Assets/Scripts/UI/InLobbyUserUI.cs
-
1Assets/Scripts/UI/LobbyUserVolumeUI.cs
-
2Assets/Scripts/UI/MuteUI.cs
-
27Assets/Scripts/Vivox/VivoxSetup.cs
-
28Assets/Scripts/Game/LobbyUserAudio.cs
-
79Assets/Scripts/Vivox/VivoxUserHandler.cs
-
11Assets/Scripts/Vivox/VivoxUserHandler.cs.meta
-
23Assets/Scripts/Game/LocalUserAudio.cs
-
0/Assets/Scripts/Game/LobbyUserAudio.cs.meta
|
|||
using UnityEngine; |
|||
|
|||
namespace LobbyRelaySample |
|||
{ |
|||
[SerializeField] |
|||
public class LobbyUserAudio |
|||
{ |
|||
public string ID { get; private set; } |
|||
public bool HasVoice { get; set; } |
|||
public bool Muted { get; set; } |
|||
|
|||
// We should explicitly ensure that UserVolume is a normalized value, as letting the volume be set too high could be harmful to listeners.
|
|||
private float m_userVolume; |
|||
public float UserVolume |
|||
{ |
|||
get => m_userVolume; |
|||
set => m_userVolume = Mathf.Clamp01(value); |
|||
} |
|||
|
|||
public LobbyUserAudio(string userID) |
|||
{ |
|||
ID = userID; |
|||
HasVoice = false; |
|||
Muted = false; |
|||
UserVolume = 50/70f; // Begin at what will be neutral volume given the range of min to max volume.
|
|||
} |
|||
} |
|||
} |
|
|||
using UnityEngine; |
|||
using Unity.Services.Vivox; |
|||
using VivoxUnity; |
|||
|
|||
namespace LobbyRelaySample.vivox |
|||
{ |
|||
/// <summary>
|
|||
/// Listens for changes to Vivox state for one user in the lobby.
|
|||
/// Instead of going through Relay, this will listen to the Vivox service since it will already transmit state changes for all clients.
|
|||
/// </summary>
|
|||
public class VivoxUserHandler : MonoBehaviour |
|||
{ |
|||
[SerializeField] |
|||
private UI.MuteUI m_MuteUI; |
|||
[SerializeField] |
|||
private UI.LobbyUserVolumeUI m_lobbyUserVolumeUI; |
|||
|
|||
private IChannelSession m_channelSession; |
|||
private string m_id; |
|||
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 void SetId(string id) |
|||
{ |
|||
m_id = id; |
|||
Account account = new Account(id); |
|||
// Vivox appends additional info to the ID we provide, in order to associate it with a specific channel. We'll construct m_vivoxId to match the ID used by Vivox.
|
|||
m_vivoxId = account.ToString(); //"sip:." + account.Issuer + "." + m_id + ".@" + account.Domain;
|
|||
|
|||
|
|||
// TODO: This doesn't end up matching the Participants keys, since there's something else appended between id and domain.
|
|||
|
|||
|
|||
} |
|||
|
|||
public void OnChannelJoined(IChannelSession channelSession) |
|||
{ |
|||
m_channelSession = channelSession; |
|||
} |
|||
|
|||
public void OnChannelLeft() |
|||
{ |
|||
m_channelSession = null; |
|||
} |
|||
|
|||
public void OnVolumeSlide(float volumeNormalized) |
|||
{ |
|||
if (m_channelSession == null || m_vivoxId == null) // Verify initialization, since SetId and OnChannelJoined are called at different times for local vs. remote clients.
|
|||
return; |
|||
int vol = (int)Mathf.Clamp(k_volumeMin + (k_volumeMax - k_volumeMin) * volumeNormalized, k_volumeMin, k_volumeMax); // Clamping as a precaution; if UserVolume somehow got above 1, listeners could be harmed.
|
|||
bool isSelf = m_channelSession.Participants[m_vivoxId].IsSelf; |
|||
if (isSelf) |
|||
{ |
|||
VivoxService.Instance.Client.AudioInputDevices.VolumeAdjustment = vol; |
|||
} |
|||
else |
|||
{ |
|||
// TODO: Verify non-null things?
|
|||
m_channelSession.Participants[m_vivoxId].LocalVolumeAdjustment = vol; |
|||
} |
|||
} |
|||
|
|||
public void OnMuteToggle(bool isMuted) |
|||
{ |
|||
if (m_channelSession == null || m_vivoxId == null) |
|||
return; |
|||
bool isSelf = m_channelSession.Participants[m_vivoxId].IsSelf; |
|||
if (isSelf) |
|||
{ |
|||
VivoxService.Instance.Client.AudioInputDevices.Muted = isMuted; |
|||
} |
|||
else |
|||
{ |
|||
m_channelSession.Participants[m_vivoxId].LocalMute = isMuted; |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 78d292f3bd9f1614cb744dcb4fe3ac12 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections; |
|||
using System.Collections.Generic; |
|||
using UnityEngine; |
|||
|
|||
namespace LobbyRelaySample |
|||
{ |
|||
[SerializeField] |
|||
public class LobbyUserAudio |
|||
{ |
|||
public string ID { get; private set; } |
|||
public bool HasVoice; |
|||
public bool Muted; |
|||
public float UserVolume; |
|||
|
|||
public LobbyUserAudio(string userID) |
|||
{ |
|||
ID = userID; |
|||
HasVoice = false; |
|||
Muted = false; |
|||
UserVolume = 1; |
|||
} |
|||
} |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue