using System.Collections; using System.Collections.Generic; using UnityEngine; using System; using UnityEngine.UI; using Oculus.Platform; public class Screenshot : MonoBehaviour { [SerializeField] RawImage _previewImg; GameObject XRCamera; //the XR Player Camera, named "Main Camera" GameObject XRHoloVideoCamera; //the XR Player Camera, named "Main Camera no-post-processing" GameObject SmartphoneCaptureCamera; //the GameObject, named "SmartphoneCaptureCamera" is a Camera with a CullingMask where the Layer "hands" is excluded ("_HANDMENU" and "XR Interactions Hands Setup" are on the "hands" layer) // Update is called once per frame void Update() { //StartCoroutine(TakeScreenshot()); /* if (Input.GetKeyDown(KeyCode.P)) { StartCoroutine(TakeScreenshot()); } */ } public void OnClickTakeScreenshot() { StartCoroutine(TakeScreenshot()); } public void OnClickPreview() { StartCoroutine(CreatePreview()); } public void DestroyPreviewTexture() { if (_previewImg.texture == true) { Destroy(_previewImg.texture); } } IEnumerator TakeScreenshot() { yield return new WaitForEndOfFrame(); string timpStamp = DateTime.Now.ToString("ddMMyyyyHHmmssffff"); ScreenCapture.CaptureScreenshot("snapshot_" + timpStamp + ".png"); } IEnumerator CreatePreview() { yield return new WaitForEndOfFrame(); // find all Cameras: XRCamera = GameObject.Find("Main Camera"); XRHoloVideoCamera = GameObject.Find("Main Camera no-post-processing"); SmartphoneCaptureCamera = GameObject.Find("SmartphoneCaptureCamera"); // get the Camera components: Camera vrcam = XRCamera.GetComponent(); Camera vrcamnopost = XRHoloVideoCamera.GetComponent(); Camera capturecam = SmartphoneCaptureCamera.GetComponent(); // switch active Cameras vrcam.enabled = false; vrcamnopost.enabled = false; capturecam.enabled = true; // call the function to take actual screenshot _previewImg.texture = ScreenCapture.CaptureScreenshotAsTexture(); // switch active Cameras back vrcam.enabled = true; vrcamnopost.enabled = true; capturecam.enabled = false; } }