/// <summary>/// 截图/// </summary>/// <param name="rect"></param>/// <returns></returns>IEnumerator CaptureScreenshot2(Rect rect){yield return new WaitForEndOfFrame();// 先创建一个的空纹理,大小可根据实现需要来设置 Texture2D screenShot = new Texture2D((int)rect.width, (int)rect.height, TextureFormat.RGB24, false);// 读取屏幕像素信息并存储为纹理数据, screenShot.ReadPixels(rect, 0, 0);screenShot.Apply();// 然后将这些纹理数据,成一个png图片文件 byte[] bytes = screenShot.EncodeToPNG();string filename = Application.streamingAssetsPath + "/1.jpg";System.IO.File.WriteAllBytes(filename, bytes);Debug.Log(string.Format("截屏了一张图片: {0}", filename));}