ScreenShotTester.cs 952 B

1234567891011121314151617181920212223242526272829
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. //游戏全屏截图-快捷截图
  6. public class ScreenShotTester : MonoBehaviour
  7. {
  8. private string saveDir;
  9. public static void Init(string saveDir) {
  10. if (!saveDir.EndsWith("\\")) throw new System.Exception("路径错误");
  11. if (FindObjectOfType<ScreenShotTester>()) return;
  12. var comp = new GameObject(typeof(ScreenShotTester).Name).AddComponent<ScreenShotTester>();
  13. comp.saveDir = saveDir;
  14. DontDestroyOnLoad(comp);
  15. }
  16. void Update() {
  17. #if UNITY_EDITOR
  18. if (Input.GetKeyDown(KeyCode.S)) {
  19. TimeSpan ts = DateTime.Now.ToUniversalTime() - new DateTime(1970, 1, 1);
  20. string fileName = ts.TotalMilliseconds + ".jpg";
  21. ScreenCapture.CaptureScreenshot(saveDir + fileName);
  22. Debug.LogWarning("截图成功-" + fileName);
  23. }
  24. #endif
  25. }
  26. }