30 lines
919 B
C#
30 lines
919 B
C#
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);
|
|
}
|
|
|
|
public static T GetOrAddComponent<T>(this GameObject uo) where T : Component
|
|
{
|
|
return uo.GetComponent<T>() ?? uo.AddComponent<T>();
|
|
}
|
|
}
|
|
} |