唔,直接丢在一个公共的静态类就可以了
QDebug:https://blog.csdn.net/qq_17813937/article/details/79801371
QFileOperation:https://blog.csdn.net/qq_17813937/article/details/81190245
/// <summary>
/// 截屏
/// </summary>
/// <param name="action"></param>
public static void CaptureScreenshot(Action action)
{
QCoroutine.Start(CaptureScreenshotIEnumerator(action));
}
private static IEnumerator CaptureScreenshotIEnumerator(Action action)
{
var screenshotPath = Application.persistentDataPath + "/Screenshot.jpg";
QFileOperation.DeleteFile(screenshotPath);
ScreenCapture.CaptureScreenshot("Screenshot.jpg");
yield return new WaitForSeconds(1f);
#if UNITY_ANDROID || UNITY_IPHONE
//添加到相册
string path = Application.persistentDataPath.Substring(0, Application.persistentDataPath.IndexOf("Android"));
path += "DCIM/Camera";
QFileOperation.CreateDirctory(path);
var filePath = string.Format("{0}/{1}.jpg", path, QGlobalFun.GetCurTime());
var texture = QFileOperation.ReadTexture2D(screenshotPath);
QDebug.Log("读取图片");
QFileOperation.WriteBytes(filePath, texture.EncodeToJPG());
QDebug.Log("写入相册 "+filePath);
QGlobalFun.ScanFile(new string[] { filePath });
QDebug.Log("刷新相册");
GameObject.Destroy(texture);
QFileOperation.DeleteFile(screenshotPath);
#else
#endif
action();
}