12345678910111213141516171819202122232425262728293031323334 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class PhotoShopCamera : MonoBehaviour
- {
- public Camera shotCam;
- public Action<Texture2D> onRenderFinish;
- public void Awake()
- {
- shotCam = GetComponent<Camera>();
- }
- public void OnPostRender()
- {
- //设定当前RenderTexture为快照相机的targetTexture
- RenderTexture rt = shotCam.targetTexture;
- RenderTexture.active = rt;
- Texture2D tex = new Texture2D(rt.width, rt.height);
-
- //读取缓冲区像素信息
- tex.ReadPixels(new Rect(0, 0, rt.width, rt.height), 0, 0);
- tex.Apply();
- if (onRenderFinish != null)
- {
- onRenderFinish.Invoke(tex);
- }
- Destroy(tex);
- }
- }
|