在Unity中想要实现全屏截图或者截取某个对象区域的图片都是可以通过下面的函数进行截取
Texture2D
/// <summary>
/// <para>Reads the pixels from the current render target (the screen, or a RenderTexture), and writes them to the texture.</para>
/// </summary>
/// <param name="source">The region of the render target to read from.</param>
/// <param name="destX">The horizontal pixel position in the texture to write the pixels to.</param>
/// <param name="destY">The vertical pixel position in the texture to write the pixels to.</param>
/// <param name="recalculateMipMaps">If this parameter is true, Unity automatically recalculates the mipmaps for the texture after writing the pixel data. Otherwise, Unity does not do this automatically.</param>
public void ReadPixels(Rect source, int destX, int destY, [DefaultValue("true")] bool recalculateMipMaps)
Texture2D.ReadPixels() 函数参数可以翻译注释了解用法,比较简单,我下面简单说一下:
source: 读取像素的区域,坐标起点是 左下角,这个要注意
destX: 读取后写入到texture的坐标X
destY: 读取后写入到texture的坐标Y
recalculateMipMaps :