forked from cgvr/DeltaVR
add pen, animate writing when npc listening to order
This commit is contained in:
8
Assets/_PROJECT/Scripts/ModeGeneration/Cafe.meta
Normal file
8
Assets/_PROJECT/Scripts/ModeGeneration/Cafe.meta
Normal file
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5c87ada50d41fde449b9fc44a22f4991
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
76
Assets/_PROJECT/Scripts/ModeGeneration/Cafe/PenWriter.cs
Normal file
76
Assets/_PROJECT/Scripts/ModeGeneration/Cafe/PenWriter.cs
Normal file
@@ -0,0 +1,76 @@
|
||||
using UnityEngine;
|
||||
using DG.Tweening;
|
||||
|
||||
public class PenWriter : MonoBehaviour
|
||||
{
|
||||
[Header("Assign the transform that moves up/down (pen or tip root)")]
|
||||
public Transform pen; // If null, uses this.transform
|
||||
|
||||
[Header("Motion Settings")]
|
||||
[Min(0f)] public float minDown = 0.2f; // minimum down stroke depth (in local units)
|
||||
[Min(0f)] public float maxDown = 0.6f; // maximum down stroke depth
|
||||
[Min(0f)] public float minDur = 0.04f; // min duration per tap
|
||||
[Min(0f)] public float maxDur = 0.10f; // max duration per tap
|
||||
[Range(0f, 1f)] public float upFraction = 0.35f; // fraction of tap duration for the up motion (snappy up)
|
||||
|
||||
private Vector3 localUpAxis;
|
||||
private Vector3 baseLocalPos;
|
||||
private bool writing;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
if (!pen) pen = transform;
|
||||
baseLocalPos = pen.localPosition;
|
||||
localUpAxis = transform.InverseTransformDirection(Vector3.up);
|
||||
}
|
||||
|
||||
public void StartWriting()
|
||||
{
|
||||
if (writing) return;
|
||||
writing = true;
|
||||
|
||||
// Ensure any previous tweens are stopped and we reset to rest
|
||||
DOTween.Kill(pen, complete: false);
|
||||
pen.localPosition = baseLocalPos;
|
||||
|
||||
// We<57>ll add a callback that keeps enqueuing the next tap until stopped
|
||||
EnqueueNextTap();
|
||||
}
|
||||
|
||||
public void StopWriting(bool snapToRest = true)
|
||||
{
|
||||
writing = false;
|
||||
DOTween.Kill(pen);
|
||||
|
||||
if (snapToRest)
|
||||
pen.localPosition = baseLocalPos;
|
||||
else
|
||||
{
|
||||
// Smoothly return to rest
|
||||
pen.DOLocalMove(baseLocalPos, 0.08f)
|
||||
.SetEase(Ease.OutSine);
|
||||
}
|
||||
}
|
||||
|
||||
private void EnqueueNextTap()
|
||||
{
|
||||
if (!writing) return;
|
||||
|
||||
float depth = Random.Range(minDown, maxDown);
|
||||
float dur = Random.Range(minDur, maxDur);
|
||||
|
||||
Vector3 downPos = baseLocalPos - localUpAxis * depth;
|
||||
|
||||
float upDur = Mathf.Max(0.01f, dur * upFraction);
|
||||
float downDur = Mathf.Max(0.01f, dur - upDur);
|
||||
|
||||
// Down (contact), then Up (lift)
|
||||
pen.DOLocalMove(downPos, downDur).OnComplete(() =>
|
||||
{
|
||||
pen.DOLocalMove(baseLocalPos, upDur).OnComplete(() =>
|
||||
{
|
||||
if (writing) EnqueueNextTap();
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 96a5bc0230ea8fe41b253c653699fecc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -7,8 +7,9 @@ using UnityEngine.XR.Interaction.Toolkit;
|
||||
public class CafeWaiterNPC : NPCController
|
||||
{
|
||||
public FMODWhisperBridge fmodWhisperBridge;
|
||||
public TextMeshProUGUI notepadText;
|
||||
public GameObject notepad;
|
||||
public TextMeshProUGUI notepadText;
|
||||
public PenWriter pen;
|
||||
|
||||
public Transform backRoom;
|
||||
public Transform plate;
|
||||
@@ -42,6 +43,7 @@ public class CafeWaiterNPC : NPCController
|
||||
notepadOriginalRotation = notepad.transform.localRotation.eulerAngles;
|
||||
notepadFlippedRotation = notepadOriginalRotation + new Vector3(0, 180, 0);
|
||||
notepad.SetActive(false);
|
||||
pen.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
protected override void OnPlayerApproach()
|
||||
@@ -55,6 +57,7 @@ public class CafeWaiterNPC : NPCController
|
||||
fmodWhisperBridge.OnWhisperSegmentFinished += OnPlayerSpeechFinished;
|
||||
|
||||
notepad.SetActive(true);
|
||||
pen.gameObject.SetActive(true);
|
||||
state = 1;
|
||||
}
|
||||
}
|
||||
@@ -69,6 +72,8 @@ public class CafeWaiterNPC : NPCController
|
||||
if (state != 3)
|
||||
{
|
||||
notepad.SetActive(false);
|
||||
pen.StopWriting();
|
||||
pen.gameObject.SetActive(false);
|
||||
notepad.transform.localRotation = Quaternion.Euler(notepadOriginalRotation);
|
||||
state = 0;
|
||||
}
|
||||
@@ -87,6 +92,8 @@ public class CafeWaiterNPC : NPCController
|
||||
// Show transcription and ask whether it is correct
|
||||
fmodWhisperBridge.DeactivateRecording();
|
||||
notepadText.text = playerText;
|
||||
pen.StopWriting();
|
||||
pen.gameObject.SetActive(false);
|
||||
notepad.transform.DOLocalRotate(notepadFlippedRotation, 0.5f).OnComplete(() =>
|
||||
{
|
||||
fmodWhisperBridge.ActivateRecording();
|
||||
@@ -98,23 +105,25 @@ public class CafeWaiterNPC : NPCController
|
||||
} else if (state == 2)
|
||||
{
|
||||
fmodWhisperBridge.DeactivateRecording();
|
||||
bool positiveAnswer = playerText.ToLower().Contains("ye") || playerText.ToLower().Contains("correct") | playerText.ToLower().Contains("right");
|
||||
SpeakVoiceLine(positiveAnswer ? 2 : 3);
|
||||
// Flip notepad back
|
||||
notepad.transform.DOLocalRotate(notepadOriginalRotation, 0.5f);
|
||||
// if player answered positively, bring food, otherwise ask again
|
||||
if (playerText.ToLower().Contains("ye"))
|
||||
notepad.transform.DOLocalRotate(notepadOriginalRotation, 0.5f).OnComplete(() =>
|
||||
{
|
||||
|
||||
SpeakVoiceLine(2);
|
||||
Invoke("BringFood", 1f);
|
||||
state = 3;
|
||||
} else
|
||||
{
|
||||
SpeakVoiceLine(3);
|
||||
fmodWhisperBridge.ActivateRecording();
|
||||
fmodWhisperBridge.OnWhisperSegmentUpdated += OnPlayerSpeechUpdated;
|
||||
fmodWhisperBridge.OnWhisperSegmentFinished += OnPlayerSpeechFinished;
|
||||
state = 1;
|
||||
}
|
||||
if (positiveAnswer)
|
||||
{
|
||||
Invoke("BringFood", 1f);
|
||||
state = 3;
|
||||
}
|
||||
else
|
||||
{
|
||||
fmodWhisperBridge.ActivateRecording();
|
||||
fmodWhisperBridge.OnWhisperSegmentUpdated += OnPlayerSpeechUpdated;
|
||||
fmodWhisperBridge.OnWhisperSegmentFinished += OnPlayerSpeechFinished;
|
||||
pen.gameObject.SetActive(true);
|
||||
state = 1;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -123,10 +132,8 @@ public class CafeWaiterNPC : NPCController
|
||||
// Only update notepad text when currently listening to player order
|
||||
if (state == 1)
|
||||
{
|
||||
pen.StartWriting();
|
||||
notepadText.text = playerText;
|
||||
|
||||
// For now, when something is transcribed, treat it as player finished speaking
|
||||
OnPlayerSpeechFinished(playerText);
|
||||
}
|
||||
// faster reaction to player answering yes/no
|
||||
else if (state == 2)
|
||||
|
||||
@@ -13,7 +13,7 @@ public class PushableButton : MonoBehaviour
|
||||
public Transform movableParts;
|
||||
public float moveDuration = 0.25f;
|
||||
public float moveAmount = 0.05f;
|
||||
public EventReference soundEffect = FMODEvents.Instance.Click;
|
||||
public EventReference soundEffect;
|
||||
|
||||
public MeshRenderer[] wires;
|
||||
public Material wireActiveMaterial;
|
||||
|
||||
Reference in New Issue
Block a user