| | 1 | | using DCL.Services; |
| | 2 | | using DCL.SettingsCommon.SettingsControllers.BaseControllers; |
| | 3 | | using UnityEngine; |
| | 4 | | using UnityEngine.EventSystems; |
| | 5 | |
|
| | 6 | | namespace DCL.SettingsCommon.SettingsControllers.SpecificControllers |
| | 7 | | { |
| | 8 | | [CreateAssetMenu(menuName = "Settings/Controllers/Controls/Input Audio Device", fileName = nameof(InputAudioDeviceCo |
| | 9 | | public class InputAudioDeviceControlController : SpinBoxSettingsControlController |
| | 10 | | { |
| | 11 | | private IAudioDevicesService audioDevicesService; |
| | 12 | |
|
| | 13 | | public override void Initialize() |
| | 14 | | { |
| 1 | 15 | | base.Initialize(); |
| | 16 | |
|
| 1 | 17 | | audioDevicesService = Environment.i.serviceLocator.Get<IAudioDevicesService>(); |
| | 18 | |
|
| 1 | 19 | | if (audioDevicesService.HasReceivedKernelMessage) |
| | 20 | | { |
| 0 | 21 | | RaiseOnOverrideIndicatorLabel(DeviceNames()); |
| 0 | 22 | | UpdateSetting(GetStoredValue()); |
| 0 | 23 | | } |
| | 24 | | else |
| 1 | 25 | | audioDevicesService.AudioDeviceCached += OnAudioDevicesCached; |
| | 26 | |
|
| | 27 | | void OnAudioDevicesCached() |
| | 28 | | { |
| 0 | 29 | | audioDevicesService.AudioDeviceCached -= OnAudioDevicesCached; |
| | 30 | |
|
| 0 | 31 | | RaiseOnOverrideIndicatorLabel(DeviceNames()); |
| 0 | 32 | | UpdateSetting(GetStoredValue()); |
| 0 | 33 | | } |
| 1 | 34 | | } |
| | 35 | |
|
| | 36 | | public override void OnPointerClicked(PointerEventData eventData) |
| | 37 | | { |
| 0 | 38 | | if (!audioDevicesService.HasReceivedKernelMessage) |
| 0 | 39 | | audioDevicesService.RequestAudioDevices(); |
| 0 | 40 | | } |
| | 41 | |
|
| | 42 | | private string[] DeviceNames() |
| | 43 | | { |
| 0 | 44 | | string[] deviceNames = new string[audioDevicesService.InputDevices.Length]; |
| 0 | 45 | | for (int i = 0; i < audioDevicesService.InputDevices.Length; i++) |
| 0 | 46 | | deviceNames[i] = audioDevicesService.InputDevices[i].label; |
| | 47 | |
|
| 0 | 48 | | string cleanDeafult = deviceNames[0].Replace("Default", "").Replace(" - ", ""); |
| 0 | 49 | | deviceNames[0] = $"Default ({cleanDeafult})"; |
| | 50 | |
|
| 0 | 51 | | return deviceNames; |
| | 52 | | } |
| | 53 | |
|
| | 54 | | public override object GetStoredValue() => |
| 1 | 55 | | currentAudioSettings.inputDevice; |
| | 56 | |
|
| | 57 | | public override void UpdateSetting(object newValue) |
| | 58 | | { |
| 1 | 59 | | if (currentAudioSettings.inputDevice == (int)newValue) |
| 1 | 60 | | return; |
| | 61 | |
|
| 0 | 62 | | currentAudioSettings.inputDevice = (int)newValue; |
| 0 | 63 | | ApplySettings(); |
| | 64 | |
|
| 0 | 65 | | audioDevicesService.SetInputDevice((int)newValue); |
| 0 | 66 | | } |
| | 67 | | } |
| | 68 | | } |