예제 #1
0
    //单指的情况下所实现的操作
    public void TouchOneFinger()
    {
        if (Input.touchCount == 1)
        {
            // DebugLog.DebugLogInfo("touch_1: " + Input.GetTouch(0) + "  touch_2 : " + pos + "distance" + Vector2.Distance(Input.GetTouch(0).position, pos) + "time" + touchOper.time);
            timeCur += Time.deltaTime;

            if (Input.GetTouch(0).phase == TouchPhase.Began)
            {
                mousePos = Input.GetTouch(0).position;
            }
            if (Input.GetTouch(0).phase == TouchPhase.Stationary)
            {
                //长按进入光标模式
                if (!isTouchFunBan && timeCur >= Interaction.timeCurMode && !touchOper.isRotate)
                {
                    if (cursor != null)
                    {
                        isCurMode = true;
                        cursor.transform.position = Input.mousePosition;
                        cursor.SetActive(true);
                        cursorMode = cursor.GetComponent <MyCursorMode>();
                    }
                }
            }

            if (Input.GetTouch(0).phase == TouchPhase.Moved)
            {
                if (Vector2.Distance(Input.GetTouch(0).position, mousePos) < 5)
                {
                    //触摸手指移动一定范围内也判断为单击选择
                }

                if (!isCurMode)
                {
                    touchOper.isRotate = true;
                    touchOper.x       += Input.GetTouch(0).deltaPosition.x;
                    touchOper.y       -= Input.GetTouch(0).deltaPosition.y *Interaction.rotateTouchY *Interaction.AnimationRotateY;
                    touchOper.RotateOpera(touchOper.x, touchOper.y);
                }
            }

            if (Input.GetTouch(0).phase == TouchPhase.Ended)
            {
                timeCur = 0;
                if (isCurMode)
                {
                    cursor.SetActive(false);
                    cursorMode.Select();
                    isCurMode = false;
                }
                if (touchOper.isRotate)
                {
                    touchOper.isRotate = false;
                }
            }
        }
    }
예제 #2
0
    //拖拽鼠标
    public void MouseDrag()
    {
        //判断当前模式,普通模式下实现如下内容
        if (Input.GetMouseButtonDown(0))
        {
            mousePos = Input.mousePosition;
        }

        //拖拽鼠标左键,实现旋转
        if (Input.GetMouseButton(0) && (PPTGlobal.PPTEnv != PPTGlobal.PPTEnvironment.PPTPlayer || !Input.GetMouseButton(1)))
        {
#if UNITY_EDITOR
            //鼠标按下开始计时
            timeCur += Time.deltaTime;

            //Debug.Log(touchOper.time);
            // Vector2 pos = Input.mousePosition;

            //鼠标光标模式

            if (!isMouseBan && !isTouchFunBan && timeCur >= Interaction.timeCurMode && Vector2.Distance(Input.mousePosition, mousePos) < 1)
            {
                if (cursor != null)
                {
                    isCurMode = true;

                    cursor.transform.position = Input.mousePosition;
                    cursor.SetActive(true);
                    cursorMode = cursor.GetComponent <MyCursorMode>();
                }
            }
#elif UNITY_ANDROID
#endif
            if (!isCurMode)
            {
                touchOper.isRotate = true;

                // WindowsCursorHandling.POINT p;
                // WindowsCursorHandling.GetCursorPos(out p);
                // float factorX = 40.0f * (p.x - WindowsCursorHandling.centerX) / (float)Screen.width;
                // float factorY = -40.0f * (p.y - WindowsCursorHandling.centerY) / (float)Screen.width;
                // WindowsCursorHandling.CenterCursor();
                // touchOper.x += factorX * Interaction.rotateSpeedX;
                // touchOper.y -= factorY * Interaction.rotateSpeedY * Interaction.AnimationRotateY;

                touchOper.x += Input.GetAxis("Mouse X") * Interaction.rotateSpeedX;
                touchOper.y -= Input.GetAxis("Mouse Y") * Interaction.rotateSpeedY * Interaction.AnimationRotateY;

                touchOper.RotateOpera(touchOper.x, touchOper.y);
            }
        }
        else
        {
            timeCur = 0;
            if (isCurMode)
            {
                cursor.SetActive(false);

                cursorMode.Select();
                isCurMode = false;
            }
            if (touchOper.isRotate)
            {
                touchOper.isRotate = false;
            }
        }

        //拖拽鼠标右键,实现平移
        //if (Input.GetMouseButtonDown(1))
        //{
        //    Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        //    RaycastHit hit;
        //    isModel = Physics.Raycast(ray, out hit);
        //}
        if (Input.GetMouseButton(1) && (PPTGlobal.PPTEnv != PPTGlobal.PPTEnvironment.PPTPlayer || Input.GetMouseButton(0)))
        {
            //if (isModel)
            //{
            if (touchOper.lastTransPos.Count == 0)
            {
                touchOper.lastTransPos.Add(touchOper.orthCamera.ScreenToWorldPoint(Input.mousePosition));
            }
            else
            {
                Vector3 tmp = touchOper.orthCamera.ScreenToWorldPoint(Input.mousePosition);
                touchOper.TranslateOpera(touchOper.lastTransPos[0], tmp);
                touchOper.lastTransPos[0] = tmp;
            }
            //}
        }
        else
        {
            touchOper.lastTransPos.Clear();
        }
        if (Input.GetMouseButtonUp(1))
        {
            //isModel = false;
        }
    }