Пример #1
0
    void OnGUI()
    {
        if (Event.current.type == EventType.mouseDown)
        {
            times      = 0.0f;
            lastPos    = Input.mousePosition;            //Event.current.mousePosition;
            currentPos = Input.mousePosition;            //Event.current.mousePosition;
        }
        if (Event.current.type == EventType.MouseDrag)
        {
            if (currSlide != slideEnum.nullslide)
            {
                return;
            }
            currentPos = Input.mousePosition;
            times     += Time.deltaTime;
            if (times > offsetTime)
            {
                MoveTo();
                times   = 0.0f;
                lastPos = currentPos;
            }
        }

        if (Event.current.type == EventType.MouseUp)
        {
            currSlide = slideEnum.nullslide;
        }
    }
Пример #2
0
    void MoveTo()
    {
        if (cubeMoveList.Count > 0)
        {
            return;
        }

        float absX = Mathf.Abs(currentPos.x - lastPos.x);
        float absY = Mathf.Abs(currentPos.y - lastPos.y);

        if (absX - absY > 0)
        {
            if (absX < 15)
            {
                return;
            }
            // left
            if (currentPos.x < lastPos.x)
            {
                if (currSlide == slideEnum.left)
                {
                    return;
                }

                MoveByCube(slideEnum.left);
                currSlide = slideEnum.left;
            }
            //right
            if (currentPos.x > lastPos.x)
            {
                if (currSlide == slideEnum.right)
                {
                    return;
                }

                MoveByCube(slideEnum.right);
                currSlide = slideEnum.right;
            }
        }
        else
        {
            if (absY < 15)
            {
                return;
            }
            //up
            if (currentPos.y > lastPos.y)
            {
                if (currSlide == slideEnum.up)
                {
                    return;
                }

                MoveByCube(slideEnum.up);
                currSlide = slideEnum.up;
            }
            //down
            if (currentPos.y < lastPos.y)
            {
                if (currSlide == slideEnum.up)
                {
                    return;
                }

                MoveByCube(slideEnum.down);
                currSlide = slideEnum.down;
            }
        }
    }
Пример #3
0
    void MoveByCube(slideEnum slideType)
    {
        if (slideType == slideEnum.nullslide)
        {
            return;
        }

        Ray        ray = Camera.main.ScreenPointToRay(lastPos);
        RaycastHit hitRay;

        if (!Physics.Raycast(ray, out hitRay))
        {
            return;
        }
        foreach (GameObject cubeObj in cubeDictMap_)
        {
            if (slideType == slideEnum.left)
            {
                float lastPosWorldY = GetLastPosWorldY();
                if (lastPosWorldY < 3.2f)
                {
                    if (Mathf.Abs(cubeObj.transform.position.y - hitRay.collider.transform.position.y) > 1e-5)
                    {
                        continue;
                    }
                    AddListToMove(cubeObj, Vector3.up);
                }
                else
                {
                    if (currentPos.y > lastPos.y)
                    {
                        if (Mathf.Abs(cubeObj.transform.position.z - hitRay.collider.transform.position.z) > 1e-5)
                        {
                            continue;
                        }
                        AddListToMove(cubeObj, Vector3.back);
                    }
                    else
                    {
                        if (Mathf.Abs(cubeObj.transform.position.x - hitRay.collider.transform.position.x) > 1e-5)
                        {
                            continue;
                        }
                        AddListToMove(cubeObj, Vector3.right);
                    }
                }
            }
            if (slideType == slideEnum.right)
            {
                float lastPosWorldY = GetLastPosWorldY();
                if (lastPosWorldY < 3.2f)
                {
                    if (Mathf.Abs(cubeObj.transform.position.y - hitRay.collider.transform.position.y) > 1e-5)
                    {
                        continue;
                    }
                    AddListToMove(cubeObj, Vector3.down);
                }
                else
                {
                    if (currentPos.y < lastPos.y)
                    {
                        if (Mathf.Abs(cubeObj.transform.position.z - hitRay.collider.transform.position.z) > 1e-5)
                        {
                            continue;
                        }
                        AddListToMove(cubeObj, Vector3.forward);
                    }

                    else
                    {
                        if (Mathf.Abs(cubeObj.transform.position.x - hitRay.collider.transform.position.x) > 1e-5)
                        {
                            continue;
                        }
                        AddListToMove(cubeObj, Vector3.left);
                    }
                }
            }
            if (slideType == slideEnum.up)
            {
                // which 6 face of cube
                if (lastPos.x < 315)
                {
                    if (Mathf.Abs(cubeObj.transform.position.x - hitRay.collider.transform.position.x) > 1e-5)
                    {
                        continue;
                    }
                    AddListToMove(cubeObj, Vector3.left);
                }
                else
                {
                    if (Mathf.Abs(cubeObj.transform.position.z - hitRay.collider.transform.position.z) > 1e-5)
                    {
                        continue;
                    }
                    AddListToMove(cubeObj, Vector3.back);
                }
            }
            if (slideType == slideEnum.down)
            {
                // which 6 face of cube
                if (lastPos.x < 315)
                {
                    if (Mathf.Abs(cubeObj.transform.position.x - hitRay.collider.transform.position.x) > 1e-5)
                    {
                        continue;
                    }
                    AddListToMove(cubeObj, Vector3.right);
                }
                else
                {
                    if (Mathf.Abs(cubeObj.transform.position.z - hitRay.collider.transform.position.z) > 1e-5)
                    {
                        continue;
                    }
                    AddListToMove(cubeObj, Vector3.forward);
                }
            }
        }
    }