forked from cgvr/DeltaVR
archery range mic emits particles + recording is clearer to player
This commit is contained in:
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@@ -10,58 +10,72 @@ public class MicrophoneStand : MonoBehaviour
|
||||
|
||||
public FMODWhisperBridge fmodWhisperBridge;
|
||||
|
||||
public delegate void OnPlayerFinishedSpeakingDelegate();
|
||||
public event OnPlayerFinishedSpeakingDelegate OnPlayerFinishedSpeaking;
|
||||
public delegate void OnPlayerUsedMicrophoneDelegate();
|
||||
public event OnPlayerUsedMicrophoneDelegate OnPlayerUsedMicrophone;
|
||||
|
||||
[Header("Particle System Config")]
|
||||
public ParticleSystem particles;
|
||||
public float baseEmissionRate = 3;
|
||||
public float maxExtraEmissionRate = 50;
|
||||
|
||||
private ParticleSystem.EmissionModule particleEmission;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
microphoneOffStatus.SetActive(true);
|
||||
microphoneOnStatus.SetActive(false);
|
||||
|
||||
particleEmission = particles.emission;
|
||||
particleEmission.enabled = false;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
if (particleEmission.enabled)
|
||||
{
|
||||
particleEmission.rateOverTime = baseEmissionRate + fmodWhisperBridge.GetNormalizedVolume01() * maxExtraEmissionRate;
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPlayerApproach()
|
||||
{
|
||||
fmodWhisperBridge.ActivateRecording();
|
||||
fmodWhisperBridge.OnWhisperSegmentUpdated += OnPlayerSpeechUpdated;
|
||||
fmodWhisperBridge.OnWhisperSegmentFinished += OnPlayerSpeechFinished;
|
||||
|
||||
microphoneOffStatus.SetActive(false);
|
||||
microphoneOnStatus.SetActive(true);
|
||||
particleEmission.enabled = true;
|
||||
AudioManager.Instance.PlayAttachedInstance(FMODEvents.Instance.RadioButton, gameObject);
|
||||
fmodWhisperBridge.ActivateRecording();
|
||||
}
|
||||
|
||||
public void OnPlayerLeave()
|
||||
{
|
||||
fmodWhisperBridge.OnWhisperSegmentUpdated -= OnPlayerSpeechUpdated;
|
||||
fmodWhisperBridge.OnWhisperSegmentFinished -= OnPlayerSpeechFinished;
|
||||
fmodWhisperBridge.DeactivateRecording();
|
||||
|
||||
microphoneOffStatus.SetActive(true);
|
||||
microphoneOnStatus.SetActive(false);
|
||||
particleEmission.enabled = false;
|
||||
AudioManager.Instance.PlayAttachedInstance(FMODEvents.Instance.RadioButton, gameObject);
|
||||
fmodWhisperBridge.DeactivateRecording();
|
||||
}
|
||||
|
||||
private void OnPlayerSpeechUpdated(string text)
|
||||
{
|
||||
outputText.text = text;
|
||||
OnPlayerFinishedSpeaking?.Invoke();
|
||||
OnPlayerUsedMicrophone?.Invoke();
|
||||
}
|
||||
|
||||
private void OnPlayerSpeechFinished(string playerText)
|
||||
private void OnPlayerSpeechFinished(string text)
|
||||
{
|
||||
OnPlayerFinishedSpeaking?.Invoke();
|
||||
outputText.text = text;
|
||||
OnPlayerUsedMicrophone?.Invoke();
|
||||
}
|
||||
|
||||
public string GetTextOutput()
|
||||
{
|
||||
return outputText.text;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ public class ArcheryRangeNPC : NPCController
|
||||
|
||||
private void Start()
|
||||
{
|
||||
microphoneStand.OnPlayerFinishedSpeaking += OnPlayerUsedMicrophone;
|
||||
microphoneStand.OnPlayerUsedMicrophone += OnPlayerUsedMicrophone;
|
||||
imageGenerationButton.OnButtonPressed += OnImageGenerationButtonPressed;
|
||||
modelGenerationButton.OnButtonPressed += OnModelGenerationButtonPressed;
|
||||
}
|
||||
|
||||
@@ -38,11 +38,9 @@ public class RadioTransmitter : XRGrabInteractable
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (particles.emission.enabled)
|
||||
if (particleEmission.enabled)
|
||||
{
|
||||
particles.transform.LookAt(computerScreen.transform.position);
|
||||
Debug.Log("speech volume normalized: " + fmodWhisperBridge.GetNormalizedVolume01());
|
||||
Debug.Log("speech volume decibels: " + fmodWhisperBridge.GetCurrentVolumeDb());
|
||||
particleEmission.rateOverTime = baseEmissionRate + fmodWhisperBridge.GetNormalizedVolume01() * maxExtraEmissionRate;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user