/// <summary> /// Is Recursive Method /// Find match end blocks and swap,move /// Call OnContainer() and every frame /// </summary> /// <returns></returns> IEnumerator matchDownCoroutine() { bool changed = false; for (int x = 0; x < width; ++x) { List <Block> stack = new List <Block>(); for (int y = 0; y < height; ++y) { Block block = blockList[x, y]; if (block._State == Block.State.MATCH_END) { if (!stack.Contains(block)) { stack.Add(block); block._LocalPosition = new Vector2(x, height); } } else if (stack.Count != 0) { swap(x, y, x, y - stack.Count); block.Move(x, y - stack.Count); changed = true; } } for (int i = 0; i < stack.Count; ++i) { Block block = blockList[x, height - i - 1]; block.On(); block.SetRandomColor(); block.Move(x, height - i - 1); changed = true; } } if (changed) { checkCanMatch(); } yield return(null); StartCoroutine(matchDownCoroutine()); }
/// <summary> /// match blocks move /// </summary> void matchDown() { for (int x = 0; x < width; ++x) { List <Block> stack = new List <Block>(); for (int y = 0; y < height; ++y) { Block block = blockList[x, y]; if (block._State == Block.State.MATCH_END) { if (!stack.Contains(block)) { stack.Add(block); block._LocalPosition = new Vector2(x, height); } } else if (stack.Count != 0) { swap(x, y, x, y - stack.Count); block.Move(x, y - stack.Count); } } for (int i = 0; i < stack.Count; ++i) { Block block = blockList[x, height - i - 1]; block.On(); block.SetRandomColor(); block.Move(x, height - i - 1); } } }