コード例 #1
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, new SimulationPlayerSettings(), 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);
            }
        }
コード例 #2
0
        public void SetUp()
        {
            m_InputTest = new TestInput();
            m_Window    = new TestWindow();

            m_TestDevice = DeviceInfoLibrary.GetDeviceWithSupportedOrientations(new[]
            {
                ScreenOrientation.Portrait,
                ScreenOrientation.LandscapeLeft,
                ScreenOrientation.LandscapeRight,
                ScreenOrientation.PortraitUpsideDown
            });
        }
コード例 #3
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);
        }
コード例 #4
0
        public void OneTimeSetUp()
        {
            m_CachedOrientation          = PlayerSettings.defaultInterfaceOrientation;
            m_CachedAutoPortrait         = PlayerSettings.allowedAutorotateToPortrait;
            m_CachedAutoPortraitReversed = PlayerSettings.allowedAutorotateToPortraitUpsideDown;
            m_CachedAutoLandscapeLeft    = PlayerSettings.allowedAutorotateToLandscapeLeft;
            m_CachedAutoLandscapeRight   = PlayerSettings.allowedAutorotateToLandscapeRight;

            var serializedSettings = PlayerSettings.GetSerializedObject();

            serializedSettings.Update();
            m_CachedScalingMode = serializedSettings.FindProperty("resolutionScalingMode").intValue;
            m_CachedScaledDPI   = serializedSettings.FindProperty("targetPixelDensity").intValue;

            m_TestDevice = DeviceInfoLibrary.GetDeviceWithSupportedOrientations(ScreenTestUtilities.ExplicitOrientations);
            m_TestWindow = new TestWindow();
        }
コード例 #5
0
        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, new SimulationPlayerSettings(), m_Window);
            foreach (var orientation in supportedOrientations)
            {
                Screen.orientation = orientation;
                Assert.AreEqual(orientation, Screen.orientation);
            }
            Screen.orientation = unsupportedOrientation;
            Assert.AreNotEqual(unsupportedOrientation, Screen.orientation);
        }
コード例 #6
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);
        }
コード例 #7
0
        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, new SimulationPlayerSettings(), 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);
        }