IEnumerator SpawnDotCoroutine(int iRowNumber, int iColumnNumber) { //TODO: Remove the hard code values later grid[iRowNumber, iColumnNumber] = Instantiate(prefab, new Vector3(iColumnNumber * seperationX + -2f, 10f, 0), Quaternion.identity, canvasreference); Dots temp = grid[iRowNumber, iColumnNumber].GetComponent <Dots>(); temp.gameObject.name = "Dot: " + iRowNumber + " " + iColumnNumber; StartCoroutine(temp.AnimatePosition( new Vector3(iColumnNumber * seperationX + -2f, 10f, 0f), new Vector3(iColumnNumber * seperationX + -2f, iRowNumber * seperationY - 3.5f, 0f), 0.3f)); allDots.Add(temp); temp.RowNumber = iRowNumber; temp.ColumnNumber = iColumnNumber; yield return(null); }
public void CheckStatus() { dotsRemovedInColumn = new int[6]; if (isSquare) { connectedDotsList.Clear(); foreach (var d in grid.allDots) { if (d.DotType == connectDotsListType) { connectedDotsList.Add(d.gameObject); d.isAlreadyConnected = true; } } isSquare = false; } foreach (GameObject g in connectedDotsList) { dotsRemovedInColumn[g.GetComponent <Dots>().ColumnNumber]++; } for (int i = 0; i < grid.columnSize; i++) { //if there has been no change in dots in that specific column, we ignore that column if (dotsRemovedInColumn[i] == 0) { continue; } GetSpecificDots(i, (dot) => { //we do not need to calclulate under dots for first row if (dot.RowNumber != 0 && !dot.isAlreadyConnected) { int difference = GetConnectedDotsUnderConnectedDot(dot); dot.SetNewCoordinates((dot.RowNumber - difference), i); dot.gameObject.name = "Dot: " + dot.RowNumber + " " + dot.ColumnNumber; Vector3 targetPosition = new Vector3(dot.ColumnNumber * grid.seperationX - 2f, dot.RowNumber * grid.seperationY - 3.5f, 0); StartCoroutine(dot.AnimatePosition(dot.transform.position, targetPosition, 0.1f)); } }); } for (int i = 0; i < 6; i++) { int removedCount = dotsRemovedInColumn[i]; for (int j = 0; j < removedCount; j++) { int row = grid.rowSize - (removedCount - j); int lastRowIndex = connectedDotsList.Count - 1; Dots dot = connectedDotsList[lastRowIndex].GetComponent <Dots>(); connectedDotsList.RemoveAt(lastRowIndex); dot.RecycleDot(row, i, grid.seperationX, grid.seperationY); dot.ResetDot(row, i); StartCoroutine(dot.AnimatePosition(dot.transform.position, new Vector3(dot.ColumnNumber * grid.seperationX - 2f, dot.RowNumber * grid.seperationY - 3.5f, 0), 0.1f)); } } connectedDotsList.Clear(); }