コード例 #1
0
        /// <summary>
        /// Force aspect window.
        ///
        /// SOURCE: https://gamedev.stackexchange.com/questions/86707/how-to-lock-aspect-ratio-when-resizing-game-window-in-unity
        /// AUTHOR: Entity in JavaScript.
        /// Modefied: Jen-Chieh Shen to C#.
        /// </summary>
        private void DoFoceAspectScreen()
        {
            if (Screen.fullScreen)
            {
                return;
            }

            JCS_ScreenSettings ss = JCS_ScreenSettings.instance;

            int width  = JCS_Screen.width;
            int height = JCS_Screen.height;

            // if the user is changing the width
            if (PREV_SCREEN_SIZE.width != width)
            {
                // update the height
                float heightAccordingToWidth = width / ss.ASPECT_RATIO_SCREEN_SIZE.width * ss.ASPECT_RATIO_SCREEN_SIZE.height;
                JCS_Screen.SetResolution(width, (int)Mathf.Round(heightAccordingToWidth), false, 0);
            }

            // if the user is changing the height
            if (PREV_SCREEN_SIZE.height != height)
            {
                // update the width
                float widthAccordingToHeight = height / ss.ASPECT_RATIO_SCREEN_SIZE.height * ss.ASPECT_RATIO_SCREEN_SIZE.width;
                JCS_Screen.SetResolution((int)Mathf.Round(widthAccordingToHeight), height, false, 0);
            }

            this.PREV_SCREEN_SIZE.width  = width;
            this.PREV_SCREEN_SIZE.height = height;
        }
コード例 #2
0
        /// <summary>
        /// Resize the screen resolution to standard resolution once.
        /// </summary>
        /// <param name="starting"> Change the starting screen as well? </param>
        public void ForceStandardScreenOnce(bool starting = false)
        {
            JCS_Screen.SetResolution(STANDARD_SCREEN_SIZE.width, STANDARD_SCREEN_SIZE.height, false, 0);

            if (starting)
            {
                STARTING_SCREEN_SIZE.width  = STANDARD_SCREEN_SIZE.width;
                STARTING_SCREEN_SIZE.height = STANDARD_SCREEN_SIZE.height;
            }
        }
コード例 #3
0
        /// <summary>
        /// Always make the screen the same as standards screen width and
        /// standard screen height.
        /// </summary>
        private void DoAlwaysStandard()
        {
            float width  = JCS_Screen.width;
            float height = JCS_Screen.height;

            if (width != STANDARD_SCREEN_SIZE.width || height != STANDARD_SCREEN_SIZE.height)
            {
                JCS_Screen.SetResolution(STANDARD_SCREEN_SIZE.width, STANDARD_SCREEN_SIZE.height, false, 0);
            }

            this.PREV_SCREEN_SIZE.width  = width;
            this.PREV_SCREEN_SIZE.height = height;
        }
コード例 #4
0
        /// <summary>
        /// Make the screen in certain aspect ratio.
        /// </summary>
        /// <param name="starting"> Change the starting screen as well? </param>
        public void ForceAspectScreenOnce(bool starting = false)
        {
            int width  = JCS_Screen.width;
            int height = JCS_Screen.height;

            bool smaller = ASPECT_RATIO_SCREEN_SIZE.width > ASPECT_RATIO_SCREEN_SIZE.height;

            // Reverse it if resize to larger edge.
            if (!RESIZE_TO_SMALLER_EDGE)
            {
                smaller = !smaller;
            }

            if (smaller)
            {
                // update the height
                float heightAccordingToWidth = width / ASPECT_RATIO_SCREEN_SIZE.width * ASPECT_RATIO_SCREEN_SIZE.height;
                JCS_Screen.SetResolution(width, (int)Mathf.Round(heightAccordingToWidth), false, 0);

                if (starting)
                {
                    STARTING_SCREEN_SIZE.width  = width;
                    STARTING_SCREEN_SIZE.height = (int)heightAccordingToWidth;
                }
            }
            else
            {
                // update the width
                float widthAccordingToHeight = height / ASPECT_RATIO_SCREEN_SIZE.height * ASPECT_RATIO_SCREEN_SIZE.width;
                JCS_Screen.SetResolution((int)Mathf.Round(widthAccordingToHeight), height, false, 0);

                if (starting)
                {
                    STARTING_SCREEN_SIZE.width  = (int)widthAccordingToHeight;
                    STARTING_SCREEN_SIZE.height = height;
                }
            }
        }