using System.Collections; using System.Collections.Generic; using UnityEngine; using System; namespace Ferdi{ public class Screenshoter : MonoBehaviour{ public static Screenshoter Instance; string Folder; string FilePath; [SerializeField] string FolderName = "Screenshots"; [SerializeField] string FileName = "Screenshot"; [SerializeField] [RangeAttribute(1, 12)] int Supersize = 1; [SerializeField] KeyCode Key = KeyCode.Space; void Start(){ if(Instance == null){ Instance = this; DontDestroyOnLoad(gameObject); }else{ Destroy(gameObject); } CreateFolder(); } void Update(){ if(Input.GetKeyDown(Key)){ TakeScreenshot(); } } void CreateFolder(){ string Folder = ""; switch(Application.platform){ case RuntimePlatform.OSXPlayer: case RuntimePlatform.OSXEditor: case RuntimePlatform.WindowsPlayer: case RuntimePlatform.WindowsEditor: Folder = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyPictures); break; case RuntimePlatform.Android: Folder = Application.persistentDataPath; System.IO.Directory.CreateDirectory("/storage/emulated/0/Pictures/"+FolderName); break; } Folder += "/"+FolderName; System.IO.Directory.CreateDirectory(Folder); FilePath = Folder; } public void OpenFolder(){ CreateFolder(); if(Application.platform == RuntimePlatform.OSXPlayer || Application.platform == RuntimePlatform.OSXEditor){ bool openInsidesOfFolder = true; string macPath = "\"" + FilePath + "\""; string arguments = (openInsidesOfFolder ? "" : "-R ") + macPath; System.Diagnostics.Process.Start("open", arguments); }else if(Application.platform == RuntimePlatform.WindowsPlayer || Application.platform == RuntimePlatform.WindowsEditor){ bool openInsidesOfFolder = true; string myWinPath = FilePath; string winPath = myWinPath.Replace("/", "\\"); System.Diagnostics.Process.Start("explorer.exe", (openInsidesOfFolder ? "/root," : "/select,") + winPath); } } public void TakeScreenshot(){ ScreenCapture.CaptureScreenshot(FilePath + "/" + FileName + "_"+DateTime.Now.ToString("yyyyMMdd-HHmmss") + ".png", Supersize); } void OnDrawGizmos(){ Gizmos.DrawIcon(transform.position, "Screenshoter", true); } } }