private void CreateFromBoard() { int[] board = boardLogic.GetBoard(); boardLogic.PrintBoard(); for (int i = 0; i < board.Length; i++) { int y = Mathf.FloorToInt(i / width); int x = i - (y * width); int pieceType = board[i]; BoardPieceController newPiece = inactivePieces[0]; inactivePieces.RemoveAt(0); newPiece.transform.SetParent(pieceHolder); newPiece.x = x; newPiece.y = y; newPiece.gameManager = this; newPiece.SetSprite(pieceSprite[pieceType]); newPiece.gameObject.SetActive(true); newPiece.transform.localPosition = new Vector3(x * pieceWidth, y * InvertedHeight, 0); activePieces.Add(newPiece); } }
public void RefillBoard() { List <int> positionsToRefil = new List <int>(); int[] board = boardLogic.GetBoard(); for (int i = 0; i < board.Length; i++) { if (board[i] == -1) { positionsToRefil.Add(i); } } boardLogic.RefillBoard(); board = boardLogic.GetBoard(); for (int v = 0; v < positionsToRefil.Count; v++) { int i = positionsToRefil[v]; int y = Mathf.FloorToInt(i / width); int x = i - (y * width); int pieceType = board[i]; BoardPieceController newPiece = inactivePieces[0]; inactivePieces.RemoveAt(0); newPiece.transform.SetParent(pieceHolder); newPiece.x = x; newPiece.y = y; newPiece.gameManager = this; newPiece.SetSprite(pieceSprite[pieceType]); newPiece.gameObject.SetActive(true); newPiece.transform.localPosition = new Vector3(x * pieceWidth, 20, 0); newPiece.transform.localScale = new Vector3(1, 1, 1); activePieces.Add(newPiece); tweeningPiece.Add(newPiece); newPiece.ShiftDownOnFill(y * InvertedHeight); } }