Last active
November 9, 2022 10:16
-
-
Save rodrigod89/9cc0172bddca43ad741752d97d789e19 to your computer and use it in GitHub Desktop.
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 UnityEditor; | |
using UnityEngine; | |
/// <summary> | |
/// Made by Rodrigo Diaz | |
/// http://www.rodrigos.work | |
/// This code is licensed under MIT license | |
/// | |
/// Make sure to add this class under a folder named "Editor" in the Unity Project | |
/// | |
/// Instructions: Either go to Edit/Screencapture or press alt-c to take the screenshot. | |
/// It only works if you have the Game window open in the editor. | |
/// | |
/// </summary> | |
public class ScreenshotHelper | |
{ | |
private static string path; | |
[MenuItem("Edit/Screencapture &c")] | |
public static void Screencapture() | |
{ | |
if (Camera.main) { | |
if (string.IsNullOrEmpty(path)) { | |
path = EditorUtility.SaveFilePanel("Save png", path, "screenshot.png", "png"); | |
} | |
if (path.Length != 0) { | |
ScreenCapture.CaptureScreenshot(path); | |
} | |
} else { | |
EditorUtility.DisplayDialog("No Camera in the scene", "Camera not found in the scene, please add one", "OK"); | |
} | |
} | |
[MenuItem("Edit/Screencapture save as ^&c")] | |
public static void ScreenShotSaveAs() | |
{ | |
path = null; | |
Screencapture(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment