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() { notepadOriginalRotation = notepadTransform.localRotation.eulerAngles; notepadFlippedRotation = notepadOriginalRotation + new Vector3(0, 180, 0); } protected override void OnPlayerApproach() { AudioManager.Instance.PlayDialogue(voiceLineKeys[0], gameObject); fmodWhisperBridge.OnWhisperSegmentUpdated += OnPlayerSpeechUpdate; fmodWhisperBridge.OnWhisperSegmentFinished += ProcessPlayerSpeech; fmodWhisperBridge.ActivateRecording(); } protected override void OnPlayerLeave() { //AudioManager.Instance.PlayDialogue(voiceLineKeys[1], gameObject); fmodWhisperBridge.OnWhisperSegmentUpdated -= OnPlayerSpeechUpdate; fmodWhisperBridge.OnWhisperSegmentFinished -= ProcessPlayerSpeech; 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; } } } private void OnPlayerSpeechUpdate(string playerText) { if (string.IsNullOrEmpty(playerText) || playerText.Equals("BLANK_AUDIO")) { return; } notepadText.text = playerText; } }