Framwork/Assets/Scripts/Runtime/Helper/CommonHelper.cs

25 lines
747 B
C#
Raw Normal View History

2025-05-23 16:24:00 +08:00
using System.Collections;
using System.IO;
using UnityEngine;
namespace Runtime.Helper
{
public static class CommonHelper
{
// captureRect = new Rect(0, 200, 1080, 1500);
private static IEnumerator CaptureCoroutine(Rect captureRect,string savePath)
{
yield return new WaitForEndOfFrame();
Texture2D screenShot =
new Texture2D((int)captureRect.width, (int)captureRect.height, TextureFormat.RGB24, false);
screenShot.ReadPixels(captureRect, 0, 0);
screenShot.Apply();
byte[] bytes = screenShot.EncodeToPNG();
File.WriteAllBytes(savePath, bytes);
Debug.Log("Screenshot saved to: " + savePath);
}
}
}