/// <summary> /// /// </summary> /// <param name="b"></param> /// <param name="index"></param> private void MoveBlockAtIndex(GameObject b, int index) { print("SetColumIndex MoveBlockAtIndex: " + b.GetComponent <Block>().color + " " + index); int currentBlockIndex = this.sameRowBlocks.IndexOf(b); print(currentBlockIndex); this.sameRowBlocks.RemoveAt(currentBlockIndex); this.sameRowBlocks.Insert(index, draggingBlock); print("SetColumIndex MoveBlockAtIndex after: " + BlocksUtil.LogList(this.sameRowBlocks)); int startIndex = Mathf.Min(index, currentBlockIndex); int endIndex = Mathf.Max(index, currentBlockIndex); for (int iB = startIndex; iB <= endIndex; iB++) { Block block = this.sameRowBlocks[iB]?.GetComponent <Block>(); //avoid dragging block if (this.sameRowBlocks[iB] != b) { if (block != null) { block.SetColumIndex(iB); } else { //GameObject blockAtTheBottom = this.EnablePhysicsForBlocksAtColumnIndex(iB, b.GetComponent<RectTransform>().position.y); //if (blockAtTheBottom) //{ // print("blockAtTheBottom: " + blockAtTheBottom.GetComponent<Block>().GetColumnIndexes()[0] + " " + blockAtTheBottom.GetComponent<Block>().color); // //Insert the falling block to the row (iB should be equal to blockAtTheBottom.GetComponent<Block>().GetColumnIndex() // this.sameRowBlocks[blockAtTheBottom.GetComponent<Block>().GetColumnIndexes()[0]] = blockAtTheBottom; // string s = ""; // for (int iB2 = 0; iB2 < this.sameRowBlocks.Count; iB2++) // { // s += (this.sameRowBlocks[iB2] != null ? this.sameRowBlocks[iB2].GetComponent<Block>().color.ToString() : "___") + " "; // } // print("Big Total Row is: " + s); //} } } } }
/// <summary> /// /// </summary> /// <param name="columnIndex"></param> /// <param name="positionY"></param> /// <returns>Returns the block at the bottom</returns> private GameObject EnablePhysicsForBlocksAtColumnIndex(int columnIndex, float positionY) { List <GameObject> blocks = this.GetBlocksOnTop(columnIndex, positionY); print("EnablePhysicsForBlocksAtColumnIndex:" + BlocksUtil.LogList(blocks)); //get toppest block from the column and wait for the block to finish to fall down, then InvalidateBlock //as some blocks might finish the motion after the draggingBlock finish its own one. if (blocks.Count > 0) { blocks.Last().GetComponent <PhysicsBlock>().OnPhysicsComplete += OnTopBlockPhysicsComplete; } for (int iB = 0; iB < blocks.Count; iB++) { blocks[iB].GetComponent <PhysicsBlock>().enablePhysics = true; } // can be null when moving block on the top row return(blocks.Count > 0 ? blocks[0] : null); }