1
0
forked from cgvr/DeltaVR
Files
DeltaVR3DModelGeneration/Assets/_PROJECT/Scripts/ModeGeneration/NPCs/CafeWaiterNPC.cs

71 lines
2.1 KiB
C#

using DG.Tweening;
using TMPro;
using UnityEngine;
public class CafeWaiterNPC : NPCController
{
public TextMeshProUGUI notepadText;
public Transform notepadTransform;
public FMODWhisperBridge fmodWhisperBridge;
private Vector3 notepadOriginalRotation;
private Vector3 notepadFlippedRotation;
// states:
// 0 - waiting for player order
// 1 - waiting for player to answer "is this correct?"
// 2 - bringing food
private int state;
private void Awake()
{
state = 0;
}
private void Start()
{
fmodWhisperBridge.OnWhisperResultProcessed += ProcessPlayerSpeech;
notepadOriginalRotation = notepadTransform.localRotation.eulerAngles;
notepadFlippedRotation = notepadOriginalRotation + new Vector3(0, 180, 0);
}
protected override void OnPlayerApproach()
{
AudioManager.Instance.PlayDialogue(voiceLineKeys[0], gameObject);
fmodWhisperBridge.ActivateRecording();
}
protected override void OnPlayerLeave()
{
//AudioManager.Instance.PlayDialogue(voiceLineKeys[1], gameObject);
fmodWhisperBridge.DeactivateRecording();
}
private void ProcessPlayerSpeech(string playerText)
{
if (state == 0)
{
// Show transcription and ask whether it is correct
notepadText.text = playerText;
notepadTransform.DOLocalRotate(notepadFlippedRotation, 0.5f);
AudioManager.Instance.PlayDialogue(voiceLineKeys[1], gameObject);
state = 1;
} else if (state == 1)
{
// Flip notepad back
notepadTransform.DOLocalRotate(notepadOriginalRotation, 0.5f);
// if player answered positively, bring food, otherwise ask again
if (playerText.ToLower().Contains("yes"))
{
AudioManager.Instance.PlayDialogue(voiceLineKeys[2], gameObject);
state = 2;
} else
{
AudioManager.Instance.PlayDialogue(voiceLineKeys[3], gameObject);
state = 0;
}
}
}
}