コード例 #1
0
        // Insets are parts of the screen that are outside of unity rendering area, like navigation bar in windowed mode. Insets are only possible on Android at the moment.
        private void CalculateInsets()
        {
            if (!m_DeviceInfo.IsAndroidDevice())
            {
                return;
            }

            var inset = Vector4.zero;

            if (!m_IsFullScreen)
            {
                switch (m_RenderedOrientation)
                {
                case ScreenOrientation.Portrait:
                case ScreenOrientation.LandscapeLeft:
                case ScreenOrientation.LandscapeRight:
                    inset = new Vector4(0, m_Screen.height - m_SupportedOrientations[ScreenOrientation.Portrait].safeArea.height, 0, m_Screen.navigationBarHeight);
                    break;

                case ScreenOrientation.PortraitUpsideDown:
                    var topInset = m_Screen.height - m_SupportedOrientations[ScreenOrientation.Portrait].safeArea.height + m_Screen.navigationBarHeight;
                    inset = new Vector4(0, topInset, 0, 0);
                    break;
                }
            }
            Insets = inset;
            OnInsetsChanged?.Invoke(inset);
        }
コード例 #2
0
        // Insets are parts of the screen that are outside of unity rendering area, like navigation bar in windowed mode. Insets are only possible on Android at the moment.
        private void CalculateInsets()
        {
            if (!m_DeviceInfo.IsAndroidDevice())
            {
                return;
            }

            var safeArea = m_SupportedOrientations[ScreenOrientation.Portrait].safeArea;
            var inset    = Vector4.zero;

            if (!m_IsRenderingOutsideSafeArea)
            {
                inset = new Vector4
                {
                    x = safeArea.x,
                    y = m_Screen.height - safeArea.height - safeArea.y,
                    z = m_Screen.width - safeArea.width - safeArea.x,
                    w = safeArea.y
                };
            }

            if (!m_IsFullScreen)
            {
                switch (m_RenderedOrientation)
                {
                case ScreenOrientation.Portrait:
                case ScreenOrientation.LandscapeLeft:
                case ScreenOrientation.LandscapeRight:
                    inset.w += m_Screen.navigationBarHeight;
                    break;

                case ScreenOrientation.PortraitUpsideDown:
                    if (m_IsRenderingOutsideSafeArea)
                    {
                        inset.y = m_Screen.height - safeArea.height - safeArea.y;
                    }

                    inset.y += m_Screen.navigationBarHeight;

                    break;
                }
            }
            Insets = inset;
            OnInsetsChanged?.Invoke(inset);
        }
コード例 #3
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;
        }