コード例 #1
0
        /// <summary>
        /// Handle the mobile slide input.
        /// </summary>
        private void DoMobileSlide()
        {
            JCS_SlideInput si = JCS_InputManager.instance.GetGlobalSlideInput();

            if (si == null)
            {
                return;
            }

            if (si.Touched)
            {
                mPanelHolder.EnableSlidePanels(false);

                Vector3 deltaPos = si.DeltaPos;

                if (mFreezeX)
                {
                    deltaPos.x = 0.0f;
                }
                if (mFreezeY)
                {
                    deltaPos.y = 0.0f;
                }

                mPanelHolder.DeltaMove(-deltaPos / mSlideStickiness);
            }
            else
            {
                mPanelHolder.EnableSlidePanels(true);
            }

            if (JCS_Input.GetMouseButtonUp(JCS_MouseButton.LEFT))
            {
                Vector3 posDiff = mPanelHolder.PositionDiff();

                if (!mFreezeX && posDiff.x > this.mSlideDistanceX)
                {
                    if (JCS_Mathf.IsPositive(si.DragDisplacement.x))
                    {
                        SwitchScene(JCS_2D4Direction.LEFT);
                    }
                    else
                    {
                        SwitchScene(JCS_2D4Direction.RIGHT);
                    }
                }

                if (!mFreezeY && posDiff.y > this.mSlideDistanceY)
                {
                    if (JCS_Mathf.IsPositive(si.DragDisplacement.y))
                    {
                        SwitchScene(JCS_2D4Direction.BOTTOM);
                    }
                    else
                    {
                        SwitchScene(JCS_2D4Direction.TOP);
                    }
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Handle the mobile swipe input.
        /// </summary>
        private void DoMobileSwipe()
        {
            var si = JCS_SlideInput.instance;

            if (si == null)
            {
                return;
            }

            bool enableSlidePanel = true;

            if (mInteractableSwipe && si.Touched)
            {
                Vector3 deltaPos = si.DeltaPos;

                bool cancelX = false;
                bool cancelY = false;

                if (mFreezeX)
                {
                    cancelX = true;
                }
                if (mFreezeY)
                {
                    cancelY = true;
                }

                /* Fix so you don't swipe over boundaries! */
                {
                    bool positiveX = JCS_Mathf.IsPositive(deltaPos.x);
                    bool positiveY = JCS_Mathf.IsPositive(deltaPos.y);

                    if (mCurrentPage.x <= mMinPageX && positiveX ||
                        mCurrentPage.x >= mMaxPageX && !positiveX)
                    {
                        cancelX = true;
                    }

                    if (mCurrentPage.y <= mMinPageY && positiveY ||
                        mCurrentPage.y >= mMaxPageY && !positiveY)
                    {
                        cancelY = true;
                    }
                }

                if (cancelX)
                {
                    deltaPos.x = 0.0f;
                }
                if (cancelY)
                {
                    deltaPos.y = 0.0f;
                }

                // If you can move at least one dimension,
                if (!cancelX || !cancelY)
                {
                    enableSlidePanel = false;
                }

                if (!enableSlidePanel)
                {
                    mPanelHolder.DeltaMove(deltaPos);
                }
            }

            mPanelHolder.EnableSlidePanels(enableSlidePanel);

            if (mInteractableSwipe && JCS_Input.GetMouseButtonUp(JCS_MouseButton.LEFT))
            {
                Vector3         posDiff   = si.DragDistance;
                JCS_ScreenSizef vs        = JCS_ScreenSettings.instance.VisibleScreenSize();
                var             target_vs = new JCS_ScreenSizef(vs.width * mSwipeArea.x, vs.height * mSwipeArea.y);

                var speedX = si.DragDistance.x / si.TouchTime;
                var speedY = si.DragDistance.y / si.TouchTime;

                bool reachedX     = posDiff.x > target_vs.width; // distance
                bool speedExceedX = speedX > mSwipeSpeedX;       // speed

                if (!mFreezeX && (reachedX || speedExceedX))
                {
                    if (JCS_Mathf.IsPositive(si.DragDisplacement.x))
                    {
                        SwitchScene(JCS_2D4Direction.LEFT);
                    }
                    else
                    {
                        SwitchScene(JCS_2D4Direction.RIGHT);
                    }

                    if (afterSwiped != null)
                    {
                        afterSwiped.Invoke(mCurrentPage);
                    }
                }

                bool reachedY     = posDiff.y > target_vs.height; // distance
                bool speedExceedY = speedY > mSwipeSpeedY;        // speed

                if (!mFreezeY && (reachedY || speedExceedY))
                {
                    if (JCS_Mathf.IsPositive(si.DragDisplacement.y))
                    {
                        SwitchScene(JCS_2D4Direction.BOTTOM);
                    }
                    else
                    {
                        SwitchScene(JCS_2D4Direction.TOP);
                    }

                    if (afterSwiped != null)
                    {
                        afterSwiped.Invoke(mCurrentPage);
                    }
                }
            }
        }
コード例 #3
0
        /// <summary>
        /// Handle the mobile swipe input.
        /// </summary>
        private void DoMobileSwipe()
        {
            JCS_SlideInput si = JCS_InputManager.instance.GetGlobalSlideInput();

            if (si == null)
            {
                return;
            }

            bool enableSlidePanel = true;

            if (si.Touched)
            {
                Vector3 deltaPos = si.DeltaPos;

                bool cancelX = false;
                bool cancelY = false;

                if (mFreezeX)
                {
                    cancelX = true;
                }
                if (mFreezeY)
                {
                    cancelY = true;
                }

                /* Fix so you don't swipe over boundaries! */
                {
                    bool positiveX = JCS_Mathf.IsPositive(deltaPos.x);
                    bool positiveY = JCS_Mathf.IsPositive(deltaPos.y);

                    if (mCurrentPage.x <= mMinPageX && positiveX ||
                        mCurrentPage.x >= mMaxPageX && !positiveX)
                    {
                        cancelX = true;
                    }

                    if (mCurrentPage.y <= mMinPageY && positiveY ||
                        mCurrentPage.y >= mMaxPageY && !positiveY)
                    {
                        cancelY = true;
                    }
                }

                if (cancelX)
                {
                    deltaPos.x = 0.0f;
                }
                if (cancelY)
                {
                    deltaPos.y = 0.0f;
                }

                // If you can move at least one dimension,
                if (!cancelX || !cancelY)
                {
                    enableSlidePanel = false;
                }

                if (!enableSlidePanel)
                {
                    mPanelHolder.DeltaMove(deltaPos);
                }
            }

            mPanelHolder.EnableSlidePanels(enableSlidePanel);

            if (JCS_Input.GetMouseButtonUp(JCS_MouseButton.LEFT))
            {
                Vector3         posDiff   = si.DragDistance;
                JCS_ScreenSizef vs        = JCS_ScreenSettings.instance.VisibleScreenSize();
                JCS_ScreenSizef target_vs = new JCS_ScreenSizef(vs.width * mSwipeArea.x, vs.height * mSwipeArea.y);

                if (!mFreezeX && posDiff.x > target_vs.width)
                {
                    if (JCS_Mathf.IsPositive(si.DragDisplacement.x))
                    {
                        SwitchScene(JCS_2D4Direction.LEFT);
                    }
                    else
                    {
                        SwitchScene(JCS_2D4Direction.RIGHT);
                    }
                }

                if (!mFreezeY && posDiff.y > target_vs.height)
                {
                    if (JCS_Mathf.IsPositive(si.DragDisplacement.y))
                    {
                        SwitchScene(JCS_2D4Direction.BOTTOM);
                    }
                    else
                    {
                        SwitchScene(JCS_2D4Direction.TOP);
                    }
                }
            }
        }