forked from cgvr/DeltaVR
46 lines
1.4 KiB
C#
46 lines
1.4 KiB
C#
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();
|
|
});
|
|
}
|
|
}
|