Ejemplo n.º 1
0
        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;
        }
 private async ValueTask DispatchEventAsync(bool isFullScreen) => await Task.Run(() => OnFullScreenChanged?.Invoke(isFullScreen));