Beispiel #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);
                    }
                }
            }
        }
        /// <summary>
        /// Handle these events.
        ///   -> OnMouseUp
        ///   -> OnMouseOver
        /// </summary>
        private void Handle_UpOver()
        {
            JCS_InputManager im = JCS_InputManager.instance;

            JCS_SlideInput slideInput = im.GetGlobalSlideInput();

            foreach (RaycastHit hit in mHits)
            {
                if (hit.transform == null)
                {
                    continue;
                }

                GameObject obj = hit.transform.gameObject;

                if (im.Support_OnMouseOver)
                {
                    _SendMessage(obj, "OnMouseOver");
                }

                if (im.Support_OnMouseUp)
                {
                    if (mTouchedLastFrame && !slideInput.Touched)
                    {
                        _SendMessage(obj, "OnMouseUp");
                    }
                }

                PrintName(hit.transform);
            }
        }
        /* Setter & Getter */

        public void SetGlobalSlideInput(JCS_SlideInput si)
        {
            if (mSlideInput != null)
            {
                JCS_Debug.LogWarning("You are trying to override an existing `slide input`");
                return;
            }
            this.mSlideInput = si;
        }
        /// <summary>
        /// Handle these events.
        ///   -> OnMouseDown
        ///   -> OnMouseDrag
        /// </summary>
        private void Handle_DownDrag()
        {
            JCS_InputManager im = JCS_InputManager.instance;

            JCS_SlideInput slideInput = im.GetGlobalSlideInput();

            if (!slideInput.Touched)
            {
                this.mTouchedLastFrame = false;
                return;
            }

            // A ray is an infinite line starting at an origin and going into a direction
            // For this we will use our mouse position
            Ray ray = mCamera.ScreenPointToRay(Input.mousePosition);

            mHits = Physics.RaycastAll(ray, mRaycastDistance);

            foreach (RaycastHit hit in mHits)
            {
                if (hit.transform == null)
                {
                    continue;
                }

                GameObject obj = hit.transform.gameObject;

                if (slideInput.Touched)
                {
                    if (im.Support_OnMouseDown)
                    {
                        if (!mTouchedLastFrame)
                        {
                            _SendMessage(obj, "OnMouseDown");
                        }
                    }

                    if (im.Support_OnMouseDrag)
                    {
                        if (slideInput.DeltaPos != Vector2.zero)
                        {
                            _SendMessage(obj, "OnMouseDrag");
                        }
                    }
                }

                PrintName(hit.transform);
            }

            this.mTouchedLastFrame = true;
        }
Beispiel #5
0
        private void Update()
        {
#if (UNITY_EDITOR)
            Test();
#endif

            if (mPanelHolder != null)
            {
                JCS_SlideInput si = JCS_InputManager.instance.GetJCSSlideInput();
                if (si != null)
                {
                    mPanelHolder.AddForce(-si.DeltaPos.x, JCS_Axis.AXIS_X);
                    mPanelHolder.AddForce(-si.DeltaPos.y, JCS_Axis.AXIS_Y);
                }
            }
        }
        /// <summary>
        /// Add the input type base on the platform type.
        /// </summary>
        private void AddInputBaseOnPlatform()
        {
            switch (JCS_ApplicationManager.instance.PlatformType)
            {
            case JCS_PlatformType.MOBILE:
            {
                if (this.mSlideInput == null)
                {
                    this.mSlideInput = this.gameObject.AddComponent <JCS_SlideInput>();
                }

                if (this.mMobileMouseEvent == null)
                {
                    this.mMobileMouseEvent = this.gameObject.AddComponent <JCS_MobileMouseEvent>();
                }
            }
            break;
            }
        }
Beispiel #7
0
        protected virtual void FixedUpdate()
        {
            if (this.mTargetTransform == null)
            {
                ResetVelocityWhileNotActive();
                return;
            }

            if (!mFollowing)
            {
                ResetVelocityWhileNotActive();
                return;
            }

            // if freezing effect in runtime, we have to record down this
            if (mFreezeInRuntime)
            {
                this.mFreezeRecord = this.transform.position;
            }

            if (mZoomWithMouseOrTouch)
            {
#if (UNITY_EDITOR || UNITY_STANDALONE)
                // Get the wheel value from the Unity API
                //
                // physical layer [mouse wheel] ->
                // OS layer ->
                // application layer [Unity itself] ->
                // to here...
                mWheelDegree = Input.GetAxis("Mouse ScrollWheel");
#elif (UNITY_ANDROID || UNITY_IPHIONE || UNITY_IOS)
                JCS_SlideInput slideInput = JCS_InputManager.instance.GetGlobalSlideInput();
                mWheelDegree = slideInput.TouchDistanceDelta;
#endif
                ZoomCamera(mWheelDegree);
            }

            // Smooth track.
            if (mSmoothTrack)
            {
                // Try to approach to the target position.
                mVelocity.x = ((this.mTargetTransform.position.x + mPositionOffset.x) -
                               this.transform.position.x) / mFrictionX;
                mVelocity.y = ((this.mTargetTransform.position.y + mPositionOffset.y) -
                               this.transform.position.y) / mFrictionY;
                mVelocity.z = ((this.mTargetPosition.z + mPositionOffset.z) -
                               this.transform.position.z) / mScrollFriction;

                // Update self position
                this.transform.position += this.mVelocity * Time.deltaTime;
            }
            // Hard track
            else
            {
                // follow the object with frame distance.
                // distance = current frame position - last frame position
                Vector3 currentFramePos = mTargetTransform.position + mPositionOffset;
                this.transform.position += currentFramePos - mLastFramePos;
                mLastFramePos            = currentFramePos;
            }

            // do freezing the last
            DoFreezing();

            // Do the camera boundaries check!!
            CameraBoundaries();
        }
        //----------------------
        // Protected Variables

        //========================================
        //      setter / getter
        //------------------------------
        public void SetJCSSlideInput(JCS_SlideInput sl)
        {
            this.mSlideInput = sl;
        }
Beispiel #9
0
        protected override void LateUpdate()
        {
#if (UNITY_EDITOR)
            Test();
#endif
            base.LateUpdate();

            if (mTargetTransform == null)
            {
                return;
            }

            InputCamera();

            DoFollowing();

            UpDownMovement();


            this.mRecordPosition = this.transform.position;

            if (mZoomWithMouseOrTouch)
            {
#if (UNITY_EDITOR || UNITY_STANDALONE)
                // Get the wheel value from the Unity API
                //
                // physical layer [mouse wheel] ->
                // OS layer ->
                // application layer [Unity itself] ->
                // to here...
                mWheelDegree = Input.GetAxis("Mouse ScrollWheel");
#elif (UNITY_ANDROID || UNITY_IPHIONE || UNITY_IOS)
                JCS_SlideInput slideInput = JCS_InputManager.instance.GetGlobalSlideInput();
                mWheelDegree = slideInput.TouchDistanceDelta;
#endif
                ZoomCamera(mWheelDegree);
            }

            Vector3 newPos = Vector3.forward * mTargetScrollSpeed * Time.deltaTime;

            // if is valid, do action.
            if (!JCS_Mathf.IsNaN(newPos))
            {
                // record down the position before calling the
                // translate function
                Vector3 currentPos = this.transform.position;

                // do translate base on the scrolling distance
                // we get from the input buffer.
                this.transform.Translate(newPos);

                // get the updated position!
                Vector3 afterTransPos = this.transform.position;

                // update the track position
                mTrackPosition += afterTransPos - currentPos;
            }

            // Fix the speed if reach the distance!
            FixedMinMaxDistance();

            // asymptotic back to zero
            mTargetScrollSpeed += (0.0f - mTargetScrollSpeed) / mScrollSpeedFriction * Time.deltaTime;

            // asymptotic revolution
            {
                float revoDelta = (mTargetRevolution - mCurrentRevolution) / mRotateFriction * Time.deltaTime;

                mCurrentRevolution += revoDelta;

                this.transform.RotateAround(mTargetTransform.position, Vector3.up, revoDelta);
            }
        }
        /// <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);
                    }
                }
            }
        }