forked from cgvr/DeltaVR
created ShapeDetectionNPC with voicelines, moved shape detection minigame controller logic inside it
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.XR.Interaction.Toolkit;
|
||||
|
||||
public class RadioTransmitter : XRGrabInteractable
|
||||
{
|
||||
public delegate void OnPlayerPickUpDelegate();
|
||||
public event OnPlayerPickUpDelegate OnPlayerPickUp;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected override void OnSelectEntered(SelectEnterEventArgs args)
|
||||
{
|
||||
base.OnSelectEntered(args);
|
||||
OnPlayerPickUp?.Invoke();
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7000d3fd17422c74e9f86757bc8529f0
|
||||
guid: d5f509001c54a4e4794e50075eb0e214
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
@@ -1,91 +0,0 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class ShapeDetectionMinigameController : 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 Transform modelSpawnPoint;
|
||||
public string shapeScannerTag = "ShapeScannable";
|
||||
public int ignorePlayerCollisionLayer = 2;
|
||||
|
||||
private bool modelGenerationInProgress;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
imageGenerationButton.OnButtonPressed += InvokeImageGeneration;
|
||||
modelGenerationButton.OnButtonPressed += InvokeModelGeneration;
|
||||
modelGenerationInProgress = false;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
private async void InvokeModelGeneration()
|
||||
{
|
||||
modelGenerationInProgress = true;
|
||||
string encodedTexture = Convert.ToBase64String(GeneratedTexture.EncodeToJPG());
|
||||
byte[] encodedModel = await TrellisClient.Instance.GenerateModel(encodedTexture);
|
||||
|
||||
GameObject spawnedObject = await ModelGenerationUtils.Instance.SpawnModel(encodedModel);
|
||||
InitializeSpawnedObject(spawnedObject);
|
||||
|
||||
if (GeneratedModel != null)
|
||||
{
|
||||
// Destroy previous generated object (first move out of ShapeScanner to trigger OnTriggerExit
|
||||
GeneratedModel.transform.position = Vector3.zero;
|
||||
//Destroy(GeneratedModel);
|
||||
}
|
||||
GeneratedModel = spawnedObject;
|
||||
|
||||
modelGenerationButton.Deactivate();
|
||||
modelGenerationInProgress = false;
|
||||
}
|
||||
|
||||
private void InitializeSpawnedObject(GameObject spawnedObject)
|
||||
{
|
||||
GameObject spawnedObjectParent = new GameObject("SpawnedModelParent");
|
||||
spawnedObjectParent.transform.parent = modelSpawnPoint;
|
||||
spawnedObjectParent.transform.position = modelSpawnPoint.transform.position;
|
||||
spawnedObjectParent.layer = ignorePlayerCollisionLayer;
|
||||
Rigidbody rigidbody = spawnedObjectParent.AddComponent<Rigidbody>();
|
||||
rigidbody.isKinematic = true;
|
||||
|
||||
//spawnedObject.AddComponent<NetworkObject>();
|
||||
//spawnedObject.AddComponent<NetworkTransform>();
|
||||
|
||||
MeshCollider spawnedObjectCollider = spawnedObject.GetComponent<MeshCollider>();
|
||||
spawnedObjectCollider.convex = false;
|
||||
spawnedObject.transform.parent = spawnedObjectParent.transform;
|
||||
spawnedObject.transform.position = spawnedObjectParent.transform.position;
|
||||
spawnedObject.tag = shapeScannerTag;
|
||||
spawnedObject.layer = ignorePlayerCollisionLayer;
|
||||
|
||||
spawnedObjectParent.AddComponent<TwoHandScaleGrabInteractable>();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user