Exemple #1
0
        private void SwitchFaces(RubikFace from, RubikFaceType to, int indexTo)
        {
            from.Index = indexTo;
            from.Type  = to;

            _faces[to][indexTo] = from;
        }
Exemple #2
0
 private void ClearSelectedCube()
 {
     if (Input.GetMouseButtonUp(0))
     {
         _currentRubikFace        = null;
         CameraController.CanMove = true;
     }
 }
Exemple #3
0
 private void DetectSelectedCubeOnMouseUp()
 {
     if (Input.GetMouseButtonUp(0))
     {
         RaycastHit hit;
         var        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
         if (Physics.Raycast(ray, out hit))
         {
             if (hit.transform != null)
             {
                 var subcube = hit.transform.gameObject.GetComponent <RubikFace>();
                 if (subcube != null)
                 {
                     _currentRubikFace = subcube;
                 }
             }
         }
     }
 }
Exemple #4
0
 private void DetectSelectedCube()
 {
     if (_currentRubikFace == null)
     {
         if (Input.GetMouseButtonDown(0))
         {
             RaycastHit hit;
             var        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
             if (Physics.Raycast(ray, out hit))
             {
                 if (hit.transform != null)
                 {
                     var subcube = hit.transform.gameObject.GetComponent <RubikFace>();
                     if (subcube != null)
                     {
                         _currentRubikFace        = subcube;
                         _initialPoint            = Input.mousePosition;
                         CameraController.CanMove = false;
                     }
                 }
             }
         }
     }
 }
Exemple #5
0
 public RubikMove GetStartingFaceData(RubikFace face)
 {
     return(_moves[face.Type][face.Index]);
 }
Exemple #6
0
        protected void LateUpdate()
        {
            if (!CanMove)
            {
                return;
            }
            if (EnableSwiping)
            {
                DeactivateAllFaceSelections();
            }

            DetectNearestFace();
            CheckBackFaceVisibility();

            if (EnableSwiping)
            {
                DetectSelectedCube();

                if (_currentRubikFace != null)
                {
                    var position = Input.mousePosition;
                    var distance = Vector3.Distance(_initialPoint, position);

                    if (distance >= MovesActivationThreshold)
                    {
                        var directionX = position.x - _initialPoint.x;
                        var directionY = position.y - _initialPoint.y;

                        var cubeSelectedMove = Cube.GetStartingFaceData(_currentRubikFace);

                        bool isHorizontal = Mathf.Abs(directionX) > Mathf.Abs(directionY);
                        if (_nearestFace == RubikFaceType.Right || _nearestFace == RubikFaceType.Left)
                        {
                            if (_currentRubikFace.Type == RubikFaceType.Top ||
                                _currentRubikFace.Type == RubikFaceType.Bottom)
                            {
                                isHorizontal = !isHorizontal;
                            }
                        }

                        RubikFaceType selectedFace = RubikFaceType.None;
                        bool          clockwise;

                        if (isHorizontal)
                        {
                            clockwise = (directionX >= 0);
                            bool isPositive = directionY >= 0;
                            if (isPositive)
                            {
                                selectedFace = cubeSelectedMove.HorizontalMove;
                            }
                            else
                            {
                                selectedFace = cubeSelectedMove.HorizontalMove;
                            }

                            if (cubeSelectedMove.InvertHorizontalMove)
                            {
                                clockwise = !clockwise;
                            }
                        }
                        else
                        {
                            clockwise = (directionY >= 0);
                            bool isPositive = directionX >= 0;
                            if (isPositive)
                            {
                                selectedFace = cubeSelectedMove.VerticalMove;
                            }
                            else
                            {
                                selectedFace = cubeSelectedMove.VerticalMove;
                            }

                            if (cubeSelectedMove.InvertVerticalMove)
                            {
                                clockwise = !clockwise;
                            }
                        }

                        /*if (selectedFace == RubikFaceType.Top || selectedFace == RubikFaceType.Bottom)
                         * {
                         *  if (_isBackFaceVisible)
                         *      clockwise = !clockwise;
                         * }*/

                        Debug.Log("Face: " + selectedFace + " - " + clockwise);
                        Cube.Rotate(selectedFace, clockwise);

                        _currentRubikFace = null;
                    }
                }

                ClearSelectedCube();
            }
            else
            {
                DetectSelectedCubeOnMouseUp();
                ActivateFaceSelection();
            }
        }