Пример #1
0
    private void OnMouseDrag()
    {
        if (!MainGameLogic.IsMainGame())
        {
            return;
        }
        if (!manager.IsPerformingAction())
        {
            if (startCubeTile == null || startFace == null)
            {
                startCubeTile = manager.QueryFirstCubeTile();
                startFace     = manager.QueryMagicCubeFace();

                if (startCubeTile != null && startFace != null)
                {
                    Vector3 temp = manager.GetWorldPos();
                    if (temp != Vector3.positiveInfinity)
                    {
                        mouseDragStartPos = temp;
                    }
                }
            }

            if (startCubeTile != null && startFace != null)
            {
                Vector3 temp = manager.GetWorldPos();
                if (!float.IsInfinity(temp.x))
                {
                    currentDragPos = temp;
                }
            }
        }
    }
Пример #2
0
 private void OnApplicationQuit()
 {
     if (MainGameLogic.IsMainGame() || MainGameLogic.IsGameMenu())
     {
         if (manager != null && !manager.IsPerformingAction())
         {
             manager.Save();
         }
     }
 }
Пример #3
0
    // Update is called once per frame
    void Update()
    {
        if (!MainGameLogic.IsMainGame())
        {
            return;
        }

        if (manager != null)
        {
            manager.Update();
        }

        if (Input.GetKeyDown(KeyCode.Home))
        {
            if (MainGameLogic.IsMainGame() || MainGameLogic.IsGameMenu())
            {
                manager.Save();
            }
        }
    }
Пример #4
0
 // Update is called once per frame
 void Update()
 {
     if (!MainGameLogic.IsMainGame())
     {
         return;
     }
     if (Input.GetMouseButtonDown(0))
     {
         if (startCubeTile == null)
         {
             startCubeTile = manager.QueryFirstCubeTile();
             if (startCubeTile == null)
             {
                 if (MainGameLogic.GetMainCamera().GetComponent <CameraControl>() != null)
                 {
                     MainGameLogic.GetMainCamera().GetComponent <CameraControl>().InitRotation(transform.gameObject);
                 }
             }
             startCubeTile = null;
         }
     }
 }
Пример #5
0
    // Update is called once per frame
    void Update()
    {
        if (!MainGameLogic.IsMainGame())
        {
            return;
        }

        if (Input.touchCount == 2)
        {
            Touch touchZero = Input.GetTouch(0);
            Touch touchOne  = Input.GetTouch(1);

            Vector2 touchZeroPrevPos = touchZero.position - touchZero.deltaPosition;
            Vector2 touchOnePrevPos  = touchOne.position - touchOne.deltaPosition;

            float prevTouchDeltaMag = (touchZeroPrevPos - touchOnePrevPos).magnitude;
            float touchDeltaMag     = (touchZero.position - touchOne.position).magnitude;

            float deltaMagnitudeDiff = prevTouchDeltaMag - touchDeltaMag;

            if (deltaMagnitudeDiff < 0)
            {
                ZoomIn();
            }
            else if (deltaMagnitudeDiff > 0)
            {
                ZoomOut();
            }
        }

        if (bStartedRotation)
        {
            if (Input.GetMouseButtonUp(0))
            {
                Reset();
            }
        }
        if (bStartedRotation)
        {
            if (Input.touchCount == 2)
            {
                Reset();
            }

            Vector3 difference = startMousePos - Input.mousePosition;
            difference     = new Vector3(-difference.y, difference.x, 0);
            distanceMoved += Vector3.Distance(currentMousePos, Input.mousePosition);
            distanceMoved  = (startMousePos.x - Input.mousePosition.x) + (startMousePos.y - Input.mousePosition.y);
            if (distanceMoved > easeInDistance)
            {
                distanceMoved = easeInDistance;
            }
            else if (distanceMoved < -easeInDistance)
            {
                distanceMoved = -easeInDistance;
            }
            //Debug.Log(distanceMoved);

            currentMousePos = Input.mousePosition;

            float delta = 0.0f;
            if (Math.Abs(distanceMoved) < easeInDistance)
            {
                delta = Math.Abs(distanceMoved) / easeInDistance;
                delta = easeInCurve.Evaluate(delta);
            }
            else
            {
                delta = 1.0f;
            }
            float actualCameraMoveSpeed = delta * cameraSpeed;

            if (!bLockedAxis)
            {
                if (Math.Abs(difference.x) > easeInDistance / 4)
                {
                    bRotateX    = true;
                    bLockedAxis = true;
                }
                if (Math.Abs(difference.y) > easeInDistance / 4)
                {
                    bRotateY    = true;
                    bLockedAxis = true;
                }
            }

            if (bRotateX)
            {
                if (difference.x > 0)
                {
                    transform.RotateAround(rotationTarget.transform.position, -transform.right, Time.deltaTime * actualCameraMoveSpeed);
                }
                else
                {
                    transform.RotateAround(rotationTarget.transform.position, transform.right, Time.deltaTime * actualCameraMoveSpeed);
                }
            }
            else if (bRotateY)
            {
                if (difference.y > 0)
                {
                    transform.RotateAround(rotationTarget.transform.position, -transform.up, Time.deltaTime * actualCameraMoveSpeed);
                }
                else
                {
                    transform.RotateAround(rotationTarget.transform.position, transform.up, Time.deltaTime * actualCameraMoveSpeed);
                }
            }
        }
        else
        {
            float scroll = Input.GetAxis("Mouse ScrollWheel");
            if (scroll > 0f)
            {
                // scroll up
                ZoomIn();
            }
            else if (scroll < 0f)
            {
                // scroll down
                ZoomOut();
            }
        }
    }
Пример #6
0
    private void OnMouseUp()
    {
        if (!MainGameLogic.IsMainGame())
        {
            return;
        }
        if (startCubeTile != null && startFace != null && !float.IsInfinity(currentDragPos.x))
        {
            //Debug.Log(mouseDragStartPos + "             " + currentDragPos);
            Vector3 dragResult = -mouseDragStartPos + currentDragPos;
            if (Mathf.Abs(dragResult.x) > deltaDistanceToSwipe || Mathf.Abs(dragResult.y) > deltaDistanceToSwipe || Mathf.Abs(dragResult.z) > deltaDistanceToSwipe)
            {
                switch (manager.GetWhichSide(startFace))
                {
                case MagicCubeManager.MagicCubeSide.PosX:
                    if (Mathf.Abs(dragResult.z) > Mathf.Abs(dragResult.y))
                    {
                        if (dragResult.z > 0)
                        {
                            currentDragDirection = SwipeDragDirection.RIGHT;
                        }
                        else
                        {
                            currentDragDirection = SwipeDragDirection.LEFT;
                        }
                    }
                    else
                    {
                        if (dragResult.y > 0)
                        {
                            currentDragDirection = SwipeDragDirection.UP;
                        }
                        else
                        {
                            currentDragDirection = SwipeDragDirection.DOWN;
                        }
                    }
                    break;

                case MagicCubeManager.MagicCubeSide.NegX:
                    if (Mathf.Abs(dragResult.z) > Mathf.Abs(dragResult.y))
                    {
                        if (dragResult.z > 0)
                        {
                            currentDragDirection = SwipeDragDirection.LEFT;
                        }
                        else
                        {
                            currentDragDirection = SwipeDragDirection.RIGHT;
                        }
                    }
                    else
                    {
                        if (dragResult.y > 0)
                        {
                            currentDragDirection = SwipeDragDirection.DOWN;
                        }
                        else
                        {
                            currentDragDirection = SwipeDragDirection.UP;
                        }
                    }
                    break;

                case MagicCubeManager.MagicCubeSide.PosY:
                    if (Mathf.Abs(dragResult.z) > Mathf.Abs(dragResult.x))
                    {
                        if (dragResult.z > 0)
                        {
                            currentDragDirection = SwipeDragDirection.LEFT;
                        }
                        else
                        {
                            currentDragDirection = SwipeDragDirection.RIGHT;
                        }
                    }
                    else
                    {
                        if (dragResult.x > 0)
                        {
                            currentDragDirection = SwipeDragDirection.DOWN;
                        }
                        else
                        {
                            currentDragDirection = SwipeDragDirection.UP;
                        }
                    }
                    break;

                case MagicCubeManager.MagicCubeSide.NegY:
                    if (Mathf.Abs(dragResult.z) > Mathf.Abs(dragResult.x))
                    {
                        if (dragResult.z > 0)
                        {
                            currentDragDirection = SwipeDragDirection.RIGHT;
                        }
                        else
                        {
                            currentDragDirection = SwipeDragDirection.LEFT;
                        }
                    }
                    else
                    {
                        if (dragResult.x > 0)
                        {
                            currentDragDirection = SwipeDragDirection.UP;
                        }
                        else
                        {
                            currentDragDirection = SwipeDragDirection.DOWN;
                        }
                    }
                    break;

                case MagicCubeManager.MagicCubeSide.PosZ:
                    if (Mathf.Abs(dragResult.x) > Mathf.Abs(dragResult.y))
                    {
                        if (dragResult.x > 0)
                        {
                            currentDragDirection = SwipeDragDirection.LEFT;
                        }
                        else
                        {
                            currentDragDirection = SwipeDragDirection.RIGHT;
                        }
                    }
                    else
                    {
                        if (dragResult.y > 0)
                        {
                            currentDragDirection = SwipeDragDirection.DOWN;
                        }
                        else
                        {
                            currentDragDirection = SwipeDragDirection.UP;
                        }
                    }
                    break;

                case MagicCubeManager.MagicCubeSide.NegZ:
                    if (Mathf.Abs(dragResult.x) > Mathf.Abs(dragResult.y))
                    {
                        if (dragResult.x > 0)
                        {
                            currentDragDirection = SwipeDragDirection.RIGHT;
                        }
                        else
                        {
                            currentDragDirection = SwipeDragDirection.LEFT;
                        }
                    }
                    else
                    {
                        if (dragResult.y > 0)
                        {
                            currentDragDirection = SwipeDragDirection.UP;
                        }
                        else
                        {
                            currentDragDirection = SwipeDragDirection.DOWN;
                        }
                    }
                    break;

                default:
                    break;
                }
            }

            if (!manager.IsPerformingAction())
            {
                manager.QuerySliceRotation(startCubeTile, startFace, currentDragDirection);
            }
        }


        startCubeTile        = null;
        startFace            = null;
        mouseDragStartPos    = Vector3.negativeInfinity;
        currentDragPos       = Vector3.positiveInfinity;
        currentDragDirection = SwipeDragDirection.NONE;
    }