Esempio n. 1
0
 public PerspectiveInputer()
 {
     mInputData = new InputData();
 }
Esempio n. 2
0
        public void CheckInteracting()
        {
            if (!IsOpenInput)
            {
                return;
            }

            if (mCamera == default)
            {
                mCamera = Camera.main;
            }
            if (mInputData == default)
            {
                mInputData = new InputData();
            }

            mMousePos = Input.mousePosition;
            mInputRay = mCamera.ScreenPointToRay(mMousePos);

            if (Physics.Raycast(mInputRay, out mInputHit, float.MaxValue, LayerMask))
            {
                mHitTarget = mInputHit.transform.gameObject;
                if (Input.GetMouseButtonDown(0))
                {
                    mIsDragStart = false;

                    mMouseDownPos = Input.mousePosition;
                    mTargetTrans  = mInputHit.transform;
                    mScreenSpace  = mCamera.WorldToScreenPoint(mTargetTrans.position);

                    Vector3 screenPos = new Vector3(mMousePos.x, mMousePos.y, mScreenSpace.z);
                    mOffset = mTargetTrans.position - mCamera.ScreenToWorldPoint(screenPos);

                    mInputData.target         = mTargetTrans;
                    mInputData.screenPosition = mMousePos;
                    onClickDown?.Invoke(mInputData);
                }
                if (!mIsEnter)
                {
                    mIsEnter = true;
                    onEnter?.Invoke(mHitTarget);
                }
                onStay?.Invoke(mHitTarget);
                if ((mPrevTarget != default) && (mPrevTarget != mHitTarget))
                {
                    InteractExit();
                }
                mPrevTarget = mHitTarget;
            }
            else
            {
                InteractExit();
                mHitTarget = default;

                mInputData.screenPosition = mMousePos;
                mInputData.target         = default;
                if (Input.GetMouseButtonDown(0))
                {
                    mMouseDownPos = Input.mousePosition;
                    onClickNoneDown?.Invoke(mInputData);
                }
                if (Input.GetMouseButton(0))
                {
                    mMouseDis = Vector3.Distance(mMouseDownPos, mMousePos);
                    if (mIsDrag == false && mMouseDis < ClickRange)
                    {
                        onClickNoneStay?.Invoke(mInputData);
                    }
                    else
                    {
                        if (!mIsDragStart)
                        {
                            onDragStart?.Invoke(mInputData);
                            mIsDragStart = true;
                        }
                        mIsDrag     = true;
                        mCurDraging = default;
                        onDrag?.Invoke(mInputData);
                    }
                }
                if (Input.GetMouseButtonUp(0))
                {
                    mMouseDis = Vector3.Distance(mMouseDownPos, mMousePos);
                    if (mMouseDis < ClickRange && !mIsDrag)
                    {
                        onClickNoneUp?.Invoke(mInputData);
                    }
                    else
                    {
                        mInputData.target = mCurDraging;
                        onDragEnd?.Invoke(mInputData);
                    }
                    mIsDrag      = false;
                    mTargetTrans = default;
                    mCurDraging  = default;
                }
            }

            if (mTargetTrans == default && !IsNullStart)
            {
                return;
            }

            if (Input.GetMouseButton(0))
            {
                if (Physics.Raycast(mInputRay, out mInputHit, float.MaxValue, LayerMask))
                {
                    onClick?.Invoke(mInputHit.transform.gameObject);
                }
                mMouseDis = Vector3.Distance(mMouseDownPos, mMousePos);
                if (mIsDrag == false && mMouseDis < ClickRange)
                {
                    onClickStay?.Invoke(mTargetTrans.gameObject);
                }
                else
                {
                    if (!mIsDragStart)
                    {
                        onDragStart?.Invoke(mInputData);
                        mIsDragStart = true;
                    }
                    mIsDrag = true;
                    Vector3 curScreenSpace = new Vector3(mMousePos.x, mMousePos.y, mScreenSpace.z);
                    Vector3 curPosition    = mCamera.ScreenToWorldPoint(curScreenSpace) + mOffset;

                    mInputData.target         = mTargetTrans;
                    mInputData.position       = curPosition;
                    mInputData.screenPosition = curScreenSpace;
                    mCurDraging = mTargetTrans;
                    onDrag?.Invoke(mInputData);
                }
            }
            if (Input.GetMouseButtonUp(0))
            {
                mMouseDis = Vector3.Distance(mMouseDownPos, mMousePos);
                if (mInputData != default)
                {
                    mInputData.target = mTargetTrans;
                }
                if (mMouseDis < ClickRange && !mIsDrag)
                {
                    onClickUp?.Invoke(mInputData);
                }
                else
                {
                    onDragEnd?.Invoke(mInputData);
                }
                mIsDrag      = false;
                mTargetTrans = default;
                mCurDraging  = default;
            }
        }