From a9e8d0f5bef9058c8543079d489bd1b7555bd45b Mon Sep 17 00:00:00 2001 From: Adam Courtney <32782486+TheFunnyBrain@users.noreply.github.com> Date: Thu, 27 May 2021 11:09:13 +0100 Subject: [PATCH] First commit! Can store screenshots to a custom path in streamingassets or your persistant data path. :) Next will be the plan to add any path, resolution and transparency settings I can. --- Screenshotter.cs | 66 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 Screenshotter.cs diff --git a/Screenshotter.cs b/Screenshotter.cs new file mode 100644 index 0000000..c5b8f07 --- /dev/null +++ b/Screenshotter.cs @@ -0,0 +1,66 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using System.IO; + + +public enum DesiredSaveLocation +{ + Persistent, StreamingAssets +} + +public class Screenshotter : MonoBehaviour +{ + int ID; + + string fullPath; + + public string ImagePrefix = "Image "; + + public string folder = "Screenshotter"; + + public int screenshotScale = 1; + + public DesiredSaveLocation imageSaveLocation; + + // Start is called before the first frame update + void Start() + { + + } + + private void Update() + { + if (Input.GetKeyDown(KeyCode.Period)) + { + + + switch (imageSaveLocation) + { + case DesiredSaveLocation.Persistent: + fullPath = Path.Combine(Application.persistentDataPath, folder); + CheckThenCreateDir(fullPath); + break; + case DesiredSaveLocation.StreamingAssets: + CheckThenCreateDir(fullPath); + fullPath = Path.Combine(Application.streamingAssetsPath, folder); + break; + } + + ID++; + string imageName = ImagePrefix + ID + ".png"; + + ScreenCapture.CaptureScreenshot(Path.Combine(fullPath, imageName), screenshotScale); + Debug.LogFormat("Screenshot {0} saved to {1}", imageName, fullPath); + } + } + + private void CheckThenCreateDir(string path) + { + if (!Directory.Exists(path)) + { + Directory.CreateDirectory(path); + } + } + +}