private void Move(bool shuffling) { MoveCubeCommand command = null; if (Mathf.Abs(_mouseDirection.x) > Mathf.Abs(_mouseDirection.y)) { // X is the same for all the sides if (_targetCubeLayer != Consts.TOP_OF_CUBE_LAYER && _targetCubeLayer != Consts.BOTTOM_OF_CUBE_LAYER) { var axis = _mouseDirection.x < 0 ? Vector3.up : Vector3.down; command = new MoveCubeCommand(_selectedCube.XSelection, axis, shuffling); } // Top and bottom have different X else { command = HandleTopAndBottomXRotation(shuffling); } } else { // Y needs to be handled on a side by side basis Vector3 axis; switch (_targetCubeLayer) { case Consts.FRONT_OF_CUBE_LAYER: axis = _mouseDirection.y < 0 ? Vector3.right : Vector3.left; command = new MoveCubeCommand(_selectedCube.YSelection, axis, shuffling); break; case Consts.RIGHT_OF_CUBE_LAYER: axis = _mouseDirection.y < 0 ? Vector3.back : Vector3.forward; command = new MoveCubeCommand(_selectedCube.ZSelection, axis, shuffling); break; case Consts.TOP_OF_CUBE_LAYER: case Consts.BOTTOM_OF_CUBE_LAYER: command = HandleTopAndBottomYRotation(shuffling); break; case Consts.LEFT_OF_CUBE_LAYER: axis = _mouseDirection.y < 0 ? Vector3.forward : Vector3.back; command = new MoveCubeCommand(_selectedCube.ZSelection, axis, shuffling); break; case Consts.BACK_OF_CUBE_LAYER: axis = _mouseDirection.y < 0 ? Vector3.left : Vector3.right; command = new MoveCubeCommand(_selectedCube.YSelection, axis, shuffling); break; default: break; } } if (command != null) { _commandManager.Move(command); } }
private static LinkedList <ICommand> BuildCommandListFromString(string commandString) { LinkedList <ICommand> list = new LinkedList <ICommand>(); string[] commands = commandString.Split(','); foreach (var command in commands) { var mcc = MoveCubeCommand.BuildFromString(command); if (mcc != null) { list.AddLast(mcc); } } return(list); }
public static MoveCubeCommand BuildFromString(string command) { MoveCubeCommand temp = null; string[] vars = command.Split(Delimter); if (vars.Length == 3) { var trigger = TriggerManager.StringToTrigger.ContainsKey(vars[0]) ? TriggerManager.StringToTrigger[vars[0]] : TriggerManager.GetEmptyTrigger(); var shuffling = vars[1].Equals("1"); var direction = _stringToDirection.ContainsKey(vars[2]) ? _stringToDirection[vars[2]] : Vector3.zero; temp = new MoveCubeCommand(trigger, direction, shuffling); } return(temp); }
private MoveCubeCommand HandleTopAndBottomYRotation(bool shuffling) { MoveCubeCommand command = null; if (_targetCubeLayer != Consts.TOP_OF_CUBE_LAYER && _targetCubeLayer != Consts.BOTTOM_OF_CUBE_LAYER) { return(command); } var cameraPosition = Camera.main.transform.position; var cubePosition = Vector3.forward; var angle = Vector3.Angle(cubePosition, cameraPosition.normalized); Vector3 axis; if (_targetCubeLayer == Consts.TOP_OF_CUBE_LAYER) { // Rotating from the front if (angle < Consts.FRONT_OF_CUBE_ANGLE) { axis = _mouseDirection.y < 0 ? Vector3.right : Vector3.left; command = new MoveCubeCommand(_selectedCube.YSelection, axis, shuffling); } // Rotating from the side else if (angle < Consts.SIDE_OF_CUBE_ANGLE) { // Left side if ((cubePosition.x - cameraPosition.x) > 0) { axis = _mouseDirection.y < 0 ? Vector3.forward : Vector3.back; command = new MoveCubeCommand(_selectedCube.ZSelection, axis, shuffling); } // Right side else { axis = _mouseDirection.y < 0 ? Vector3.back : Vector3.forward; command = new MoveCubeCommand(_selectedCube.ZSelection, axis, shuffling); } } // Rotating from the back else { axis = _mouseDirection.y < 0 ? Vector3.left : Vector3.right; command = new MoveCubeCommand(_selectedCube.YSelection, axis, shuffling); } } else if (_targetCubeLayer == Consts.BOTTOM_OF_CUBE_LAYER) { // Rotating from the front if (angle < Consts.FRONT_OF_CUBE_ANGLE) { axis = _mouseDirection.y < 0 ? Vector3.right : Vector3.left; command = new MoveCubeCommand(_selectedCube.YSelection, axis, shuffling); } // Rotating from the side else if (angle < Consts.SIDE_OF_CUBE_ANGLE) { // Left side if ((cubePosition.x - cameraPosition.x) > 0) { axis = _mouseDirection.y < 0 ? Vector3.forward : Vector3.back; command = new MoveCubeCommand(_selectedCube.ZSelection, axis, shuffling); } // Right side else { axis = _mouseDirection.y < 0 ? Vector3.back : Vector3.forward; command = new MoveCubeCommand(_selectedCube.ZSelection, axis, shuffling); } } // Rotating from the back else { axis = _mouseDirection.y < 0 ? Vector3.left : Vector3.right; command = new MoveCubeCommand(_selectedCube.YSelection, axis, shuffling); } } return(command); }