|
@@ -449,24 +449,33 @@ namespace GFGGame
|
|
|
|
|
|
public static NTexture GetPrintscreenNTexture(Camera camera)
|
|
public static NTexture GetPrintscreenNTexture(Camera camera)
|
|
{
|
|
{
|
|
- Rect rect = new Rect(0, 0, UnityEngine.Screen.width, UnityEngine.Screen.height);
|
|
|
|
- RenderTexture render = new RenderTexture((int)rect.width, (int)rect.height, -1);//创建一个RenderTexture对象
|
|
|
|
|
|
+ // Rect rect = new Rect(0, 0, UnityEngine.Screen.width, UnityEngine.Screen.height);
|
|
|
|
+ // RenderTexture render = new RenderTexture((int)rect.width, (int)rect.height, -1);//创建一个RenderTexture对象
|
|
|
|
|
|
- // camera.gameObject.SetActive(true);//启用截图相机
|
|
|
|
- camera.targetTexture = render;//设置截图相机的targetTexture为render
|
|
|
|
- camera.Render();//手动开启截图相机的渲染
|
|
|
|
|
|
+ // // camera.gameObject.SetActive(true);//启用截图相机
|
|
|
|
+ // camera.targetTexture = render;//设置截图相机的targetTexture为render
|
|
|
|
+ // camera.Render();//手动开启截图相机的渲染
|
|
|
|
|
|
- RenderTexture.active = render;//激活RenderTexture
|
|
|
|
- Texture2D tex = new Texture2D((int)rect.width, (int)rect.height, TextureFormat.ARGB32, false);//新建一个Texture2D对象
|
|
|
|
- tex.ReadPixels(rect, 0, 0);//读取像素
|
|
|
|
- tex.Apply();//保存像素信息
|
|
|
|
|
|
+ // RenderTexture.active = render;//激活RenderTexture
|
|
|
|
+ // Texture2D tex = new Texture2D((int)rect.width, (int)rect.height, TextureFormat.ARGB32, false);//新建一个Texture2D对象
|
|
|
|
+ // tex.ReadPixels(rect, 0, 0);//读取像素
|
|
|
|
+ // tex.Apply();//保存像素信息
|
|
|
|
|
|
- camera.targetTexture = null;//重置截图相机的targetTexture
|
|
|
|
- RenderTexture.active = null;//关闭RenderTexture的激活状态
|
|
|
|
- Object.Destroy(render);//删除RenderTexture对象
|
|
|
|
|
|
+ // camera.targetTexture = null;//重置截图相机的targetTexture
|
|
|
|
+ // RenderTexture.active = null;//关闭RenderTexture的激活状态
|
|
|
|
+ // Object.Destroy(render);//删除RenderTexture对象
|
|
// camera.gameObject.SetActive(true);
|
|
// camera.gameObject.SetActive(true);
|
|
-
|
|
|
|
- return new NTexture(tex);
|
|
|
|
|
|
+ RenderTexture rt = new RenderTexture(UnityEngine.Screen.width, UnityEngine.Screen.height, 0);//渲染一张1920*1080的图
|
|
|
|
+ camera.targetTexture = rt;//传到主摄像机上
|
|
|
|
+ camera.Render();//渲染
|
|
|
|
+ RenderTexture.active = rt;
|
|
|
|
+ Texture2D screenShot = new Texture2D(UnityEngine.Screen.width, UnityEngine.Screen.height, TextureFormat.ARGB32, false);
|
|
|
|
+ screenShot.ReadPixels(new Rect(0, 0, UnityEngine.Screen.width, UnityEngine.Screen.height), 0, 0);//读像素
|
|
|
|
+ screenShot.Apply();
|
|
|
|
+ camera.targetTexture = null;
|
|
|
|
+ RenderTexture.active = null;
|
|
|
|
+ Object.Destroy(rt);
|
|
|
|
+ return new NTexture(screenShot);
|
|
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|