1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- 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<byte>().CopyTo(bts);
- screenShot.LoadRawTextureData(bts);
- screenShot.Apply();
- // tex.SetPixels32(req.GetData<Color32>().ToArray());
- this.GetComponent<RawImage>().texture = screenShot;
- }
- else
- {
- Debug.LogError("Error AsyncGPUReadbackRequest.hasError");
- }
- }
- }
- }
|