forked from cgvr/DeltaVR
77 lines
2.2 KiB
C#
77 lines
2.2 KiB
C#
using TMPro;
|
|
using UnityEngine;
|
|
|
|
public class MicrophoneStand : MonoBehaviour
|
|
{
|
|
public TextMeshProUGUI outputText;
|
|
|
|
public GameObject microphoneOffStatus;
|
|
public GameObject microphoneOnStatus;
|
|
|
|
public FMODWhisperBridge fmodWhisperBridge;
|
|
|
|
public delegate void OnPlayerFinishedSpeakingDelegate();
|
|
public event OnPlayerFinishedSpeakingDelegate OnPlayerFinishedSpeaking;
|
|
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
microphoneOffStatus.SetActive(true);
|
|
microphoneOnStatus.SetActive(false);
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
|
|
void OnTriggerEnter(Collider other)
|
|
{
|
|
KbmController controller = other.GetComponent<KbmController>();
|
|
Debug.Log("Mic stand collided with object " + other.gameObject.name);
|
|
|
|
if (controller != null || other.gameObject.tag == "Player Head")
|
|
{
|
|
fmodWhisperBridge.OnWhisperSegmentUpdated += OnPlayerSpeechUpdated;
|
|
fmodWhisperBridge.OnWhisperSegmentFinished += OnPlayerSpeechFinished;
|
|
|
|
microphoneOffStatus.SetActive(false);
|
|
microphoneOnStatus.SetActive(true);
|
|
AudioManager.Instance.PlayAttachedInstance(FMODEvents.Instance.RadioButton, gameObject);
|
|
fmodWhisperBridge.ActivateRecording();
|
|
}
|
|
}
|
|
|
|
private void OnTriggerExit(Collider other)
|
|
{
|
|
KbmController controller = other.GetComponent<KbmController>();
|
|
if (controller != null | other.gameObject.tag == "Player Head")
|
|
{
|
|
fmodWhisperBridge.OnWhisperSegmentUpdated -= OnPlayerSpeechUpdated;
|
|
fmodWhisperBridge.OnWhisperSegmentFinished -= OnPlayerSpeechFinished;
|
|
|
|
microphoneOffStatus.SetActive(true);
|
|
microphoneOnStatus.SetActive(false);
|
|
AudioManager.Instance.PlayAttachedInstance(FMODEvents.Instance.RadioButton, gameObject);
|
|
fmodWhisperBridge.DeactivateRecording();
|
|
}
|
|
}
|
|
|
|
private void OnPlayerSpeechUpdated(string text)
|
|
{
|
|
outputText.text = text;
|
|
}
|
|
|
|
private void OnPlayerSpeechFinished(string playerText)
|
|
{
|
|
OnPlayerFinishedSpeaking?.Invoke();
|
|
}
|
|
|
|
public string GetTextOutput()
|
|
{
|
|
return outputText.text;
|
|
|
|
}
|
|
}
|