diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index 1f8894e..803bbca 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -41,7 +41,7 @@ jobs:
- 2022.3.17f1
- 2023.2.5f1
include:
- - unityVersion: 2019.4.40f1
+ - unityVersion: 2022.3.17f1
octocov: true
steps:
diff --git a/Runtime/Attributes/SimulatorViewAttribute.cs b/Runtime/Attributes/SimulatorViewAttribute.cs
new file mode 100644
index 0000000..479ab9d
--- /dev/null
+++ b/Runtime/Attributes/SimulatorViewAttribute.cs
@@ -0,0 +1,37 @@
+// Copyright (c) 2023-2024 Koji Hasegawa.
+// This software is released under the MIT License.
+
+using System;
+using NUnit.Framework;
+using NUnit.Framework.Interfaces;
+using NUnit.Framework.Internal;
+using TestHelper.RuntimeInternals;
+using UnityEngine;
+
+namespace TestHelper.Attributes
+{
+ ///
+ /// Set SimulatorView orientation before SetUp test.
+ /// This attribute works only with Unity 2022.2 or newer. (not support device simulator package)
+ ///
+ [AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class | AttributeTargets.Method)]
+ public class SimulatorViewAttribute : NUnitAttribute, IApplyToContext
+ {
+ private readonly ScreenOrientation _orientation;
+
+ ///
+ /// Set SimulatorView orientation before SetUp test.
+ /// This attribute works only with Unity 2022.2 or newer. (not support device simulator package)
+ ///
+ /// Set screen orientation
+ public SimulatorViewAttribute(ScreenOrientation orientation = ScreenOrientation.Portrait)
+ {
+ _orientation = orientation;
+ }
+
+ public void ApplyToContext(ITestExecutionContext context)
+ {
+ SimulatorViewControlHelper.SetScreenOrientation(_orientation);
+ }
+ }
+}
diff --git a/Runtime/Attributes/SimulatorViewAttribute.cs.meta b/Runtime/Attributes/SimulatorViewAttribute.cs.meta
new file mode 100644
index 0000000..f0705a6
--- /dev/null
+++ b/Runtime/Attributes/SimulatorViewAttribute.cs.meta
@@ -0,0 +1,2 @@
+fileFormatVersion: 2
+guid: b03db1ab479ec4082aa9a1a5399a2383
\ No newline at end of file
diff --git a/RuntimeInternals/GameViewControlHelper.cs b/RuntimeInternals/GameViewControlHelper.cs
index ed5d44b..891cda3 100644
--- a/RuntimeInternals/GameViewControlHelper.cs
+++ b/RuntimeInternals/GameViewControlHelper.cs
@@ -16,7 +16,7 @@ namespace TestHelper.RuntimeInternals
public static class GameViewControlHelper
{
///
- /// Focus GameView or SimulatorWindow.
+ /// Focus GameView.
///
public static void Focus()
{
diff --git a/RuntimeInternals/SimulatorViewControlHelper.cs b/RuntimeInternals/SimulatorViewControlHelper.cs
new file mode 100644
index 0000000..b23b8db
--- /dev/null
+++ b/RuntimeInternals/SimulatorViewControlHelper.cs
@@ -0,0 +1,45 @@
+// Copyright (c) 2023-2024 Koji Hasegawa.
+// This software is released under the MIT License.
+
+using UnityEngine;
+#if UNITY_EDITOR && UNITY_2022_2_OR_NEWER
+using UnityEditor;
+using Screen = UnityEngine.Device.Screen; // defined in UnityEditor.DeviceSimulatorModule module
+#endif
+
+namespace TestHelper.RuntimeInternals
+{
+ ///
+ /// SimulatorView control helper.
+ /// This class can be used from the runtime code because it does not depend on test-framework.
+ /// This class works only with Unity 2022.2 or newer. (not support device simulator package)
+ ///
+ public static class SimulatorViewControlHelper
+ {
+ ///
+ /// Focus SimulatorView.
+ ///
+ public static void Focus()
+ {
+#if UNITY_EDITOR && UNITY_2022_2_OR_NEWER
+ PlayModeWindow.SetViewType(PlayModeWindow.PlayModeViewTypes.SimulatorView);
+#else
+ Debug.LogError("SimulatorView is not supported.");
+#endif
+ }
+
+ ///
+ /// Set ScreenOrientation on SimulatorView.
+ ///
+ /// Screen orientation. However, AutoRotation is ignored
+ public static void SetScreenOrientation(ScreenOrientation orientation)
+ {
+#if UNITY_EDITOR && UNITY_2022_2_OR_NEWER
+ PlayModeWindow.SetViewType(PlayModeWindow.PlayModeViewTypes.SimulatorView);
+ Screen.orientation = orientation; // UnityEngine.Device.Screen
+#else
+ Debug.LogError("SimulatorView is not supported.");
+#endif
+ }
+ }
+}
diff --git a/RuntimeInternals/SimulatorViewControlHelper.cs.meta b/RuntimeInternals/SimulatorViewControlHelper.cs.meta
new file mode 100644
index 0000000..a9e4b85
--- /dev/null
+++ b/RuntimeInternals/SimulatorViewControlHelper.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: 3566c79b2819f40a1981063caa66a263
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Tests/Runtime/Attributes/SimulatorViewAttributeTest.cs b/Tests/Runtime/Attributes/SimulatorViewAttributeTest.cs
new file mode 100644
index 0000000..17d5340
--- /dev/null
+++ b/Tests/Runtime/Attributes/SimulatorViewAttributeTest.cs
@@ -0,0 +1,42 @@
+// Copyright (c) 2023-2024 Koji Hasegawa.
+// This software is released under the MIT License.
+
+using System.Threading.Tasks;
+using Cysharp.Threading.Tasks;
+using NUnit.Framework;
+using TestHelper.RuntimeInternals;
+using UnityEngine;
+using UnityEngine.TestTools;
+
+namespace TestHelper.Attributes
+{
+ [TestFixture]
+ [UnityPlatform(RuntimePlatform.OSXEditor, RuntimePlatform.WindowsEditor, RuntimePlatform.LinuxEditor)]
+ [UnityVersion("2022.2")]
+ public class SimulatorViewAttributeTest
+ {
+ [OneTimeTearDown]
+ public void OneTimeTearDown()
+ {
+ SimulatorViewControlHelper.SetScreenOrientation(ScreenOrientation.Portrait);
+ }
+
+ [Test]
+ [SimulatorView(ScreenOrientation.PortraitUpsideDown)]
+ public async Task Attach_ScreenOrientation_PortraitUpsideDown()
+ {
+ await UniTask.NextFrame(); // Wait to apply change SimulatorView
+
+ Assert.That(Screen.orientation, Is.EqualTo(ScreenOrientation.PortraitUpsideDown));
+ }
+
+ [Test]
+ [SimulatorView(ScreenOrientation.LandscapeLeft)]
+ public async Task Attach_ScreenOrientation_LandscapeLeft()
+ {
+ await UniTask.NextFrame(); // Wait to apply change SimulatorView
+
+ Assert.That(Screen.orientation, Is.EqualTo(ScreenOrientation.LandscapeLeft));
+ }
+ }
+}
diff --git a/Tests/Runtime/Attributes/SimulatorViewAttributeTest.cs.meta b/Tests/Runtime/Attributes/SimulatorViewAttributeTest.cs.meta
new file mode 100644
index 0000000..2a82dff
--- /dev/null
+++ b/Tests/Runtime/Attributes/SimulatorViewAttributeTest.cs.meta
@@ -0,0 +1,2 @@
+fileFormatVersion: 2
+guid: 76dda6dad8f774ff28128e74f98c79a9
\ No newline at end of file
diff --git a/Tests/RuntimeInternals/SimulatorViewControlHelperTest.cs b/Tests/RuntimeInternals/SimulatorViewControlHelperTest.cs
new file mode 100644
index 0000000..14ed426
--- /dev/null
+++ b/Tests/RuntimeInternals/SimulatorViewControlHelperTest.cs
@@ -0,0 +1,30 @@
+// Copyright (c) 2023-2024 Koji Hasegawa.
+// This software is released under the MIT License.
+
+using System.Threading.Tasks;
+using Cysharp.Threading.Tasks;
+using NUnit.Framework;
+using TestHelper.Attributes;
+using UnityEngine;
+using UnityEngine.TestTools;
+
+namespace TestHelper.RuntimeInternals
+{
+ [TestFixture]
+ [UnityPlatform(RuntimePlatform.OSXEditor, RuntimePlatform.WindowsEditor, RuntimePlatform.LinuxEditor)]
+ [UnityVersion("2022.2")]
+ public class SimulatorViewControlHelperTest
+ {
+ [TestCase(ScreenOrientation.Portrait)]
+ [TestCase(ScreenOrientation.PortraitUpsideDown)]
+ [TestCase(ScreenOrientation.LandscapeLeft)]
+ [TestCase(ScreenOrientation.LandscapeRight)]
+ public async Task SetScreenOrientation_RotateScreen(ScreenOrientation orientation)
+ {
+ SimulatorViewControlHelper.SetScreenOrientation(orientation);
+ await UniTask.NextFrame();
+
+ Assert.That(Screen.orientation, Is.EqualTo(orientation));
+ }
+ }
+}
diff --git a/Tests/RuntimeInternals/SimulatorViewControlHelperTest.cs.meta b/Tests/RuntimeInternals/SimulatorViewControlHelperTest.cs.meta
new file mode 100644
index 0000000..fad8002
--- /dev/null
+++ b/Tests/RuntimeInternals/SimulatorViewControlHelperTest.cs.meta
@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: ec16ac3a4551242ffb23cea2374bfe53
+MonoImporter:
+ externalObjects: {}
+ serializedVersion: 2
+ defaultReferences: []
+ executionOrder: 0
+ icon: {instanceID: 0}
+ userData:
+ assetBundleName:
+ assetBundleVariant:
diff --git a/Tests/RuntimeInternals/TestHelper.RuntimeInternals.Tests.asmdef b/Tests/RuntimeInternals/TestHelper.RuntimeInternals.Tests.asmdef
index c095b95..b5c6fda 100644
--- a/Tests/RuntimeInternals/TestHelper.RuntimeInternals.Tests.asmdef
+++ b/Tests/RuntimeInternals/TestHelper.RuntimeInternals.Tests.asmdef
@@ -5,6 +5,7 @@
"UnityEngine.TestRunner",
"UnityEditor.TestRunner",
"TestHelper.RuntimeInternals",
+ "TestHelper",
"UniTask"
],
"includePlatforms": [],