Last active
January 24, 2018 13:00
-
-
Save Arakade/cc6bf21abf38b943e5f81fa404e2d1db to your computer and use it in GitHub Desktop.
Utility to capture screenshots at crazily large sizes required by printers for floor standing banners, etc prior to 2017.03.0p1
This file contains 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 System; | |
using UnityEngine; | |
namespace UGS { | |
/// <summary> | |
/// See <seealso cref="http://docs.unity3d.com/ScriptReference/Application.CaptureScreenshot.html"/>. | |
/// N.b. docs now say "Removed in version 2017.3.0p1" | |
/// Now API call includes super-size facility https://docs.unity3d.com/ScriptReference/ScreenCapture.CaptureScreenshot.html | |
/// </summary> | |
public class ScreenCaptureUtil : MonoBehaviour { | |
#region Resize | |
[Header("Resize")] | |
[Tooltip("What key activates resizes the window.")] | |
[SerializeField] | |
private KeyCode resizeKey = KeyCode.F10; | |
[SerializeField] | |
private int desiredOutputWidth = 9520, desiredOutputHeight = 23693; | |
[SerializeField] | |
private KeyCode showSizeToggleKey = KeyCode.F7; | |
private bool showSize = false; | |
#endregion Resize | |
#region Screenshot | |
[Header("Screenshot")] | |
[Tooltip("What key activates screenshot taking.")] | |
[SerializeField] | |
private KeyCode takePicKey = KeyCode.F9; | |
[Tooltip("Where to save.")] | |
[SerializeField] | |
private string filename = "SnwScf-screenshot.png"; | |
[Tooltip("What ration to scale-up to")] | |
[SerializeField] | |
private int superSize = 8; | |
[SerializeField] | |
private string filenamePatternForAutomated = "SnwScf-{0}.png"; | |
private int automatedScreenCapNum; | |
#endregion Screenshot | |
public void OnGUI() { | |
if (!showSize) | |
return; | |
var sizeMsg = string.Format("Size : {0} x {1}", Screen.width, Screen.height); | |
GUI.Label(new Rect(0, 0, 100, 100), sizeMsg); | |
} | |
public void Update() { | |
if (Input.GetKeyDown(takePicKey)) { | |
capture(filename); | |
return; | |
} | |
if (Input.GetKeyDown(resizeKey)) { | |
resizeWindow(); | |
return; | |
} | |
if (Input.GetKeyDown(showSizeToggleKey)) { | |
showSize = !showSize; | |
return; | |
} | |
} | |
private void capture(string file) { | |
Application.CaptureScreenshot(file, superSize); | |
} | |
private void resizeWindow() { | |
int windowWidth = Mathf.CeilToInt(desiredOutputWidth / (float)superSize); | |
int windowHeight = Mathf.CeilToInt(desiredOutputHeight / (float)superSize); | |
LogR.log(LogR.Level.ALL, "{0} resizing to {1} x {2} (for a x{3} capture to {4} x {5})", | |
this, windowWidth, windowHeight, superSize, desiredOutputWidth, desiredOutputHeight); | |
Screen.SetResolution(windowWidth, windowHeight, false); | |
} | |
internal void captureAnotherScreen() { | |
var filename = string.Format(filenamePatternForAutomated, automatedScreenCapNum++); | |
capture(filename); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment