Skip to content

Instantly share code, notes, and snippets.

@bugshake
Created February 21, 2018 15:55
Show Gist options
  • Save bugshake/8bfb9af7edd4e595c8aa7326f7f7737b to your computer and use it in GitHub Desktop.
Save bugshake/8bfb9af7edd4e595c8aa7326f7f7737b to your computer and use it in GitHub Desktop.
Save a screenshot in any resolution from the Unity Editor. Useful for making screenshots higher than your monitor's resolution.
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using UnityEditor;
/*
AUTHOR: Stijn Raaijmakers @bugshake
Custom editor window which will save a screenshot in the play windows resolution.
For example if you have a 1080p screen, but want a 4k screenshot, just set that resolution in the Game window
and the file will be a full 3840x2160 pixels
*/
public class Screenshotter : EditorWindow
{
List<string> fileHistory = new List<string>();
Vector2 scrollPos = Vector2.zero;
[MenuItem("Tools/Screenshotter...")]
public static void ShowWindow()
{
var win = EditorWindow.GetWindow<Screenshotter>(false, "Screenshotter");
}
void OnGUI()
{
string screenshotPath = string.Format("{0}/Screenshots", Application.persistentDataPath);
if (GUILayout.Button("Capture"))
{
Directory.CreateDirectory(screenshotPath);
string path = string.Format("{0}/s_{1:yyyy_MM_dd hh_mm_ss}.png", screenshotPath, DateTime.Now);
Application.CaptureScreenshot(path);
fileHistory.Add(path);
}
if (GUILayout.Button("SCREENSHOTS:"))
{
Directory.CreateDirectory(screenshotPath);
EditorUtility.RevealInFinder(screenshotPath + "/");
}
scrollPos = GUILayout.BeginScrollView(scrollPos, GUILayout.Height(100f));
for( int i = fileHistory.Count; i-- > 0;)
{
GUILayout.Label(fileHistory[i]);
}
GUILayout.EndScrollView();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment