Beispiel #1
0
 public void SetOrientationExplicitly(ScreenOrientation orientation)
 {
     m_InputTest.Rotation = ScreenTestUtilities.OrientationRotation[ScreenOrientation.PortraitUpsideDown];
     m_Simulation         = new ScreenSimulation(m_TestDevice, m_InputTest, SimulatorPlayerSettingsUI.InitDefaultPlayerSettings(), m_Window);
     Screen.orientation   = orientation;
     Assert.AreEqual(orientation, Screen.orientation);
 }
Beispiel #2
0
        public void ResolutionScalingInitializedCorrectly(UIOrientation orientation, int screenWidth, int screenHeight, float screenDpi, int scaledDpi)
        {
            PlayerSettings.defaultInterfaceOrientation = orientation;
            var serializedSettings = PlayerSettings.GetSerializedObject();

            serializedSettings.Update();
            serializedSettings.FindProperty("resolutionScalingMode").intValue = 1;
            serializedSettings.FindProperty("targetPixelDensity").intValue    = scaledDpi;
            serializedSettings.ApplyModifiedPropertiesWithoutUndo();

            var testDevice = DeviceInfoLibrary.GetDeviceWithSupportedOrientations(ScreenTestUtilities.ExplicitOrientations, screenWidth, screenHeight, screenDpi);
            var testWindow = new TestWindow();

            m_Simulation = new ScreenSimulation(testDevice, m_InputTest, SimulatorPlayerSettingsUI.InitDefaultPlayerSettings(), testWindow);

            if (screenDpi >= scaledDpi)
            {
                var scale = scaledDpi / screenDpi;
                var expectedResolution = orientation.IsLandscape()
                    ? new Vector2((int)(screenHeight * scale), (int)(screenWidth * scale))
                    : new Vector2((int)(screenWidth * scale), (int)(screenHeight * scale));

                Assert.AreEqual(expectedResolution, testWindow.TargetSize);
            }
            else
            {
                var expectedResolution = orientation.IsLandscape()
                    ? new Vector2(screenHeight, screenWidth)
                    : new Vector2(screenWidth, screenHeight);

                Assert.AreEqual(expectedResolution, testWindow.TargetSize);
            }
        }
Beispiel #3
0
        public void ExplicitOrientationInitializedFromPlayerSettings(ScreenOrientation orientation)
        {
            m_InputTest.Rotation = ScreenTestUtilities.OrientationRotation[orientation];

            PlayerSettings.defaultInterfaceOrientation = ScreenTestUtilities.ScreenOrientationToUI[orientation];
            m_Simulation = new ScreenSimulation(m_TestDevice, m_InputTest, SimulatorPlayerSettingsUI.InitDefaultPlayerSettings(), m_TestWindow);

            Assert.AreEqual(orientation, Screen.orientation);
        }
Beispiel #4
0
        public void LaunchCorrectAutoOrientation(ScreenOrientation orientation)
        {
            PlayerSettings.defaultInterfaceOrientation           = UIOrientation.AutoRotation;
            PlayerSettings.allowedAutorotateToPortrait           = true;
            PlayerSettings.allowedAutorotateToPortraitUpsideDown = true;
            PlayerSettings.allowedAutorotateToLandscapeLeft      = true;
            PlayerSettings.allowedAutorotateToLandscapeRight     = true;

            m_InputTest.Rotation = ScreenTestUtilities.OrientationRotation[orientation];
            m_Simulation         = new ScreenSimulation(m_TestDevice, m_InputTest, SimulatorPlayerSettingsUI.InitDefaultPlayerSettings(), m_TestWindow);
            Assert.AreEqual(orientation, Screen.orientation);
        }
Beispiel #5
0
        public void RuntimeAutoRotationOrientationDisable(ScreenOrientation orientation)
        {
            m_InputTest.Rotation = ScreenTestUtilities.OrientationRotation[orientation];
            m_Simulation         = new ScreenSimulation(m_TestDevice, m_InputTest, SimulatorPlayerSettingsUI.InitDefaultPlayerSettings(), m_Window);

            Screen.orientation                    = ScreenOrientation.AutoRotation;
            Screen.autorotateToPortrait           = true;
            Screen.autorotateToPortraitUpsideDown = true;
            Screen.autorotateToLandscapeLeft      = true;
            Screen.autorotateToLandscapeRight     = true;

            Assert.AreEqual(orientation, Screen.orientation);
            ScreenTestUtilities.SetScreenAutoOrientation(orientation, false);
            Assert.AreNotEqual(orientation, Screen.orientation);
        }
Beispiel #6
0
        public void RotateWithAutorotate(ScreenOrientation orientation)
        {
            m_InputTest.Rotation = ScreenTestUtilities.OrientationRotation[ScreenOrientation.PortraitUpsideDown];
            m_Simulation         = new ScreenSimulation(m_TestDevice, m_InputTest, SimulatorPlayerSettingsUI.InitDefaultPlayerSettings(), m_Window);

            Screen.orientation                    = ScreenOrientation.AutoRotation;
            Screen.autorotateToPortrait           = true;
            Screen.autorotateToPortraitUpsideDown = true;
            Screen.autorotateToLandscapeLeft      = true;
            Screen.autorotateToLandscapeRight     = true;

            m_InputTest.Rotation = ScreenTestUtilities.OrientationRotation[orientation];
            m_InputTest.OnRotation?.Invoke(ScreenTestUtilities.OrientationRotation[orientation]);

            Assert.AreEqual(orientation, Screen.orientation);
        }
Beispiel #7
0
        public void ScreenResolutionChangesCorrectlyWhenChangingOrientation(ScreenOrientation initOrientation, ScreenOrientation newOrientation, int screenWidth, int screenHeight)
        {
            var portraitResolution  = new Vector2(screenWidth, screenHeight);
            var landscapeResolution = new Vector2(screenHeight, screenWidth);

            var testDevice = DeviceInfoLibrary.GetDeviceWithSupportedOrientations(ScreenTestUtilities.ExplicitOrientations, screenWidth, screenHeight);
            var testWindow = new TestWindow();

            m_Simulation = new ScreenSimulation(testDevice, m_InputTest, SimulatorPlayerSettingsUI.InitDefaultPlayerSettings(), testWindow);

            Screen.orientation = initOrientation;
            Assert.AreEqual(initOrientation.IsLandscape() ? landscapeResolution : portraitResolution, testWindow.TargetSize);

            Screen.orientation = newOrientation;
            Assert.AreEqual(newOrientation.IsLandscape() ? landscapeResolution : portraitResolution, testWindow.TargetSize);
        }
        public void WillRotateOnlyToSupportedOrientationsWhenExplicitlySet(ScreenOrientation unsupportedOrientation)
        {
            var supportedOrientations = new List <ScreenOrientation>(ScreenTestUtilities.ExplicitOrientations);

            supportedOrientations.Remove(unsupportedOrientation);

            var testDevice = DeviceInfoLibrary.GetDeviceWithSupportedOrientations(supportedOrientations.ToArray());

            m_Simulation = new ScreenSimulation(testDevice, m_InputTest, SimulatorPlayerSettingsUI.InitDefaultPlayerSettings(), m_Window);
            foreach (var orientation in supportedOrientations)
            {
                Screen.orientation = orientation;
                Assert.AreEqual(orientation, Screen.orientation);
            }
            Screen.orientation = unsupportedOrientation;
            Assert.AreNotEqual(unsupportedOrientation, Screen.orientation);
        }
Beispiel #9
0
        public void ScreenResolutionChangesCorrectlyWhenChangingResolutionAndOrientation(ScreenOrientation initOrientation, ScreenOrientation newOrientation, int newWidth, int newHeight)
        {
            var initResolution    = new Vector2(newWidth, newHeight);
            var flippedResolution = new Vector2(newHeight, newWidth);
            var isFlipped         = initOrientation.IsLandscape() ^ newOrientation.IsLandscape();

            var testDevice = DeviceInfoLibrary.GetDeviceWithSupportedOrientations(ScreenTestUtilities.ExplicitOrientations);
            var testWindow = new TestWindow();

            m_Simulation = new ScreenSimulation(testDevice, m_InputTest, SimulatorPlayerSettingsUI.InitDefaultPlayerSettings(), testWindow);

            Screen.orientation = initOrientation;
            Screen.SetResolution(newWidth, newHeight, true);
            Assert.AreEqual(initResolution, testWindow.TargetSize);

            Screen.orientation = newOrientation;
            Assert.AreEqual(isFlipped ? flippedResolution : initResolution, testWindow.TargetSize);
        }
Beispiel #10
0
        public void AutoOrientationsInitializedFromPlayerSettings(bool portrait, bool portraitUpsideDown, bool landscapeLeft, bool landscapeRight)
        {
            PlayerSettings.defaultInterfaceOrientation = UIOrientation.AutoRotation;

            // Setting all to true to avoid setting all to false, that would throw an exception and enable Portrait
            PlayerSettings.allowedAutorotateToPortrait           = true;
            PlayerSettings.allowedAutorotateToPortraitUpsideDown = true;
            PlayerSettings.allowedAutorotateToLandscapeLeft      = true;
            PlayerSettings.allowedAutorotateToLandscapeRight     = true;

            PlayerSettings.allowedAutorotateToPortrait           = portrait;
            PlayerSettings.allowedAutorotateToPortraitUpsideDown = portraitUpsideDown;
            PlayerSettings.allowedAutorotateToLandscapeLeft      = landscapeLeft;
            PlayerSettings.allowedAutorotateToLandscapeRight     = landscapeRight;

            m_Simulation = new ScreenSimulation(m_TestDevice, m_InputTest, SimulatorPlayerSettingsUI.InitDefaultPlayerSettings(), m_TestWindow);

            Assert.AreEqual(portrait, Screen.autorotateToPortrait);
            Assert.AreEqual(portraitUpsideDown, Screen.autorotateToPortraitUpsideDown);
            Assert.AreEqual(landscapeLeft, Screen.autorotateToLandscapeLeft);
            Assert.AreEqual(landscapeRight, Screen.autorotateToLandscapeRight);
        }
Beispiel #11
0
        public void WillRotateOnlyToEnabledOrientationsWhenAutoRotating(ScreenOrientation disabledOrientation)
        {
            var enabledOrientations = new List <ScreenOrientation>(ScreenTestUtilities.ExplicitOrientations);

            enabledOrientations.Remove(disabledOrientation);

            m_Simulation = new ScreenSimulation(m_TestDevice, m_InputTest, SimulatorPlayerSettingsUI.InitDefaultPlayerSettings(), m_Window);

            Screen.orientation = ScreenOrientation.AutoRotation;
            foreach (var orientation in enabledOrientations)
            {
                ScreenTestUtilities.SetScreenAutoOrientation(orientation, true);
            }
            ScreenTestUtilities.SetScreenAutoOrientation(disabledOrientation, false);

            foreach (var orientation in enabledOrientations)
            {
                m_InputTest.Rotate(orientation);
                Assert.AreEqual(orientation, Screen.orientation);
            }
            m_InputTest.Rotate(disabledOrientation);
            Assert.AreNotEqual(disabledOrientation, Screen.orientation);
        }
        public void WillRotateOnlyToSupportedOrientationsWhenAutoRotating(ScreenOrientation unsupportedOrientation)
        {
            var supportedOrientations = new List <ScreenOrientation>(ScreenTestUtilities.ExplicitOrientations);

            supportedOrientations.Remove(unsupportedOrientation);

            var testDevice = DeviceInfoLibrary.GetDeviceWithSupportedOrientations(supportedOrientations.ToArray());

            m_Simulation = new ScreenSimulation(testDevice, m_InputTest, SimulatorPlayerSettingsUI.InitDefaultPlayerSettings(), m_Window);

            Screen.orientation                    = ScreenOrientation.AutoRotation;
            Screen.autorotateToPortrait           = true;
            Screen.autorotateToPortraitUpsideDown = true;
            Screen.autorotateToLandscapeLeft      = true;
            Screen.autorotateToLandscapeRight     = true;

            foreach (var orientation in supportedOrientations)
            {
                m_InputTest.Rotate(orientation);
                Assert.AreEqual(orientation, Screen.orientation);
            }
            m_InputTest.Rotate(unsupportedOrientation);
            Assert.AreNotEqual(unsupportedOrientation, Screen.orientation);
        }
Beispiel #13
0
 public void SetUp()
 {
     m_InputProvider    = new TestInput();
     m_ScreenSimulation = new ScreenSimulation(m_Device, m_InputProvider, SimulatorPlayerSettingsUI.InitDefaultPlayerSettings(), m_SimulatorWindow);
 }