12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- 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<Texture2D> qlist = new Queue<Texture2D>();
- List<Texture2D> list = new List<Texture2D>();
- // 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<byte>().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<Color32>().ToArray());
- }
- else
- {
- Debug.LogError("Error AsyncGPUReadbackRequest.hasError");
- }
- }
- }
- // Update is called once per frame
- void Update()
- {
- }
- }
|