コード例 #1
0
        private void UpdateViewport()
        {
            var dimensions = GetDimensions(Window.ClientBounds);

            if (lastWindowDimensions == dimensions)
            {
                return;
            }
            lastWindowDimensions = dimensions;

            float ratio = (float)dimensions.X / dimensions.Y;

            if (ratio > WidescreenRatio)
            {
                var optimalDimensions = new Point(Calc.RoundToInt(dimensions.Y * WidescreenRatio), dimensions.Y);
                int leftEdge          = (dimensions.X - optimalDimensions.X) / 2;
                Viewport = new Viewport(leftEdge, 0, optimalDimensions.X, optimalDimensions.Y, 0, 1);
            }
            else if (ratio < WidescreenRatio)
            {
                var optimalDimensions = new Point(dimensions.X, Calc.RoundToInt(dimensions.X / WidescreenRatio));
                int topEdge           = (dimensions.Y - optimalDimensions.Y) / 2;
                Viewport = new Viewport(0, topEdge, optimalDimensions.X, optimalDimensions.Y, 0, 1);
            }
            else
            {
                Viewport = new Viewport(0, 0, dimensions.X, dimensions.Y, 0, 1);
            }

            MDraw.Camera.CalculateScale();

            OnResolutionChanged?.Invoke(this, EventArgs.Empty);
        }
コード例 #2
0
ファイル: ScreenSimulation.cs プロジェクト: TomPetry/Slice
        private void SetResolution(int width, int height)
        {
            m_CurrentWidth      = width;
            m_CurrentHeight     = height;
            m_Window.TargetSize = new Vector2(width, height);
            CalculateSafeAreaAndCutouts();

            OnResolutionChanged?.Invoke(m_CurrentWidth, m_CurrentHeight);
        }
コード例 #3
0
        public void Tick()
        {
            Resolution currentRes = UnityEngine.Screen.currentResolution;

            if (currentRes.width == lastRes.width && currentRes.height == lastRes.height)
            {
                return;
            }

            OnResolutionChanged?.Invoke(lastRes, currentRes);
            lastRes = currentRes;
        }