forked from cgvr/DeltaVR
43 lines
1.2 KiB
C#
43 lines
1.2 KiB
C#
using DG.Tweening;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
|
|
public class ComputerPrinter : MonoBehaviour
|
|
{
|
|
public TextMeshProUGUI textDisplay;
|
|
public PushableButton enterKey;
|
|
public Transform ejectionOrigin;
|
|
public Transform ejectionDestination;
|
|
public Printable 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);
|
|
|
|
Printable printable = Instantiate(printablePrefab, ejectionOrigin.position, Quaternion.identity);
|
|
printable.AttachTexture(generatedTexture);
|
|
|
|
printable.transform.DOMove(ejectionDestination.position, ejectionDuration).OnComplete(() =>
|
|
{
|
|
Rigidbody printableRigidbody = printable.GetComponent<Rigidbody>();
|
|
printableRigidbody.isKinematic = false;
|
|
enterKey.Deactivate();
|
|
});
|
|
}
|
|
}
|