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, default, screenDpi);
Ejemplo n.º 2
0
        public void SetUp()
        {
            m_InputTest = new TestInput();

            m_TestDevice = DeviceInfoLibrary.GetDeviceWithSupportedOrientations(new[]
            {
                ScreenOrientation.Portrait,
                ScreenOrientation.LandscapeLeft,
                ScreenOrientation.LandscapeRight,
                ScreenOrientation.PortraitUpsideDown
            });
        }
        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);
        }
        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());
            foreach (var orientation in supportedOrientations)
            {
                Screen.orientation = orientation;
                Assert.AreEqual(orientation, Screen.orientation);
            }
            Screen.orientation = unsupportedOrientation;
            Assert.AreNotEqual(unsupportedOrientation, Screen.orientation);
        }
        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);

            m_Simulation = new ScreenSimulation(testDevice, m_InputTest, new SimulationPlayerSettings());
            var width  = Screen.currentResolution.width;
            var height = Screen.currentResolution.height;

            m_Simulation.OnResolutionChanged += (w, h) =>
            {
                width  = w;
                height = h;
            };

            Screen.orientation = initOrientation;
            Assert.AreEqual(initOrientation.IsLandscape() ? landscapeResolution : portraitResolution, new Vector2(width, height));

            Screen.orientation = newOrientation;
            Assert.AreEqual(newOrientation.IsLandscape() ? landscapeResolution : portraitResolution, new Vector2(width, height));
        }
        public void ScreenResolutionChangesCorrectlyWhenChangingResolutionAndOrientation(ScreenOrientation initOrientation, ScreenOrientation newOrientation, int newWidth, int newHeight)
        {
            var width             = 0;
            var height            = 0;
            var initResolution    = new Vector2(newWidth, newHeight);
            var flippedResolution = new Vector2(newHeight, newWidth);
            var isFlipped         = initOrientation.IsLandscape() ^ newOrientation.IsLandscape();

            var testDevice = DeviceInfoLibrary.GetDeviceWithSupportedOrientations(ScreenTestUtilities.ExplicitOrientations);

            m_Simulation = new ScreenSimulation(testDevice, m_InputTest, new SimulationPlayerSettings());
            m_Simulation.OnResolutionChanged += (w, h) =>
            {
                width  = w;
                height = h;
            };

            Screen.orientation = initOrientation;
            Screen.SetResolution(newWidth, newHeight, true);
            Assert.AreEqual(initResolution, new Vector2(width, height));

            Screen.orientation = newOrientation;
            Assert.AreEqual(isFlipped ? flippedResolution : initResolution, new Vector2(width, height));
        }
        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());

            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);
        }