forked from cgvr/DeltaVR
computer screen shows text, pressing enter key prints out image
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
using DG.Tweening;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class ComputerPrinter : MonoBehaviour
|
||||
{
|
||||
public TextMeshProUGUI textDisplay;
|
||||
public PushableButton enterKey;
|
||||
public Transform ejectionOrigin;
|
||||
public Transform ejectionDestination;
|
||||
public GameObject printablePrefab;
|
||||
public float ejectionDuration = 1.0f;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
enterKey.OnButtonPressed += PrintImage;
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private async void PrintImage()
|
||||
{
|
||||
string inputPrompt = textDisplay.text;
|
||||
byte[] imageBytes = await InvokeAiClient.Instance.GenerateImage(inputPrompt);
|
||||
Texture2D generatedTexture = ModelGenerationUtils.CreateTexture(imageBytes);
|
||||
Sprite sprite = ModelGenerationUtils.CreateSprite(generatedTexture);
|
||||
|
||||
GameObject printable = Instantiate(printablePrefab, ejectionOrigin.position, Quaternion.identity);
|
||||
Image printableDisplay = printable.GetComponentInChildren<Image>();
|
||||
printableDisplay.sprite = sprite;
|
||||
|
||||
printable.transform.DOMove(ejectionDestination.position, ejectionDuration).OnComplete(() =>
|
||||
{
|
||||
Rigidbody printableRigidbody = printable.GetComponent<Rigidbody>();
|
||||
printableRigidbody.isKinematic = false;
|
||||
enterKey.Deactivate();
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user