using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Rendering; using UnityEngine.UI; public class TestThreadCamera : MonoBehaviour { public Camera ca; Texture2D screenShot; // Start is called before the first frame update void Start() { RenderTexture rt = new RenderTexture(640, 480, 0, RenderTextureFormat.ARGB32); ca.targetTexture = rt; screenShot = new Texture2D(ca.targetTexture.width,ca.targetTexture.height,TextureFormat.RGBA32, false); StartCoroutine(GetRenederFPS()); } // Update is called once per frame void Update() { } byte[] bts; IEnumerator GetRenederFPS() { while (true) { var req = AsyncGPUReadback.Request(ca.targetTexture,0, TextureFormat.RGBA32); yield return new WaitUntil(() => req.done); if (!req.hasError) { if (bts == null) { bts = new byte[req.layerDataSize]; } req.GetData().CopyTo(bts); screenShot.LoadRawTextureData(bts); screenShot.Apply(); // tex.SetPixels32(req.GetData().ToArray()); this.GetComponent().texture = screenShot; } else { Debug.LogError("Error AsyncGPUReadbackRequest.hasError"); } } } }