using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Rendering; using UnityEngine.UI; public class yanchi : MonoBehaviour { public RawImage rimage; public RenderTexture rt; Queue qlist = new Queue(); List list = new List(); // Start is called before the first frame update void Start() { for (int i = 0; i < maxcount; i++) { list.Add(new Texture2D(rt.width, rt.height, TextureFormat.RGBA32, false)); } StartCoroutine(GetRenederFPS()); } int maxcount = 1; int count=0; byte[] bts; IEnumerator GetRenederFPS() { yield return new WaitForSeconds(1) ; while (true) { var req = AsyncGPUReadback.Request(rt); yield return new WaitUntil(() => req.done); if (!req.hasError) { if (bts == null) { bts = new byte[req.layerDataSize]; } req.GetData().CopyTo(bts); list[count].LoadRawTextureData(bts); list[count].Apply(); qlist.Enqueue(list[count]); if (qlist.Count >= maxcount) { rimage.texture = qlist.Dequeue(); } count++; if(count>= list.Count) { count = 0; } // tex.SetPixels32(req.GetData().ToArray()); } else { Debug.LogError("Error AsyncGPUReadbackRequest.hasError"); } } } // Update is called once per frame void Update() { } }