forked from cgvr/DeltaVR
cafe waiter generates model and spawns it on top of plate
This commit is contained in:
Binary file not shown.
@@ -1,6 +1,8 @@
|
||||
using DG.Tweening;
|
||||
using System;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.XR.Interaction.Toolkit;
|
||||
|
||||
public class CafeWaiterNPC : NPCController
|
||||
{
|
||||
@@ -9,8 +11,11 @@ public class CafeWaiterNPC : NPCController
|
||||
public GameObject notepad;
|
||||
|
||||
public Transform backRoom;
|
||||
public Transform plate;
|
||||
public float backRoomMovingTime = 5f;
|
||||
|
||||
public int ignorePlayerCollisionLayer = 2;
|
||||
|
||||
private Vector3 notepadOriginalRotation;
|
||||
private Vector3 notepadFlippedRotation;
|
||||
private Vector3 startingPosition;
|
||||
@@ -35,6 +40,7 @@ public class CafeWaiterNPC : NPCController
|
||||
{
|
||||
notepadOriginalRotation = notepad.transform.localRotation.eulerAngles;
|
||||
notepadFlippedRotation = notepadOriginalRotation + new Vector3(0, 180, 0);
|
||||
notepad.SetActive(false);
|
||||
}
|
||||
|
||||
protected override void OnPlayerApproach()
|
||||
@@ -47,6 +53,8 @@ public class CafeWaiterNPC : NPCController
|
||||
fmodWhisperBridge.OnWhisperSegmentFinished += OnPlayerSpeechFinished;
|
||||
fmodWhisperBridge.ActivateRecording();
|
||||
|
||||
notepad.SetActive(true);
|
||||
|
||||
state = 1;
|
||||
}
|
||||
}
|
||||
@@ -94,7 +102,7 @@ public class CafeWaiterNPC : NPCController
|
||||
if (playerText.ToLower().Contains("yes"))
|
||||
{
|
||||
AudioManager.Instance.PlayDialogue(voiceLineKeys[2], gameObject);
|
||||
BringFood();
|
||||
Invoke("BringFood", 1f);
|
||||
state = 3;
|
||||
} else
|
||||
{
|
||||
@@ -110,22 +118,48 @@ public class CafeWaiterNPC : NPCController
|
||||
{
|
||||
return;
|
||||
}
|
||||
notepadText.text = playerText;
|
||||
// Only update notepad text when currently listening to player order
|
||||
if (state == 1)
|
||||
{
|
||||
notepadText.text = playerText;
|
||||
}
|
||||
}
|
||||
|
||||
private void BringFood()
|
||||
private async void BringFood()
|
||||
{
|
||||
notepad.SetActive(false);
|
||||
transform.DOMove(backRoom.position, backRoomMovingTime).OnComplete(() =>
|
||||
{
|
||||
// Come back
|
||||
transform.DOMove(startingPosition, backRoomMovingTime).OnComplete(() =>
|
||||
{
|
||||
notepad.SetActive(true);
|
||||
AudioManager.Instance.PlayDialogue(voiceLineKeys[4], gameObject);
|
||||
transform.DOMove(backRoom.position, backRoomMovingTime);
|
||||
|
||||
state = 4;
|
||||
});
|
||||
byte[] imageBytes = await InvokeAiClient.Instance.GenerateImage(notepadText.text);
|
||||
Texture2D GeneratedTexture = ModelGenerationUtils.CreateTexture(imageBytes);
|
||||
Sprite sprite = ModelGenerationUtils.CreateSprite(GeneratedTexture);
|
||||
string encodedTexture = Convert.ToBase64String(GeneratedTexture.EncodeToJPG());
|
||||
byte[] encodedModel = await TrellisClient.Instance.GenerateModel(encodedTexture);
|
||||
GameObject spawnedObject = await ModelGenerationUtils.Instance.SpawnModel(encodedModel);
|
||||
|
||||
// Come back
|
||||
transform.DOMove(startingPosition, backRoomMovingTime).OnComplete(() =>
|
||||
{
|
||||
spawnedObject.transform.position = plate.position + new Vector3(0, 1f, 0);
|
||||
InitializeSpawnedObject(spawnedObject);
|
||||
|
||||
AudioManager.Instance.PlayDialogue(voiceLineKeys[4], gameObject);
|
||||
|
||||
state = 4;
|
||||
});
|
||||
}
|
||||
|
||||
private void InitializeSpawnedObject(GameObject spawnedObject)
|
||||
{
|
||||
Rigidbody rigidbody = spawnedObject.AddComponent<Rigidbody>();
|
||||
|
||||
//spawnedObject.AddComponent<NetworkObject>();
|
||||
//spawnedObject.AddComponent<NetworkTransform>();
|
||||
|
||||
MeshCollider spawnedObjectCollider = spawnedObject.GetComponent<MeshCollider>();
|
||||
spawnedObjectCollider.convex = true;
|
||||
spawnedObject.layer = ignorePlayerCollisionLayer;
|
||||
|
||||
spawnedObject.AddComponent<XRGrabInteractable>();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user