Skip to content

Instantly share code, notes, and snippets.

@robertwahler
Created May 3, 2018 13:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robertwahler/eb8dd47693cc45fd86054194ba71cbcb to your computer and use it in GitHub Desktop.
Save robertwahler/eb8dd47693cc45fd86054194ba71cbcb to your computer and use it in GitHub Desktop.
Unity snippet for supersizing in-engine screenshots
// Take up to 10 screenshots per session, then start overwriting
private IEnumerator Capture(string path=null, string filename=null) {
Log.Debug(string.Format("ScreenCapture.Capture(path: {0}, filename: {1}) Settings.DataPath={0}", path, filename, Settings.DataPath));
screenShotCount += 1;
if (screenShotCount > 10) {
screenShotCount = 1;
}
if (filename == null) {
filename = string.Format("Screenshot{0}.png", screenShotCount.ToString());
}
if ((Application.platform != RuntimePlatform.IPhonePlayer) && (Application.platform != RuntimePlatform.Android)) {
// iOS and Android already include persistentDataPath in CaptureScreenshot
if (path == null) {
filename = System.IO.Path.Combine(Settings.DataPath, filename);
}
else {
filename = System.IO.Path.Combine(path, filename);
}
}
// @1x
Log.Debug(string.Format("ScreenCapture.Screenshot() @1x filename={0}", filename));
yield return new WaitForEndOfFrame();
int superSize = 0;
#if JAMMER_SCREENCAPTURE_SUPERSIZE_2X
superSize = 2;
#elif JAMMER_SCREENCAPTURE_SUPERSIZE_4X
superSize = 4;
#elif JAMMER_SCREENCAPTURE_SUPERSIZE_8X
superSize = 8;
#endif
//
// NOTE: May need to disable anti-aliasing in quality settings if you get a black screen
//
Application.CaptureScreenshot(filename, superSize: superSize);
Events.Raise(new PlaySFXCommandEvent() { Handled=false, SFX=SFX.Click });
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment