Created
January 30, 2016 15:26
-
-
Save miguelSantirso/ca7dd6fe2bc97cc6470c to your computer and use it in GitHub Desktop.
Unity: Press 'K' to take screenshots
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class EasyScreenshot : MonoBehaviour | |
{ | |
#region inspector properties | |
[SerializeField] | |
private int superSize = 1; | |
[SerializeField] | |
private string directory = "screenshots"; | |
[SerializeField] | |
private string label = "default"; | |
#endregion | |
public static string ScreenShotName(string directory, string tag) | |
{ | |
var timestamp = System.DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss"); | |
var relativePath = string.Format("{0}/{1}_{2}.png", directory, tag, timestamp); | |
var projectPath = System.IO.Path.GetDirectoryName(Application.dataPath); | |
return System.IO.Path.Combine(projectPath, relativePath); | |
} | |
void LateUpdate() | |
{ | |
if (Input.GetKeyDown("k")) | |
{ | |
var path = ScreenShotName(directory, label); | |
Debug.LogFormat("Capturing screenshot at: {0}", path); | |
Application.CaptureScreenshot(path, superSize); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment