|
|
@@ -0,0 +1,29 @@
|
|
|
+using System;
|
|
|
+using System.Collections;
|
|
|
+using System.Collections.Generic;
|
|
|
+using UnityEngine;
|
|
|
+
|
|
|
+//游戏全屏截图-快捷截图
|
|
|
+public class ScreenShotTester : MonoBehaviour
|
|
|
+{
|
|
|
+ private string saveDir;
|
|
|
+
|
|
|
+ public static void Init(string saveDir) {
|
|
|
+ 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
|
|
|
+ }
|
|
|
+}
|