cafe waiter npc has states, rotates notepad when spoken to

This commit is contained in:
2026-01-28 15:33:14 +02:00
parent a8e65514f4
commit e0d68454c7
6 changed files with 462 additions and 14 deletions

View File

@@ -1,16 +1,70 @@
using System.Collections;
using System.Collections.Generic;
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);
//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;
}
}
}
}