/// <summary>
/// 截取的ui,任意位置截取
/// </summary>
public IEnumerator CaptureByUI(RectTransform UIRect)
{
//等待帧画面渲染结束
yield return new WaitForEndOfFrame();
int width = (int)(UIRect.rect.width);
int height = (int)(UIRect.rect.height);
Texture2D screenTure = new Texture2D(width, height, TextureFormat.RGB24, false);
//左下角为原点(0, 0)
float leftBtmX = UIRect.transform.position.x + UIRect.rect.xMin;
float leftBtmY = UIRect.transform.position.y + UIRect.rect.yMin;
//从屏幕读取像素, leftBtmX/leftBtnY 是读取的初始位置,width、height是读取像素的宽度和高度
screenTure.ReadPixels(new Rect(leftBtmX, leftBtmY, width, height), 0, 0);
//执行读取操作
screenTure.Apply();
byte[] bytes = screenTure.EncodeToPNG();
}