private void SelectMiddleTile(bool isMiddleTile, int k, int j, int f) { if (isMiddleTile) { // Used to center the board based on the middle tile. Tile.Tile middleTile = _boardTiles[k, j, f]; if (!middleTile) { _boardTiles[k, j, f] = _tileCreator.CreateTile(new Vector3(k, j, f), true, TileCreator.TileTypes.Single, true); } middleTile = _boardTiles[k, j, f]; if (middleTile.Type == TileCreator.TileTypes.DummyH) { _middleTile = _boardTiles[k - 1, j, f]; } else if (middleTile.Type == TileCreator.TileTypes.DummyV) { _middleTile = _boardTiles[k, j - 1, f]; } else { _middleTile = _boardTiles[k, j, f]; } } }
private void CenterCameraOnBoard() { Transform cameraTransform = mainCamera.transform; Vector3 boardPosition = boardGameObject.position; cameraTransform.position = new Vector3(boardPosition.x, boardPosition.y, cameraTransform.position.z); mainCamera.transform.LookAt(boardGameObject, Vector3.forward); int boardSizeY = (int)_boardCreator.BoardSize.y; Tile.Tile t = _boardCreator.MiddleTile; Rect tileRect = t.GetComponent <RectTransform>().rect; Vector3 tilePos = t.transform.position; float newBoardPosX = tilePos.x; float newBoardPosY = tilePos.y + (boardSizeY % 2 == 0 ? tileRect.height / 2 : 0); boardGameObject.position = new Vector3(-newBoardPosX, -newBoardPosY, boardPosition.z); int fov = (int)fovForHeight.x; int boardHeight = (int)fovForHeight.y; int newFov = fov - (fov - boardSizeY * fov / boardHeight) / 2; mainCamera.fieldOfView = newFov + fovGap; _boardCreator.RemoveMiddleTile(); backgroundAdjuster.AdjustBackground(); }
private void GetNeighbours(Vector3 index, out Tile.Tile top, out Tile.Tile right, out Tile.Tile left) { Tile.Tile[,,] boardTiles = _boardCreator.BoardTiles; Vector3 boardSize = _boardCreator.BoardSize; index.ToInts(out int x, out int y, out int floor); top = null; right = null; left = null; if (floor < (int)boardSize.z - 1) { top = boardTiles[x, y, floor + 1]; } if (x > 0) { left = boardTiles[x - 1, y, floor]; } if (x < (int)boardSize.x - 1) { right = boardTiles[x + 1, y, floor]; } }
public bool CanBeSelected(Tile.Tile tile) { Vector3 index = tile.Index; GetNeighbours(index, out Tile.Tile top, out Tile.Tile right, out Tile.Tile left); if (!top && (!right || !left || right.Type == TileCreator.TileTypes.DummyH)) { return(true); } return(false); }
private void FillByFloor(GameObject[] floors) { foreach (GameObject f in floors) { List <Tile.Tile> tiles = new List <Tile.Tile>(); List <GameObject> children = f.GetActiveChildren(); foreach (GameObject c in children) { Tile.Tile tile = c.GetComponent <Tile.Tile>(); if (tile.Type == TileCreator.TileTypes.Single || tile.Type == TileCreator.TileTypes.DoubleH || tile.Type == TileCreator.TileTypes.DoubleV) { tiles.Add(tile); } } FillData(tiles); } }
private void Update() { if (Input.GetMouseButtonDown(0)) { Ray ray = mainCamera.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out RaycastHit hit)) { Tile.Tile tile = hit.collider.GetComponent <Tile.Tile>(); if (_boardMatcher.CanBeSelected(tile)) { SelectTile(tile); } else { // If the tile cannot be selected, the wrong match animation should be played _selectedTiles.Add(tile); UnselectTiles(); } } } }
// 초기화 public void Initialize() { // 타일 초기화 imageIniter.SetSize(height, width); imageIniter.TileInitialize(); tileArray = new Tile.Tile[height, width]; int ind = 0; for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { Tile.Tile targetTile = (imageIniter.tileArray[i, j] as Transform).GetComponent <Tile.Tile>(); tileArray[i, j] = targetTile; targetTile.Initialize(j, i, tileSpriteIndArr[ind++]); } } }
private void SelectTile(Tile.Tile tile) { if (_selectedTiles.Count == matchNumber && !_selectedTiles.Contains(tile)) { UnselectTiles(false); } if (!_selectedTiles.Contains(tile)) { _selectedTiles.Add(tile); tile.Selected(true); } else { _selectedTiles.Remove(tile); tile.Selected(false); } if (_selectedTiles.Count == matchNumber) { MatchTiles(); } }