2024-06-21 17:11:07 +02:00
|
|
|
using System.Collections;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using UnityEngine;
|
|
|
|
using System;
|
2024-07-15 15:55:13 +02:00
|
|
|
using UnityEngine.UI;
|
2024-06-21 17:11:07 +02:00
|
|
|
|
|
|
|
public class Screenshot : MonoBehaviour
|
|
|
|
{
|
2024-07-15 15:55:13 +02:00
|
|
|
[SerializeField]
|
|
|
|
RawImage _previewImg;
|
2024-06-21 17:11:07 +02:00
|
|
|
|
|
|
|
// Update is called once per frame
|
|
|
|
void Update()
|
|
|
|
{
|
|
|
|
//StartCoroutine(TakeScreenshot());
|
|
|
|
|
|
|
|
/* if (Input.GetKeyDown(KeyCode.P))
|
|
|
|
{
|
|
|
|
StartCoroutine(TakeScreenshot());
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
public void OnClickTakeScreenshot()
|
|
|
|
{
|
|
|
|
StartCoroutine(TakeScreenshot());
|
|
|
|
}
|
|
|
|
|
2024-07-15 15:55:13 +02:00
|
|
|
public void OnClickPreview()
|
|
|
|
{
|
|
|
|
StartCoroutine(CreatePreview());
|
|
|
|
}
|
|
|
|
|
|
|
|
public void DestroyPreviewTexture()
|
|
|
|
{
|
|
|
|
if (_previewImg.texture == true)
|
|
|
|
{
|
|
|
|
Destroy(_previewImg.texture);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-21 17:11:07 +02:00
|
|
|
IEnumerator TakeScreenshot()
|
|
|
|
{
|
|
|
|
yield return new WaitForEndOfFrame();
|
|
|
|
string timpStamp = DateTime.Now.ToString("ddMMyyyyHHmmssffff");
|
|
|
|
ScreenCapture.CaptureScreenshot("snapshot_" + timpStamp + ".png");
|
|
|
|
}
|
2024-07-15 15:55:13 +02:00
|
|
|
|
|
|
|
IEnumerator CreatePreview()
|
|
|
|
{
|
|
|
|
yield return new WaitForEndOfFrame();
|
|
|
|
_previewImg.texture = ScreenCapture.CaptureScreenshotAsTexture();
|
|
|
|
}
|
2024-06-21 17:11:07 +02:00
|
|
|
}
|