From d1307c571544c24981eb43e6c432a5e8ca74143d Mon Sep 17 00:00:00 2001 From: Koji Hasegawa Date: Wed, 1 Nov 2023 02:07:36 +0900 Subject: [PATCH 1/2] Fix can specify directory on player --- Runtime/Attributes/TakeScreenshotAttribute.cs | 2 +- Runtime/Utils/ScreenshotHelper.cs | 2 +- RuntimeInternals/ScreenshotHelper.cs | 4 ++-- Tests/Runtime/Utils/ScreenshotHelperTest.cs | 20 ------------------- 4 files changed, 4 insertions(+), 24 deletions(-) diff --git a/Runtime/Attributes/TakeScreenshotAttribute.cs b/Runtime/Attributes/TakeScreenshotAttribute.cs index 3e036ca..03e5e5e 100644 --- a/Runtime/Attributes/TakeScreenshotAttribute.cs +++ b/Runtime/Attributes/TakeScreenshotAttribute.cs @@ -36,7 +36,7 @@ public class TakeScreenshotAttribute : NUnitAttribute, IOuterUnityTestAction ///
/// Using ScreenCapture.CaptureScreenshotAsTexture internally. /// - /// Directory to save screenshots relative to project path. Only effective in Editor. + /// Directory to save screenshots. /// Filename to store screenshot. /// The factor to increase resolution with. /// The eye texture to capture when stereo rendering is enabled. diff --git a/Runtime/Utils/ScreenshotHelper.cs b/Runtime/Utils/ScreenshotHelper.cs index af80b63..8141c5f 100644 --- a/Runtime/Utils/ScreenshotHelper.cs +++ b/Runtime/Utils/ScreenshotHelper.cs @@ -34,7 +34,7 @@ private static string DefaultFilename() ///
/// Using ScreenCapture.CaptureScreenshotAsTexture internally. /// - /// Directory to save screenshots relative to project path. Only effective in Editor. + /// Directory to save screenshots. /// Filename to store screenshot. /// The factor to increase resolution with. /// The eye texture to capture when stereo rendering is enabled. diff --git a/RuntimeInternals/ScreenshotHelper.cs b/RuntimeInternals/ScreenshotHelper.cs index abff0db..32eda27 100644 --- a/RuntimeInternals/ScreenshotHelper.cs +++ b/RuntimeInternals/ScreenshotHelper.cs @@ -33,7 +33,7 @@ private static string DefaultDirectoryPath() ///
/// Using ScreenCapture.CaptureScreenshotAsTexture internally. /// - /// Directory to save screenshots relative to project path. Only effective in Editor. + /// Directory to save screenshots. /// Filename to store screenshot. /// The factor to increase resolution with. /// The eye texture to capture when stereo rendering is enabled. @@ -63,7 +63,7 @@ public static IEnumerator TakeScreenshot( // Note: This is not the case since it is a coroutine. } - if (Application.isEditor && directory != null) + if (directory != null) { directory = Path.GetFullPath(directory); } diff --git a/Tests/Runtime/Utils/ScreenshotHelperTest.cs b/Tests/Runtime/Utils/ScreenshotHelperTest.cs index ce4de37..5d8bcd1 100644 --- a/Tests/Runtime/Utils/ScreenshotHelperTest.cs +++ b/Tests/Runtime/Utils/ScreenshotHelperTest.cs @@ -69,26 +69,6 @@ public IEnumerator TakeScreenshot_SpecifyDirectoryInEditor_SaveToSpecifyPath() Assert.That(path, Does.Exist); } - [UnityTest] - [UnityPlatform(exclude = - new[] { RuntimePlatform.OSXEditor, RuntimePlatform.WindowsEditor, RuntimePlatform.LinuxEditor })] - [LoadScene(TestScene)] - public IEnumerator TakeScreenshot_SpecifyDirectoryOnPlayer_SaveToDefaultPath() - { - const string RelativePath = "Logs/Screenshots"; - var path = Path.Combine(_defaultOutputDirectory, - $"{nameof(TakeScreenshot_SpecifyDirectoryOnPlayer_SaveToDefaultPath)}.png"); - if (File.Exists(path)) - { - File.Delete(path); - } - - Assume.That(path, Does.Not.Exist); - - yield return ScreenshotHelper.TakeScreenshot(directory: RelativePath); - Assert.That(path, Does.Exist); - } - [UnityTest] [LoadScene(TestScene)] public IEnumerator TakeScreenshot_SpecifyFilename_SaveToSpecifyPath() From 77da00da3d3c9d106a4987074f35369b1718d73e Mon Sep 17 00:00:00 2001 From: Koji Hasegawa Date: Wed, 1 Nov 2023 02:17:47 +0900 Subject: [PATCH 2/2] Fix test run on player --- RuntimeInternals/GameViewControlHelper.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/RuntimeInternals/GameViewControlHelper.cs b/RuntimeInternals/GameViewControlHelper.cs index 72411cd..859183f 100644 --- a/RuntimeInternals/GameViewControlHelper.cs +++ b/RuntimeInternals/GameViewControlHelper.cs @@ -1,9 +1,11 @@ // Copyright (c) 2023 Koji Hasegawa. // This software is released under the MIT License. +using UnityEngine; +#if UNITY_EDITOR using TestHelper.RuntimeInternals.Wrappers.UnityEditor; using UnityEditor; -using UnityEngine; +#endif namespace TestHelper.RuntimeInternals {