using System;
using UnityEngine;
namespace Convai.Scripts.Utils
{
public class MicrophoneManager
{
///
/// Singleton instance of the MicrophoneTestController.
///
public static MicrophoneManager Instance
{
get
{
if(_instance == null)
{
_instance = new MicrophoneManager();
}
return _instance;
}
}
///
/// Private Instance of the Singleton
///
private static MicrophoneManager _instance;
///
/// Keeps track on the selected microphone device index
///
private int _selectedMicrophoneIndex;
///
/// Public Getter for Selected Microphone Name
///
public string SelectedMicrophoneName
{
get
{
if(_selectedMicrophoneIndex < 0 || _selectedMicrophoneIndex >= Microphone.devices.Length) return string.Empty;
return Microphone.devices[_selectedMicrophoneIndex];
}
}
///
/// Event indicating that the selected Microphone has changed.
///
public event Action OnMicrophoneDeviceChanged;
private MicrophoneManager()
{
_selectedMicrophoneIndex = UISaveLoadSystem.Instance.SelectedMicrophoneDeviceNumber ;
}
///
/// Called when the selected microphone device is changed.
///
public void SetSelectedMicrophoneIndex(int selectedMicrophoneDeviceValue)
{
_selectedMicrophoneIndex = selectedMicrophoneDeviceValue;
OnMicrophoneDeviceChanged?.Invoke(SelectedMicrophoneName);
}
///
/// Returns whether any microphone is present in the system or not
///
///
public bool HasAnyMicrophoneDevices() => Microphone.devices.Length != 0;
}
}