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, 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 ApplyChanges() { var updateSafeArea = false; var orientationEvent = false; var resolutionEvent = false; var fullScreenEvent = false; var screenSpaceSafeAreaEvent = false; var insetsEvent = false; if (m_RequestedOrientation != m_RenderedOrientation) { if (m_RequestedOrientation.IsLandscape() != m_RenderedOrientation.IsLandscape()) { // Swap resolution Width and Height if changing from Portrait to Landscape or vice versa if (m_WasResolutionSet) { (m_RequestedHeight, m_RequestedWidth) = (m_RequestedWidth, m_RequestedHeight); } else { m_RequestDefaultResolution = true; } } m_RenderedOrientation = m_RequestedOrientation; orientationEvent = true; m_RequestInsetUpdate = true; updateSafeArea = true; } if (m_RequestedFullScreen != m_IsFullScreen) { m_IsFullScreen = m_RequestedFullScreen; m_RequestInsetUpdate = true; // We only change the resolution if we never set the resolution by calling Screen.SetResolution(). if (!m_WasResolutionSet) { m_RequestDefaultResolution = true; } updateSafeArea = true; fullScreenEvent = true; } if (m_RequestInsetUpdate) { CalculateInsets(); insetsEvent = true; } if ((m_RequestedWidth != m_CurrentWidth || m_RequestedHeight != m_CurrentHeight) && m_WasResolutionSet) { m_CurrentWidth = m_RequestedWidth; m_CurrentHeight = m_RequestedHeight; updateSafeArea = true; resolutionEvent = true; } else if (m_RequestDefaultResolution) { CalculateResolutionWithInsets(); updateSafeArea = true; resolutionEvent = true; } if (updateSafeArea) { CalculateSafeAreaAndCutouts(); screenSpaceSafeAreaEvent = true; } if (orientationEvent) { OnOrientationChanged?.Invoke(); } if (resolutionEvent) { OnResolutionChanged?.Invoke(m_CurrentWidth, m_CurrentHeight); } if (fullScreenEvent) { OnFullScreenChanged?.Invoke(m_IsFullScreen); } if (screenSpaceSafeAreaEvent) { OnScreenSpaceSafeAreaChanged?.Invoke(ScreenSpaceSafeArea); } if (insetsEvent) { OnInsetsChanged?.Invoke(Insets); } m_RequestDefaultResolution = false; m_RequestedOrientation = m_RenderedOrientation; m_RequestedHeight = m_CurrentHeight; m_RequestedWidth = m_CurrentWidth; m_RequestInsetUpdate = false; }