81 lines
2.3 KiB
C#
81 lines
2.3 KiB
C#
using TMPro;
|
|
using UnityEngine;
|
|
|
|
public class MicrophoneStand : MonoBehaviour
|
|
{
|
|
public TextMeshProUGUI outputText;
|
|
|
|
public GameObject microphoneOffStatus;
|
|
public GameObject microphoneOnStatus;
|
|
|
|
public NPCController npcController;
|
|
public FMODWhisperBridge fmodWhisperBridge;
|
|
|
|
// 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 += OnWhisperResult;
|
|
fmodWhisperBridge.OnWhisperSegmentFinished += OnWhisperResult;
|
|
|
|
microphoneOffStatus.SetActive(false);
|
|
microphoneOnStatus.SetActive(true);
|
|
AudioManager.Instance.PlayAttachedInstance(FMODEvents.Instance.RadioButton, gameObject);
|
|
if (npcController != null)
|
|
{
|
|
npcController.SpeakVoiceLine(1);
|
|
}
|
|
fmodWhisperBridge.ActivateRecording();
|
|
}
|
|
}
|
|
|
|
private void OnTriggerExit(Collider other)
|
|
{
|
|
KbmController controller = other.GetComponent<KbmController>();
|
|
if (controller != null | other.gameObject.tag == "Player Head")
|
|
{
|
|
fmodWhisperBridge.OnWhisperSegmentUpdated -= OnWhisperResult;
|
|
fmodWhisperBridge.OnWhisperSegmentFinished -= OnWhisperResult;
|
|
|
|
microphoneOffStatus.SetActive(true);
|
|
microphoneOnStatus.SetActive(false);
|
|
AudioManager.Instance.PlayAttachedInstance(FMODEvents.Instance.RadioButton, gameObject);
|
|
if (npcController != null)
|
|
{
|
|
npcController.SpeakVoiceLine(2);
|
|
}
|
|
fmodWhisperBridge.DeactivateRecording();
|
|
}
|
|
}
|
|
|
|
private void OnWhisperResult(string result)
|
|
{
|
|
if (string.IsNullOrEmpty(result) || result.Equals("BLANK_AUDIO"))
|
|
{
|
|
return;
|
|
}
|
|
outputText.text = result;
|
|
}
|
|
|
|
public string GetTextOutput()
|
|
{
|
|
return outputText.text;
|
|
}
|
|
}
|