| | 1 | | using UnityEngine; |
| | 2 | | using UnityEngine.Analytics; |
| | 3 | |
|
| | 4 | | namespace DCL |
| | 5 | | { |
| | 6 | | public class DCLVoiceChatController : MonoBehaviour |
| | 7 | | { |
| | 8 | | [Header("InputActions")] |
| | 9 | | public InputAction_Hold voiceChatAction; |
| | 10 | | public InputAction_Trigger voiceChatToggleAction; |
| | 11 | |
|
| | 12 | | private InputAction_Hold.Started voiceChatStartedDelegate; |
| | 13 | | private InputAction_Hold.Finished voiceChatFinishedDelegate; |
| | 14 | | private InputAction_Trigger.Triggered voiceChatToggleDelegate; |
| | 15 | |
|
| 598 | 16 | | private bool firstTimeVoiceRecorded = true; |
| | 17 | |
|
| | 18 | | void Awake() |
| | 19 | | { |
| 597 | 20 | | voiceChatStartedDelegate = (action) => StartVoiceChatRecording(); |
| 597 | 21 | | voiceChatFinishedDelegate = (action) => DCL.Interface.WebInterface.SendSetVoiceChatRecording(false); |
| 597 | 22 | | voiceChatToggleDelegate = (action) => DCL.Interface.WebInterface.ToggleVoiceChatRecording(); |
| 597 | 23 | | voiceChatAction.OnStarted += voiceChatStartedDelegate; |
| 597 | 24 | | voiceChatAction.OnFinished += voiceChatFinishedDelegate; |
| 597 | 25 | | voiceChatToggleAction.OnTriggered += voiceChatToggleDelegate; |
| | 26 | |
|
| 863 | 27 | | KernelConfig.i.EnsureConfigInitialized().Then(config => EnableVoiceChat(config.comms.voiceChatEnabled)); |
| 597 | 28 | | KernelConfig.i.OnChange += OnKernelConfigChanged; |
| 597 | 29 | | } |
| | 30 | | void OnDestroy() |
| | 31 | | { |
| 597 | 32 | | voiceChatAction.OnStarted -= voiceChatStartedDelegate; |
| 597 | 33 | | voiceChatAction.OnFinished -= voiceChatFinishedDelegate; |
| 597 | 34 | | KernelConfig.i.OnChange -= OnKernelConfigChanged; |
| 597 | 35 | | } |
| | 36 | |
|
| 0 | 37 | | void OnKernelConfigChanged(KernelConfigModel current, KernelConfigModel previous) { EnableVoiceChat(current.comm |
| | 38 | |
|
| 532 | 39 | | void EnableVoiceChat(bool enable) { CommonScriptableObjects.voiceChatDisabled.Set(!enable); } |
| | 40 | |
|
| | 41 | | private void StartVoiceChatRecording() |
| | 42 | | { |
| 0 | 43 | | DCL.Interface.WebInterface.SendSetVoiceChatRecording(true); |
| 0 | 44 | | if (firstTimeVoiceRecorded) |
| | 45 | | { |
| 0 | 46 | | AnalyticsHelper.SendVoiceChatStartedAnalytic(); |
| 0 | 47 | | firstTimeVoiceRecorded = false; |
| | 48 | | } |
| 0 | 49 | | } |
| | 50 | | } |
| | 51 | | } |