BugReportScreenshotUtil.cs 764 B

1234567891011121314151617181920212223242526272829
  1. namespace SRDebugger.Internal
  2. {
  3. using System.Collections;
  4. using UnityEngine;
  5. public class BugReportScreenshotUtil
  6. {
  7. public static byte[] ScreenshotData;
  8. public static IEnumerator ScreenshotCaptureCo()
  9. {
  10. if (ScreenshotData != null)
  11. {
  12. Debug.LogWarning("[SRDebugger] Warning, overriding existing screenshot data.");
  13. }
  14. yield return new WaitForEndOfFrame();
  15. var tex = new Texture2D(Screen.width, Screen.height, TextureFormat.RGB24, false);
  16. tex.ReadPixels(new Rect(0, 0, Screen.width, Screen.height), 0, 0);
  17. tex.Apply();
  18. ScreenshotData = tex.EncodeToPNG();
  19. Object.Destroy(tex);
  20. }
  21. }
  22. }