| 12345678910111213141516171819202122232425262728293031323334353637 |
- using UnityEngine;
- using UnityEditor;
- using System.IO;
- public static class ScreenshotToolEditor
- {
- private const string PREF_KEY_LAST_PATH = "ScreenshotTool_LastPath";
- [MenuItem("Tools/截图/捕获当前屏幕 %#s")] // Ctrl/Cmd + Shift + S
- public static void CaptureScreenshot()
- {
- // 从 EditorPrefs 读取上次保存的路径
- string lastPath = EditorPrefs.GetString(PREF_KEY_LAST_PATH, Application.dataPath);
- // 弹出保存对话框
- string path = EditorUtility.SaveFilePanel(
- "选择截图保存位置",
- lastPath, // 👈 打开上次使用的文件夹
- "Screenshot",
- "png"
- );
- if (string.IsNullOrEmpty(path))
- {
- Debug.Log("📸 截图已取消。");
- return;
- }
- // 保存路径下次复用
- string directory = Path.GetDirectoryName(path);
- EditorPrefs.SetString(PREF_KEY_LAST_PATH, directory);
- // 执行截图
- ScreenCapture.CaptureScreenshot(path, 1);
- Debug.Log($"✅ 截图已保存:{path}");
- }
- }
|