/// <summary> /// Lets the screenshot utility persist through scenes. /// </summary> private void Awake() { if (ScreenShotUtility != null) { // this gameobject must already have been setup in a previous scene, so just destroy this game object Destroy(gameObject); } else { // this is the first time we are setting up the screenshot utility // setup reference to ScreenshotUtility class ScreenShotUtility = GetComponent <ScreenshotUtility>(); // keep this gameobject around as new scenes load DontDestroyOnLoad(gameObject); // get image count from player prefs for indexing of filename _mImageCount = PlayerPrefs.GetInt(ImageCntKey); } // if there is not a "Screenshots" directory in the Project folder, create one if (!Directory.Exists("Screenshots")) { Directory.CreateDirectory("Screenshots"); } }
/// <summary> /// This sets up the screenshot utility and allows it to persist through scenes. /// </summary> void Awake() { if (screenShotUtility != null) { // this gameobject must already have been setup in a previous scene, so just destroy this game object Destroy(this.gameObject); } else if (runOnlyInEditor && !Application.isEditor) { // chose not to work if this is running outside the editor so destroy it Destroy(this.gameObject); } else { // this is the first time we are setting up the screenshot utility // setup reference to ScreenshotUtility class screenShotUtility = this.GetComponent <ScreenshotUtility>(); // keep this gameobject around as new scenes load DontDestroyOnLoad(gameObject); // get image count from player prefs for indexing of filename m_ImageCount = PlayerPrefs.GetInt(ImageCntKey); // if there is not a "Screenshots" directory in the Project folder, create one if (!Directory.Exists("Screenshots")) { Directory.CreateDirectory("Screenshots"); } } }
public void QuitDriver() { if (ScenarioContext.TestError != null) { ScreenshotUtility.TakeScreehShot(_webDriver); } _webDriver.Quit(); }
public static SettingsProvider ScreenshotSettings() { var provider = new SettingsProvider("Preferences/Screenshot", SettingsScope.User) { label = "Screenshot", guiHandler = (searchContent) => { FileNameFormat = EditorGUILayout.TextField("File name format", FileNameFormat); EditorGUILayout.HelpBox("{P} = Project name\n{S} = Scene name\n{R} = Resolution\n{D} = Date\n{T} = Time\n{U} = Unique number", MessageType.None); EditorGUILayout.LabelField("Example: " + ScreenshotUtility.FormatFileName(1, DateFormats[DateFormat])); ScreenshotUtility.DateFormat = EditorGUILayout.Popup("Date format", DateFormat, DateFormats); }, keywords = new HashSet <string>(new[] { "Screenshot" }) }; return(provider); }
/// <summary> /// Lets the screenshot utility persist through scenes. /// </summary> void Awake () { if (screenShotUtility!=null) { // this gameobject must already have been setup in a previous scene, so just destroy this game object Destroy(this.gameObject); } else { // this is the first time we are setting up the screenshot utility // setup reference to ScreenshotUtility class screenShotUtility = this.GetComponent<ScreenshotUtility>(); // keep this gameobject around as new scenes load DontDestroyOnLoad(gameObject); // get image count from player prefs for indexing of filename m_ImageCount = PlayerPrefs.GetInt(ImageCntKey); } // if there is not a "Screenshots" directory in the Project folder, create one if (!Directory.Exists("Screenshots")) { Directory.CreateDirectory("Screenshots"); } }
public static SettingsProvider ScreenshotSettings() { var provider = new SettingsProvider("Preferences/Screenshot", SettingsScope.User) { label = "Screenshot", guiHandler = (searchContent) => { FileNameFormat = EditorGUILayout.TextField("File name format", FileNameFormat); EditorGUILayout.HelpBox("{P} = Project name\n{S} = Scene name\n{R} = Resolution\n{D} = Date\n{T} = Time\n{U} = Unique number", MessageType.None); ScreenshotUtility.DateFormat = EditorGUILayout.Popup("Date format", DateFormat, DateFormats, GUILayout.MaxWidth(250f)); ScreenshotUtility.TimeFormat = EditorGUILayout.Popup("Time format", TimeFormat, TimeFormats, GUILayout.MaxWidth(250f)); EditorGUILayout.LabelField("Example: " + ScreenshotUtility.FormatFileName(1, DateFormats[DateFormat]), EditorStyles.miniLabel); EditorGUILayout.Space(); ListenToPrintButton = EditorGUILayout.Toggle(new GUIContent("Print-screen button", "If the window is open, capture a screenshot whenever the print-screen keyboard button is pressed"), ListenToPrintButton); }, keywords = new HashSet <string>(new[] { "Screenshot" }) }; return(provider); }
public IEnumerator TestScreenshotCapture() { var path = ScreenshotUtility.GetScreenshotPath(); try { Assert.False(string.IsNullOrEmpty(path), "GetScreenshotFileName returned a null or empty string."); // Tests which require a valid device context (such as taking screenshots) cannot be run in batch mode. if (!Application.isBatchMode) { Assert.True(ScreenshotUtility.CaptureScreenshot(path, 1), "Failed to capture a 1x resolution screenshot."); // Edit mode tests can only "yield return null" so we must roll our own "WaitForSeconds" implementation. var waitRoutine = WaitForSeconds(1); while (waitRoutine.MoveNext()) { yield return(null); } FileAssert.Exists(path, "A file was not written to disk during 1x resolution screenshot capture."); Assert.True(ScreenshotUtility.CaptureScreenshot(path, 4), "Failed to capture a 4x resolution screenshot."); waitRoutine = WaitForSeconds(4); while (waitRoutine.MoveNext()) { yield return(null); } FileAssert.Exists(path, "A file was not written to disk during 4x resolution screenshot capture."); Assert.True(ScreenshotUtility.CaptureScreenshot(path, 1, true), "Failed to capture a 1x resolution screenshot with a transparent clear color."); waitRoutine = WaitForSeconds(1); while (waitRoutine.MoveNext()) { yield return(null); } FileAssert.Exists(path, "A file was not written to disk during 1x resolution screenshot capture with a transparent clear color."); Assert.True(ScreenshotUtility.CaptureScreenshot(path, 4, true), "Failed to capture a 4x resolution screenshot with a transparent clear color."); waitRoutine = WaitForSeconds(4); while (waitRoutine.MoveNext()) { yield return(null); } FileAssert.Exists(path, "A file was not written to disk during 4x resolution screenshot capture with a transparent clear color."); } Assert.False(ScreenshotUtility.CaptureScreenshot(null, 1), "A screenshot was captured with an invalid path."); Assert.False(ScreenshotUtility.CaptureScreenshot(ScreenshotUtility.GetScreenshotPath(), -1), "A screenshot was captured with an invalid super size."); } finally { // Clean up any screenshots created. if (File.Exists(path)) { File.Delete(path); } } }