forked from cgvr/DeltaVR
moved archery range model generation logic to npc script, added corresponding voicelines
This commit is contained in:
@@ -1,99 +0,0 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using FMOD.Studio;
|
||||
|
||||
public class ArcheryRangeModelGenerationController : MonoBehaviour
|
||||
{
|
||||
public MicrophoneStand microphoneStand;
|
||||
public PushableButton imageGenerationButton;
|
||||
public PushableButton modelGenerationButton;
|
||||
|
||||
public Texture2D GeneratedTexture { get; private set; }
|
||||
public Image imageDisplay;
|
||||
|
||||
public GameObject GeneratedModel { get; private set; }
|
||||
public float generatedObjectRotationSpeed = 10f;
|
||||
|
||||
public Transform modelDisplay;
|
||||
public Material modelDisplayActiveMaterial;
|
||||
public Transform wire;
|
||||
public Material wireActiveMaterial;
|
||||
public NPCController npcController;
|
||||
|
||||
private bool modelGenerationInProgress;
|
||||
private EventInstance printingSound;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
imageGenerationButton.OnButtonPressed += InvokeImageGeneration;
|
||||
modelGenerationButton.OnButtonPressed += InvokeModelGeneration;
|
||||
modelGenerationInProgress = false;
|
||||
|
||||
printingSound = AudioManager.Instance.CreateInstance(FMODEvents.Instance.Printing);
|
||||
printingSound.setParameterByName("3DPrinterPrintingJob", 1);
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (GeneratedModel != null)
|
||||
{
|
||||
GeneratedModel.transform.Rotate(Vector3.up, generatedObjectRotationSpeed * Time.deltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
private async void InvokeImageGeneration()
|
||||
{
|
||||
string inputPrompt = microphoneStand.GetTextOutput();
|
||||
byte[] imageBytes = await InvokeAiClient.Instance.GenerateImage(inputPrompt);
|
||||
GeneratedTexture = ModelGenerationUtils.CreateTexture(imageBytes);
|
||||
Sprite sprite = ModelGenerationUtils.CreateSprite(GeneratedTexture);
|
||||
imageDisplay.sprite = sprite;
|
||||
|
||||
imageGenerationButton.Deactivate();
|
||||
if (!modelGenerationInProgress)
|
||||
{
|
||||
modelGenerationButton.Deactivate();
|
||||
}
|
||||
|
||||
npcController.SpeakVoiceLine(3);
|
||||
}
|
||||
|
||||
private async void InvokeModelGeneration()
|
||||
{
|
||||
modelGenerationInProgress = true;
|
||||
|
||||
printingSound.start();
|
||||
printingSound.setParameterByName("3DPrinterPrintingJob", 0);
|
||||
|
||||
string encodedTexture = Convert.ToBase64String(GeneratedTexture.EncodeToJPG());
|
||||
byte[] encodedModel = await TrellisClient.Instance.GenerateModel(encodedTexture);
|
||||
|
||||
GameObject spawnedObject = await ModelGenerationUtils.Instance.SpawnModel(encodedModel);
|
||||
// Destroy previous generated object
|
||||
Destroy(GeneratedModel);
|
||||
spawnedObject.transform.parent = modelDisplay;
|
||||
spawnedObject.transform.position = modelDisplay.position;
|
||||
GeneratedModel = spawnedObject;
|
||||
|
||||
printingSound.setParameterByName("3DPrinterPrintingJob", 1);
|
||||
npcController.SpeakVoiceLine(4);
|
||||
|
||||
OnModelReady();
|
||||
modelGenerationButton.Deactivate();
|
||||
modelGenerationInProgress = false;
|
||||
}
|
||||
|
||||
private void OnModelReady()
|
||||
{
|
||||
foreach (MeshRenderer meshRenderer in wire.GetComponentsInChildren<MeshRenderer>())
|
||||
{
|
||||
meshRenderer.material = wireActiveMaterial;
|
||||
}
|
||||
|
||||
modelDisplay.GetComponent<MeshRenderer>().material = modelDisplayActiveMaterial;
|
||||
AudioManager.Instance.PlayAttachedInstance(FMODEvents.Instance.ShapeScannerSuccess, gameObject);
|
||||
}
|
||||
}
|
||||
@@ -8,9 +8,11 @@ public class MicrophoneStand : MonoBehaviour
|
||||
public GameObject microphoneOffStatus;
|
||||
public GameObject microphoneOnStatus;
|
||||
|
||||
public NPCController npcController;
|
||||
public FMODWhisperBridge fmodWhisperBridge;
|
||||
|
||||
public delegate void OnPlayerFinishedSpeakingDelegate();
|
||||
public event OnPlayerFinishedSpeakingDelegate OnPlayerFinishedSpeaking;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
@@ -31,16 +33,12 @@ public class MicrophoneStand : MonoBehaviour
|
||||
|
||||
if (controller != null || other.gameObject.tag == "Player Head")
|
||||
{
|
||||
fmodWhisperBridge.OnWhisperSegmentUpdated += OnPlayerSpeech;
|
||||
fmodWhisperBridge.OnWhisperSegmentFinished += OnPlayerSpeech;
|
||||
fmodWhisperBridge.OnWhisperSegmentUpdated += OnPlayerSpeechUpdated;
|
||||
fmodWhisperBridge.OnWhisperSegmentFinished += OnPlayerSpeechFinished;
|
||||
|
||||
microphoneOffStatus.SetActive(false);
|
||||
microphoneOnStatus.SetActive(true);
|
||||
AudioManager.Instance.PlayAttachedInstance(FMODEvents.Instance.RadioButton, gameObject);
|
||||
if (npcController != null)
|
||||
{
|
||||
npcController.SpeakVoiceLine(1);
|
||||
}
|
||||
fmodWhisperBridge.ActivateRecording();
|
||||
}
|
||||
}
|
||||
@@ -50,31 +48,29 @@ public class MicrophoneStand : MonoBehaviour
|
||||
KbmController controller = other.GetComponent<KbmController>();
|
||||
if (controller != null | other.gameObject.tag == "Player Head")
|
||||
{
|
||||
fmodWhisperBridge.OnWhisperSegmentUpdated -= OnPlayerSpeech;
|
||||
fmodWhisperBridge.OnWhisperSegmentFinished -= OnPlayerSpeech;
|
||||
fmodWhisperBridge.OnWhisperSegmentUpdated -= OnPlayerSpeechUpdated;
|
||||
fmodWhisperBridge.OnWhisperSegmentFinished -= OnPlayerSpeechFinished;
|
||||
|
||||
microphoneOffStatus.SetActive(true);
|
||||
microphoneOnStatus.SetActive(false);
|
||||
AudioManager.Instance.PlayAttachedInstance(FMODEvents.Instance.RadioButton, gameObject);
|
||||
if (npcController != null)
|
||||
{
|
||||
npcController.SpeakVoiceLine(2);
|
||||
}
|
||||
fmodWhisperBridge.DeactivateRecording();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnPlayerSpeech(string text)
|
||||
private void OnPlayerSpeechUpdated(string text)
|
||||
{
|
||||
if (string.IsNullOrEmpty(text) || text.Contains("BLANK_AUDIO"))
|
||||
{
|
||||
return;
|
||||
}
|
||||
outputText.text = text;
|
||||
}
|
||||
|
||||
private void OnPlayerSpeechFinished(string playerText)
|
||||
{
|
||||
OnPlayerFinishedSpeaking?.Invoke();
|
||||
}
|
||||
|
||||
public string GetTextOutput()
|
||||
{
|
||||
return outputText.text;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class ModelDisplay : MonoBehaviour
|
||||
{
|
||||
public Material modelDisplayActiveMaterial;
|
||||
public Transform wire;
|
||||
public Material wireActiveMaterial;
|
||||
|
||||
public GameObject Model { get; private set; }
|
||||
public float generatedObjectRotationSpeed = 10f;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (Model != null)
|
||||
{
|
||||
Model.transform.Rotate(Vector3.up, generatedObjectRotationSpeed * Time.deltaTime);
|
||||
}
|
||||
}
|
||||
|
||||
public void DisplayModel(GameObject modelObject)
|
||||
{
|
||||
foreach (MeshRenderer meshRenderer in wire.GetComponentsInChildren<MeshRenderer>())
|
||||
{
|
||||
meshRenderer.material = wireActiveMaterial;
|
||||
}
|
||||
|
||||
gameObject.GetComponent<MeshRenderer>().material = modelDisplayActiveMaterial;
|
||||
AudioManager.Instance.PlayAttachedInstance(FMODEvents.Instance.ShapeScannerSuccess, gameObject);
|
||||
|
||||
// Destroy previous generated object
|
||||
Destroy(Model);
|
||||
modelObject.transform.parent = transform;
|
||||
modelObject.transform.position = transform.position;
|
||||
Model = modelObject;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 99e1fdda206b5d04082b6a45593a1e84
|
||||
guid: 4034b87c80896fe4d9e18ef54faa1ef6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
Reference in New Issue
Block a user