| 1234567891011121314151617181920212223242526272829303132 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- //游戏全屏截图-快捷截图
- public class ScreenShotTester : MonoBehaviour
- {
- private string saveDir;
- public static void Init(string saveDir = "C:\\Users\\JC\\Desktop\\弓箭截图\\")
- {
- if (!saveDir.EndsWith("\\")) throw new System.Exception("路径错误");
- if (FindObjectOfType<ScreenShotTester>()) return;
- var comp = new GameObject(typeof(ScreenShotTester).Name).AddComponent<ScreenShotTester>();
- comp.saveDir = saveDir;
- DontDestroyOnLoad(comp);
- }
- void Update()
- {
- #if UNITY_EDITOR
- if (Input.GetKeyDown(KeyCode.S))
- {
- TimeSpan ts = DateTime.Now.ToUniversalTime() - new DateTime(1970, 1, 1);
- string fileName = ts.TotalMilliseconds + ".jpg";
- ScreenCapture.CaptureScreenshot(saveDir + fileName);
- Debug.LogWarning("截图成功-" + fileName);
- }
- #endif
- }
- }
|