示例#1
0
        /// <summary>
        /// UGUI method switch the panel.
        /// </summary>
        /// <param name="towardDirection"> direction to switch scene. </param>
        private void UGUISwitchScene(JCS_2D4Direction towardDirection)
        {
            // get the Screen Width and Screen Height
            JCS_ScreenSettings ss = JCS_ScreenSettings.instance;

            float screenWidth  = ss.STARTING_SCREEN_WIDTH;
            float screenHeight = ss.STARTING_SCREEN_HEIGHT;

            // make a copy of old position
            Vector3 newScenePosition = Vector3.zero;

            switch (towardDirection)
            {
            case JCS_2D4Direction.TOP:
                newScenePosition.y += screenHeight;
                break;

            case JCS_2D4Direction.BOTTOM:
                newScenePosition.y -= screenHeight;
                break;

            case JCS_2D4Direction.RIGHT:
                newScenePosition.x += screenWidth;
                break;

            case JCS_2D4Direction.LEFT:
                newScenePosition.x -= screenWidth;
                break;
            }

            mPanelHolder.AddForce(newScenePosition);
        }
示例#2
0
        /// <summary>
        /// Resize the game if screen size changes.
        /// </summary>
        protected virtual void OnResizeGame()
        {
            JCS_ScreenSettings ss = JCS_ScreenSettings.instance;

            float currentScreenRatio  = ss.CURRENT_SCREEN_WIDTH / ss.CURRENT_SCREEN_HEIGHT;
            float startingScreenRatio = (float)ss.STARTING_SCREEN_WIDTH / (float)ss.STARTING_SCREEN_HEIGHT;

            if (currentScreenRatio > startingScreenRatio)
            {
                // Set the limit if reach the starting screen ratio.
                ss.CURRENT_SCREEN_WIDTH  = (float)ss.STARTING_SCREEN_WIDTH;
                ss.CURRENT_SCREEN_HEIGHT = (float)ss.STARTING_SCREEN_HEIGHT;
            }

            float prevRatio = ss.PREV_SCREEN_WIDTH / ss.PREV_SCREEN_HEIGHT;
            float newRatio  = ss.CURRENT_SCREEN_WIDTH / ss.CURRENT_SCREEN_HEIGHT;

            float divRatio = prevRatio / newRatio;

            mCamera.orthographicSize *= divRatio;
            mCamera.fieldOfView      *= divRatio;

            if (mSceneJustLoad)
            {
                float bw = ss.BlackspaceWidth();
                float bh = ss.BlackspaceHeight();

                // Width does not need to be calculate, but
                // need to set back to the original value.
                // Hence, the 'mRecordOrthographicSize' variable.
                if (bw > bh)
                {
                    mCamera.orthographicSize = mRecordOrthographicSize;
                    mCamera.fieldOfView      = mRecordFieldOfView;
                }
                // Calculating the proper hight.
                else
                {
                    // Calculate what the height suppose to be!
                    float supposeHeight = ((float)Screen.width * (float)ss.STARTING_SCREEN_HEIGHT) / (float)ss.STARTING_SCREEN_WIDTH;

                    // Use the 'suppose height' to find the proper
                    // height ratio.
                    float heightRatio = ((float)Screen.height / supposeHeight);

                    mCamera.orthographicSize = heightRatio * mRecordOrthographicSize;
                    mCamera.fieldOfView      = heightRatio * mRecordFieldOfView;
                }

                mSceneJustLoad = false;
            }

            /* Store it to screen settings. */
            {
                ss.ORTHOGRAPHIC_SIZE = mCamera.orthographicSize;
                ss.FIELD_OF_VIEW     = mCamera.fieldOfView;
            }
        }
示例#3
0
        //----------------------
        // Protected Functions

        //----------------------
        // Private Functions

        /// <summary>
        /// Resize the UI if screen size changes.
        /// </summary>
        private void DoResizeUI()
        {
            JCS_ScreenSettings ss = JCS_ScreenSettings.instance;

            mWScale = (float)Screen.width / (float)ss.STARTING_SCREEN_WIDTH;
            mHScale = (float)Screen.height / (float)ss.STARTING_SCREEN_HEIGHT;

            mTargetScale = (mWScale > mHScale) ? mHScale : mWScale;

            transform.localScale = Vector3.one * mTargetScale;
        }
示例#4
0
        /// <summary>
        /// Fit screen size base on Unity Engine architecture.
        /// </summary>
        private void FitPerfectSize()
        {
            JCS_ScreenSettings ss = JCS_ScreenSettings.instance;

            float newWidth  = ss.STARTING_SCREEN_WIDTH;
            float newHeight = ss.STARTING_SCREEN_HEIGHT;

            float currentWidth  = mRectTransform.sizeDelta.x;
            float currentHeight = mRectTransform.sizeDelta.y;

            mPanelDeltaWidthRatio  = currentWidth / newWidth;
            mPanelDeltaHeightRatio = currentHeight / newHeight;

            Vector3 newPosition = mRectTransform.localPosition;

            if (JCS_Camera.main != null)
            {
                // make toward to the camera position
                Camera cam = JCS_Camera.main.GetCamera();

                if (cam != null)
                {
                    Vector3 panelPos = mRectTransform.localPosition;
                    // This was `camer position`, but we don't need to
                    // add up the camera position because Canvas has their
                    // own coordinate system or you can call it Canvas Space.
                    Vector3 centerPos = Vector3.zero;

                    // Find the distance between the dialogue object and
                    // the center (which is camera in this case)
                    float distanceX = panelPos.x - centerPos.x;
                    float distanceY = panelPos.y - centerPos.y;

                    newPosition.x = (distanceX / mPanelDeltaWidthRatio);
                    newPosition.y = (distanceY / mPanelDeltaHeightRatio);
                }
            }

            /*
             * NOTE(jenchieh):
             * Cool, `sizeDelta' will actually change the `localPosition'
             * now since version 2017.4.
             *
             * So we set the `sizeDelta' (width and height) first, then
             * set the `localPosition'.
             */
            {
                // set the width and height to the new app rect
                mRectTransform.sizeDelta = new Vector2(newWidth, newHeight);

                // set to the new position
                mRectTransform.localPosition = newPosition;
            }
        }
示例#5
0
        /// <summary>
        /// Fit screen size base on Unity Engine architecture.
        /// </summary>
        private void FitPerfectSize()
        {
            JCS_ScreenSettings ss = JCS_ScreenSettings.instance;

            float newWidth  = ss.STARTING_SCREEN_WIDTH;
            float newHeight = ss.STARTING_SCREEN_HEIGHT;

            float currentWidth  = mRectTransform.sizeDelta.x;
            float currentHeight = mRectTransform.sizeDelta.y;

            mPanelDeltaWidthRatio  = currentWidth / newWidth;
            mPanelDeltaHeightRatio = currentHeight / newHeight;

            Vector3 newPosition = mRectTransform.localPosition;

            if (JCS_Camera.main != null)
            {
                // make toward to the camera position
                Camera cam = JCS_Camera.main.GetCamera();

                if (cam != null)
                {
                    // Find the distance between the dialogue object and
                    // the center (which is camera in this case)
                    float distanceX = mRectTransform.localPosition.x - cam.transform.localPosition.x;
                    float distanceY = mRectTransform.localPosition.y - cam.transform.localPosition.y;

                    newPosition.x = (distanceX / mPanelDeltaWidthRatio);
                    newPosition.y = (distanceY / mPanelDeltaHeightRatio);
                }
            }

            /*
             * NOTE(jenchieh):
             * Cool, `sizeDelta' will actually change the `localPosition'
             * now since version 2017.4.
             *
             * So we set the `sizeDelta' (width and height) first, then
             * set the `localPosition'.
             */
            {
                // set the width and height to the new app rect
                mRectTransform.sizeDelta = new Vector2(newWidth, newHeight);

                // set to the new position
                mRectTransform.localPosition = newPosition;
            }
        }
示例#6
0
        /// <summary>
        /// Fit RECT into our screen space.
        /// </summary>
        /// <param name="rect"> The `RectTransform` object to resize fro screen. </param>
        private void FitScreenSize(RectTransform rect)
        {
            if (rect == null)
            {
                return;
            }

            JCS_ScreenSettings ss         = JCS_ScreenSettings.instance;
            JCS_ScreenSizef    screenRaio = ss.ScreenRatio();

            Vector3 newScale = rect.localScale;

            newScale.x     /= screenRaio.width;
            newScale.y     /= screenRaio.height;
            rect.localScale = newScale;
        }
示例#7
0
        /// <summary>
        /// Set the panel to the edge of the screen.
        /// </summary>
        private void SetToScreenEdge()
        {
            JCS_ScreenSettings ss = JCS_ScreenSettings.instance;

            Vector2 appRect     = new Vector2(ss.STARTING_SCREEN_SIZE.width, ss.STARTING_SCREEN_SIZE.height);
            Vector2 halfAppRect = appRect / 2.0f;

            Vector2 panelSize = mRectTransform.sizeDelta;

            float halfScreenWidth  = (panelSize.x / 2.0f) + halfAppRect.x;
            float halfScreenHeight = (panelSize.y / 2.0f) + halfAppRect.y;

            Vector3 newPos = mRectTransform.localPosition;

            switch (mPlaceDirection)
            {
            case JCS_2D4Direction.TOP:
            {
                newPos.y  += halfScreenHeight;
                this.name += " (Top)";
            }
            break;

            case JCS_2D4Direction.BOTTOM:
            {
                newPos.y  -= halfScreenHeight;
                this.name += " (Bottom)";
            }
            break;

            case JCS_2D4Direction.LEFT:
            {
                newPos.x  -= halfScreenWidth;
                this.name += " (Left)";
            }
            break;

            case JCS_2D4Direction.RIGHT:
            {
                newPos.x  += halfScreenWidth;
                this.name += " (Right)";
            }
            break;
            }

            mRectTransform.localPosition = newPos;
        }
        private void Start()
        {
            JCS_ScreenSettings ss = JCS_ScreenSettings.instance;

            if (RESIZE_SCREEN_THIS_SCENE)
            {
                // Apply new screen aspect ratio.
                ss.ASPECT_RATIO_SCREEN_WIDTH  = ASPECT_RATION_SCREEN_WIDTH_THIS_SCENE;
                ss.ASPECT_RATIO_SCREEN_HEIGHT = ASPECT_RATION_SCREEN_HEIGHT_THIS_SCENE;

                // Resize the screen base on the new screen aspect ratio.
                ss.ForceAspectScreenOnce();
            }

            // Set the panels' color
            SetResizablePanelsColor(ss.RESIZABLE_PANELS_COLOR);
        }
        /// <summary>
        /// Return the screen size according to the GUI mode.
        /// </summary>
        /// <returns>
        /// Return a Vector2 with screen width and height.
        /// </returns>
        private Vector2 GetScreenSize()
        {
            float screenWidth  = 0.0f;
            float screenHeight = 0.0f;

            JCS_ScreenSettings ss  = JCS_ScreenSettings.instance;
            JCS_Camera         cam = JCS_Camera.main;

            JCS_PanelRoot panelRoot = mPanelHolder.slidePanels[0].GetComponent <JCS_PanelRoot>();

            if (panelRoot == null)
            {
                panelRoot = mPanelHolder.slidePanels[0].GetComponentInParent <JCS_PanelRoot>();
            }

            switch (mUnityGUIType)
            {
            case JCS_UnityGUIType.uGUI_2D:
            {
                if (panelRoot != null)
                {
                    screenWidth  = ss.STARTING_SCREEN_SIZE.width;
                    screenHeight = ss.STARTING_SCREEN_SIZE.height;
                }
                else
                {
                    screenWidth  = ss.STANDARD_SCREEN_SIZE.width;
                    screenHeight = ss.STANDARD_SCREEN_SIZE.height;
                }
            }
            break;

            case JCS_UnityGUIType.nGUI_3D:
            {
                screenWidth  = cam.CamRectSize.x;
                screenHeight = cam.CamRectSize.y;
            }
            break;
            }

            return(new Vector2(screenWidth, screenHeight));
        }
示例#10
0
        /// <summary>
        /// Resize the UI if screen size changes.
        /// </summary>
        private void DoResizeUI()
        {
            JCS_ScreenSettings ss = JCS_ScreenSettings.instance;

            float width  = (float)Screen.width;
            float height = (float)Screen.height;

            if (ss.ENSURE_INSIDE_SAFE_AREA)
            {
                width  = (float)JCS_Screen.width;
                height = (float)JCS_Screen.height;
            }

            mWScale = width / (float)ss.STARTING_SCREEN_SIZE.width;
            mHScale = height / (float)ss.STARTING_SCREEN_SIZE.height;

            mTargetScale = (mWScale > mHScale) ? mHScale : mWScale;

            transform.localScale = Vector3.one * mTargetScale;
        }
示例#11
0
        /// <summary>
        /// Set the panel to the edge of the screen.
        /// </summary>
        private void SetToScreenEdge()
        {
            JCS_ScreenSettings ss = JCS_ScreenSettings.instance;

            Vector2 halfAppRect = (new Vector2(ss.STARTING_SCREEN_WIDTH, ss.STARTING_SCREEN_HEIGHT)) / 2.0f;

            float halfScreenWidth  = (mRectTransform.sizeDelta.x / 2.0f) + halfAppRect.x;
            float halfScreenHeight = (mRectTransform.sizeDelta.y / 2.0f) + halfAppRect.y;


            Vector3 newPos = mRectTransform.localPosition;

            switch (mPlaceDirection)
            {
            case JCS_2D4Direction.TOP:
            {
                newPos.y += halfScreenHeight;
            }
            break;

            case JCS_2D4Direction.BOTTOM:
            {
                newPos.y -= halfScreenHeight;
            }
            break;

            case JCS_2D4Direction.LEFT:
            {
                newPos.x -= halfScreenWidth;
            }
            break;

            case JCS_2D4Direction.RIGHT:
            {
                newPos.x += halfScreenWidth;
            }
            break;
            }

            mRectTransform.localPosition = newPos;
        }
示例#12
0
        private void Update()
        {
            JCS_ScreenSettings ss = JCS_ScreenSettings.instance;

            /* Handle color. */
            {
                // Make color editable in runtime.
                SetResizablePanelsColor(ss.RESIZABLE_PANELS_COLOR);
            }

            /* Show hide the panels. */
            {
                if (ss.SHOW_RESIZABLE_PANELS)
                {
                    ShowResizablePanels();
                }
                else
                {
                    HideResizablePanels();
                }
            }
        }