Exemplo n.º 1
0
 void updateCubePosion(GameObject cube, CubePosion cubePosion)
 {
     if (cube == null)
     {
         log("updateCubePosion, cube is null");
         return;
     }
     cube.transform.position         = cubePosion.position;
     cube.transform.localEulerAngles = cubePosion.angle;
     cube.transform.localScale       = cubePosion.scal;
 }
Exemplo n.º 2
0
 CubeWrap focusCube(CubePosion cubePosion)
 {
     foreach (CubeWrap cubeWrap in cubesList)
     {
         if (cubeWrap.startPosion == cubePosion)
         {
             cubeWrap.focused = true;
             cubeWrap.cube.transform.localScale = cubePosion.scal * 1.1f;
             return(cubeWrap);
         }
     }
     return(null);
 }
Exemplo n.º 3
0
 void unfocusCube()
 {
     foreach (CubeWrap cubeWrap in cubesList)
     {
         if (cubeWrap.focused)
         {
             cubeWrap.focused = false;
             cubeWrap.cube.transform.localScale = cubeWrap.startPosion.scal;
             break;
         }
     }
     focusedCubeWrap   = null;
     focusedCubePosion = null;
 }
Exemplo n.º 4
0
 void updateKeyPosition(CubePosion cubePosion, GameObject gameObject)
 {
     cubePosion.position = gameObject.transform.position;
     cubePosion.angle    = gameObject.transform.localEulerAngles;
     cubePosion.scal     = gameObject.transform.localScale;
 }
Exemplo n.º 5
0
    void slideGesture()   // 滑动方法
    {
        if (Event.current.type == EventType.MouseDown)
        //判断当前手指是按下事件
        {
            touchDown      = Event.current.mousePosition;
            touchFirst     = Event.current.mousePosition;//记录开始按下的位置
            touchThird     = Event.current.mousePosition;
            slowTouchStart = Event.current.mousePosition;
            log("Gesture.............................. MouseDown   mousePosition:" + touchFirst.ToString());
            mouseDown = true;
            downtime  = Time.time;

            if (state == State.STOP)
            {
                focusedCubePosion = getTouchedCube(touchFirst);
                if (focusedCubePosion != null)
                {
                    focusedCubeWrap = focusCube(focusedCubePosion);
                }
            }
        }

        if (Event.current.type == EventType.MouseUp)
        {
            mouseDown   = false;
            longPressed = false;
            clicktime   = Time.time - downtime;
            touchUp     = Event.current.mousePosition;
            touchThird  = Event.current.mousePosition;
            float distance = touchThird.x - touchFirst.x;


            log("Gesture.............................. MouseUp   clicktime:" + clicktime + "  distance:" + distance + "  touchUp:" + touchUp);
            if (focusedCubeWrap != null && clicktime > 0.02 && clicktime < 0.2 && distance < 5 && distance > -5 && state == State.STOP)
            {
                onClick(focusedCubeWrap.cube.name);
            }
            unfocusCube();
            slowMove = false;


            if (Mathf.Abs(dragDetaDistance) > 1)
            {
                float x = dragDetaDistance;
                acce       = ACCE_MIN;
                startSpeed = Mathf.Abs(x / (clicktime * 100));
                if (x < 0) //左滑
                {
                    if (speed > 0)
                    {
                        if (state == State.RIGHT)
                        {
                            log("Gesture...........RIGHT >> LEFT ");
                            speed = 0;
                            state = State.LEFT;
                            startMove();
                        }
                        else if (state == State.LEFT)
                        {
                            speed = speed + 1;
                            log("Gesture...........left acce speed ! ");
                        }
                    }
                    else
                    {
                        state = State.LEFT;
                        log("Gesture left , startSpeed = " + startSpeed);
                        startMove();
                    }
                }
                else//右滑
                {
                    if (speed > 0)
                    {
                        if (state == State.LEFT)
                        {
                            log("Gesture...........LEFT >> RIGHT ");
                            speed = 0;
                            state = State.RIGHT;
                            startMove();
                        }
                        else if (state == State.RIGHT)
                        {
                            speed = speed + 1;
                            log("Gesture...........right acce speed ! ");
                        }
                    }
                    else
                    {
                        state = State.RIGHT;
                        log("Gesture right , startSpeed = " + startSpeed);
                        startMove();
                    }
                }
            }
        }

        if (Event.current.type == EventType.MouseDrag)
        //判断当前手指是拖动事件
        {
            if (Event.current.mousePosition.x != touchSecond.x)
            {
                dragDetaDistance = Event.current.mousePosition.x - touchSecond.x;
            }
            touchSecond = Event.current.mousePosition;
            log("Gesture........... MouseDrag  touchSecond=" + touchSecond.ToString());

            dragDetaTime = Time.time - dragTime;
            dragTime     = Time.time;

            if (slowMove == false && state != State.STOP)
            {
                speed = 0;

                /*
                 * touchFirst = touchSecond;
                 * if(state == State.RIGHT)
                 * {
                 *  touchFirst.x = touchSecond.x - moveDelta * 300;
                 * }
                 * else if (state == State.LEFT)
                 * {
                 *  touchFirst.x = touchSecond.x + moveDelta * 300;
                 * }
                 * log("Gesture........... MouseDrag  stop,  state=" + state);*/

                state = State.STOP;
                return;
            }

            slowMove = true;
            Vector2 slideDirection = touchSecond - touchFirst;
            if (slideDirection.x > 2)
            {
                state = State.RIGHT;
            }
            else if (slideDirection.x < -2)
            {
                state = State.LEFT;
            }
            else
            {
                state = State.STOP;
            }
            log("Gesture..................................... MouseDrag  slowMove=" + slowMove + "  ,state=" + state);
        }   // 滑动方法
    }