///////////////////////////////////////////// public bool Swipe(Cell _selectedCell, InputController.SwipeDirection _direction) { Cell c = GetCellByDirection(_selectedCell, _direction); bool canSwipe = false; if (_selectedCell != null && c != null) { if (_selectedCell.GetChildrens().Count > 0 && c.GetChildrens().Count > 0) { Vector3 newPos = new Vector3(c.GetWorldPosition().x, c.GetWorldPosition().y + c.GetChildrens().Count *Cell.ingredientOffset, c.GetWorldPosition().z); canSwipe = true; _selectedCell.MoveObjects(newPos, _direction, () => { for (int i = _selectedCell.GetChildrens().Count - 1; i >= 0; i--) { c.AddChild(_selectedCell.GetChildrens()[i]); } if (GameManager.I.GetGameController().CurrentGameType == GameController.GameType.Numbers) { c.CheckCombinations(); } _selectedCell.ClearIngredients(); GameManager.I.GetGameController().CheckVictory(); }); } } return(canSwipe); }
internal void MoveObjects(Vector3 newPosition, InputController.SwipeDirection _direction, TweenCallback callBack) { TweenCallback margeCallback = () => { callBack(); ObjectToMove.transform.localPosition = Vector3.zero; ObjectToRotate.ResetRotation(); InputController.CellInMotion = false; }; float ingredients = GetChildrens().Count; ObjectToRotate.transform.localPosition = new Vector3(ObjectToMove.transform.localPosition.x, ingredients / 2 * 0.1f, ObjectToMove.transform.localPosition.z); for (int i = 0; i < GetChildrens().Count; i++) { GetChildrens()[i].transform.parent = ObjectToRotate.transform; } ObjectToMove.transform.DOJump(newPosition, 0.5f, 1, 0.4f).OnComplete(margeCallback); ObjectToRotate.SetRotation(_direction); }
///////////////////////////////////////////// /// <summary> /// Return the cell next to the start cell given by direction /// </summary> /// <param name="_startCell"></param> /// <param name="_direction"></param> /// <returns></returns> Cell GetCellByDirection(Cell _startCell, InputController.SwipeDirection _direction) { Cell value = null; switch (_direction) { case InputController.SwipeDirection.Left: if (_startCell.GetGridPosition().x > 0) { value = cells[_startCell.GetGridPosition().x - 1, _startCell.GetGridPosition().y]; } break; case InputController.SwipeDirection.Right: if (_startCell.GetGridPosition().x < gridDimension_x - 1) { value = cells[_startCell.GetGridPosition().x + 1, _startCell.GetGridPosition().y]; } break; case InputController.SwipeDirection.Up: if (_startCell.GetGridPosition().y < gridDimension_y - 1) { value = cells[_startCell.GetGridPosition().x, _startCell.GetGridPosition().y + 1]; } break; case InputController.SwipeDirection.Down: if (_startCell.GetGridPosition().y > 0) { value = cells[_startCell.GetGridPosition().x, _startCell.GetGridPosition().y - 1]; } break; default: break; } return(value); }