using System;
using UnityEngine;
namespace Convai.Scripts.Runtime.UI
{
public class MicrophoneManager
{
///
/// Private Instance of the Singleton
///
private static MicrophoneManager _instance;
///
/// Keeps track on the selected microphone device index
///
private int _selectedMicrophoneIndex;
private MicrophoneManager()
{
_selectedMicrophoneIndex = UISaveLoadSystem.Instance.SelectedMicrophoneDeviceNumber;
}
///
/// Singleton instance of the MicrophoneTestController.
///
public static MicrophoneManager Instance
{
get
{
if (_instance == null) _instance = new MicrophoneManager();
return _instance;
}
}
///
/// 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;
///
/// 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()
{
return Microphone.devices.Length != 0;
}
}
}