BugReportScreenshotUtil.cs 772 B

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