This commit is contained in:
bob
2025-05-28 20:14:34 +08:00
parent 69c57e3a39
commit 8e7afd9ea1
31 changed files with 338 additions and 22 deletions

View File

@@ -0,0 +1,53 @@
using UnityEditor;
using UnityEngine;
using System.IO;
public class ScreenshotCapturer : MonoBehaviour
{
#if UNITY_EDITOR
private void Update()
{
if (Input.GetKeyDown(KeyCode.F12))
{
CaptureScreenshot();
}
}
private void CaptureScreenshot()
{
// 获取Assets上一级目录路径
string projectPath = Directory.GetParent(Application.dataPath).FullName;
string screenshotDir = Path.Combine(projectPath, "Screenshots");
// 如果目录不存在则创建
if (!Directory.Exists(screenshotDir))
{
Directory.CreateDirectory(screenshotDir);
}
// 生成基于时间的文件名
string timestamp = System.DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss");
string filename = $"Screenshot_{timestamp}.png";
string fullPath = Path.Combine(screenshotDir, filename);
// 确保文件名唯一
int counter = 1;
while (File.Exists(fullPath))
{
filename = $"Screenshot_{timestamp}_{counter}.png";
fullPath = Path.Combine(screenshotDir, filename);
counter++;
}
// 截取屏幕
ScreenCapture.CaptureScreenshot(fullPath);
Debug.Log($"Screenshot saved to: {fullPath}");
// 刷新资源数据库(如果需要)
AssetDatabase.Refresh();
}
#endif
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 0c9b2dc114877d3479675dbe81e42739