private void GenerateApples() { mAppleArray = new UIItemApple[x, y]; for (int _y = 0; _y < y; _y++) { for (int _x = 0; _x < x; _x++) { UIItemApple itemApple = null; applePool.Spawn(ref itemApple, trStage); itemApple.SetIndex(new Index(_x, _y)) .SetName($"Apple[{_x}, {_y}]") .SetNumber(Random.Range(1, 10)) .SetSize(new Vector2(mCellSize, mCellSize)) .SetLocalPosition(new Vector2(_x + 0.5f, -_y - 0.5f) * mSpace - offSet) .SetLocalRotation(Quaternion.identity); mAppleArray[_x, _y] = itemApple; } } }
private void ActivateGravityFall(List <UIItemApple> terminatedApples, Action finishCallback /*사과가 다 내려온 후에 검사 시작*/) { var orderedAppleList = terminatedApples.ToList(); orderedAppleList.Sort((apple1, apple2) => { if (apple1.index.y < apple2.index.y) { return(-1); } else if (apple1.index.y > apple2.index.y) { return(1); } else { if (apple1.index.x < apple2.index.x) { return(-1); } else { return(1); } } }); var firstApple = orderedAppleList[0]; var lastApple = orderedAppleList[terminatedApples.Count - 1]; int xAxisLength = Mathf.Abs(firstApple.index.x - lastApple.index.x) + 1; int yAxisLength = Mathf.Abs(firstApple.index.y - lastApple.index.y) + 1; var x = 0; var y = 0; orderedAppleList.ForEach(apple => { UIItemApple itemApple = null; applePool.Spawn(ref itemApple, trStage); var index = apple.index; for (int _y = index.y - yAxisLength; _y >= 0; _y--) { var targetApple = mAppleArray[index.x, _y]; if (!aboutToFallAppleList.Contains(targetApple)) { aboutToFallAppleList.Add(targetApple); } } if (xAxisLength > 1 && yAxisLength > 1) { if (x % xAxisLength == 0) { y--; } x++; } else if (y > -yAxisLength) { y--; } index.y = y; itemApple.SetIndex(index) .SetNumber(Random.Range(1, 10)) .SetSize(new Vector2(mCellSize, mCellSize)) .SetLocalPosition(new Vector2(index.x + 0.5f, -index.y - 0.5f) * mSpace - offSet) .SetLocalRotation(Quaternion.identity); aboutToFallAppleList.Add(itemApple); }); aboutToFallAppleList.ForEach(apple => { var targetIndex = apple.index; targetIndex.y += yAxisLength; var targetPos = new Vector2(targetIndex.x + 0.5f, -targetIndex.y - 0.5f) * mSpace - offSet; apple.SetIndex(targetIndex) .SetName($"Apple[{targetIndex.x}, {targetIndex.y}]") .MoveToTarget(targetPos); mAppleArray[targetIndex.x, targetIndex.y] = apple; }); aboutToFallAppleList.Clear(); finishCallback(); }