Created
November 3, 2015 21:01
-
-
Save dilmerv/462be10b5a21c8a6edd5 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 UnityEngine; | |
using System.Collections; | |
using UnityEditor; | |
using System.IO; | |
using System; | |
public class LevelScreenshot: EditorWindow { | |
// Quality Settings | |
enum Quality { | |
high = 4, Medium = 3, Normal = 2, Low = 1 | |
} | |
// Default Quality Option | |
// This field is serializable to enable changes during runtime | |
[SerializeField] | |
Quality option = Quality.Normal; | |
// This field is serializable to enable changes during runtime | |
[SerializeField] | |
string savePath = "./Screenshots/Screenshot"; | |
// Menu Option Location and Name | |
[MenuItem("Window/SuperStick/LevelScreenshot")] | |
public static void ShowWindow() { | |
EditorWindow.GetWindow(typeof(LevelScreenshot)); | |
} | |
// Utility function to create screenshots directory | |
static void CreateDir() { | |
if (!Directory.Exists("Screenshots")) { | |
Directory.CreateDirectory("Screenshots"); | |
} | |
} | |
// Draws each GUI element onto the editor window | |
void OnGUI() { | |
// Draw Label | |
GUILayout.Label("Options: ", EditorStyles.boldLabel); | |
// Draw Popup (Dropdown) for Quality Options | |
option = (Quality) EditorGUILayout.EnumPopup("Quality", option); | |
Rect r = EditorGUILayout.BeginHorizontal("Button"); | |
// Call Create Directory | |
CreateDir(); // Set Button Color | |
GUI.backgroundColor = Color.yellow; | |
// Draw Button and placement | |
if (GUI.Button(r, GUIContent.none)) { | |
// Button Trigger Event | |
Application.CaptureScreenshot(string.Format(savePath + "-{0:yyyy-MM-dd_hh-mm-ss-tt}.png", DateTime.Now), (int) option); | |
} | |
GUI.backgroundColor = Color.clear; | |
// Button Label | |
GUILayout.Label("Take Screenshot"); | |
EditorGUILayout.EndHorizontal(); | |
// Output Location | |
GUILayout.Label("Screenshot Path: "); | |
EditorGUILayout.LabelField(savePath); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment