-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathVoipHandler.cs
More file actions
51 lines (43 loc) · 1.4 KB
/
VoipHandler.cs
File metadata and controls
51 lines (43 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright (c) Meta Platforms, Inc. and affiliates.
using Photon.Voice.Unity;
using UnityEngine;
using UnityEngine.Assertions;
namespace Meta.Multiplayer.Core
{
/// <summary>
/// Keeps reference to the audio speaker and the voice recorder to handle muting.
/// </summary>
public class VoipHandler : MonoBehaviour
{
private AudioSource m_speakerAudioSource;
private VoiceConnection m_voiceRecorder;
private bool m_isMuted = false;
public bool IsMuted
{
get => m_isMuted;
set
{
m_isMuted = value;
if (m_speakerAudioSource)
{
m_speakerAudioSource.mute = m_isMuted;
}
if (m_voiceRecorder)
{
m_voiceRecorder.PrimaryRecorder.TransmitEnabled = !m_isMuted;
}
}
}
public void SetRecorder(VoiceConnection recorder)
{
m_voiceRecorder = recorder;
m_voiceRecorder.PrimaryRecorder.TransmitEnabled = !m_isMuted;
}
public void SetSpeaker(Speaker speaker)
{
m_speakerAudioSource = speaker.GetComponent<AudioSource>();
Assert.IsNotNull(m_speakerAudioSource, "Voip Speaker should have an AudioSource component.");
m_speakerAudioSource.mute = m_isMuted;
}
}
}