您的位置:首页 > 移动开发 > Unity3D

Unity使用RenderTexture进行截屏

2015-10-29 16:54 579 查看
private IEnumerator cutScreen()
{
RenderTexture rt = new RenderTexture(Screen.width, Screen.height, 24);
m_mainCam.targetTexture = rt;
m_mainCam.Render();
m_auxCam.targetTexture = rt;
m_auxCam.Render();
m_nguiCam.targetTexture = rt;
m_nguiCam.Render();
RenderTexture.active = rt;

Texture2D tex = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false);
tex.ReadPixels(new Rect(0,0,Screen.width,Screen.height),0,0);
tex.Apply();

RenderTexture.active = null;
m_mainCam.targetTexture = null;
m_auxCam.targetTexture = null;
m_nguiCam.targetTexture = null;
Destroy(rt);

GameObject photo = new GameObject("photo");
UITexture uiTex = photo.AddComponent<UITexture>();
uiTex .mainTexture = tex;

photo.transform.parent = m_gamePanel.transform;
photo.transform.localPosition = new Vector3();
photo.transform.localScale = Vector3.one;
uiTex.width = 611;
uiTex.height = 344;

yield return null;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: