/// <summary> /// 执行方块掉落动画 /// </summary> public static void gridDrop() { //[0]定义每帧掉落距离和横移距离 dropY = moveX = mInterval * 0.1f; //[1]遍历所有列,完成方块掉落 for (int h = 18; h > 0; h--) { for (int i = 0; i < mGameData.vertical; i++) { if (mGridListManager[i].Count >= h) { checkIndex = h - 1; //[3]判断剩余List的最后一个对象是否需要移动,每帧执行移动并修改后续需要移动的距离 if (mGridListManager[i][checkIndex].dropHeight > 0 || mGridListManager[i][checkIndex].hasMoveWidth > 0 || mGridListManager[i][checkIndex].hasDropHeight > 0 || mGridListManager[i][checkIndex].dropAfterMoveHeight > 0) { //[3.1]先进行垂直掉落 if (mGridListManager[i][checkIndex].dropHeight > dropY) { //执行掉落 mGridListManager[i][checkIndex].gridObject.GetComponent <RectTransform>().position += new Vector3(0.0f, -dropY, 0.0f); mGridListManager[i][checkIndex].dropHeight -= dropY; //若为补充方块掉落,则掉落距离超过第一个格子一半,则开始显示 if (mGridListManager[i][checkIndex].isTop && mGridListManager[i][checkIndex].gridObject.GetComponent <RectTransform>().position.y <= gridBorderY) { mGridListManager[i][checkIndex].gridObject.SetActive(true); mGridListManager[i][checkIndex].isTop = false; } //若为传送门入口方块掉落,则掉落距离超过传送门下方格子,则开始隐藏 if (mDoorDataList != null) { foreach (DoorBean doorBean in mDoorDataList) { if (doorBean.inVertical == i) { gridHideInDoor = mGridBaseListManager[i][doorBean.inHorizontal].gridBase.GetComponent <RectTransform>().position.y; if (mGridListManager[i][checkIndex].isDropInDoor && mGridListManager[i][checkIndex].gridObject.GetComponent <RectTransform>().position.y <= gridHideInDoor) { mGridListManager[i][checkIndex].gridObject.SetActive(false); mGridListManager[i][checkIndex].isDropInDoor = false; break; } } } //若为传送门出口方块掉落,则掉落距离超过传送门上方格子,则开始显示 foreach (DoorBean doorBean in mDoorDataList) { if (doorBean.outVertical == i) { gridShowOutDoor = (mGridBaseListManager[i][doorBean.outHorizontal].gridBase.GetComponent <RectTransform>().position + new Vector3(0.0f, mGridSize / 2, 0.0f)).y; if (mGridListManager[i][checkIndex].isDropOutDoor && mGridListManager[i][checkIndex].gridObject.GetComponent <RectTransform>().position.y <= gridShowOutDoor) { mGridListManager[i][checkIndex].gridObject.SetActive(true); mGridListManager[i][checkIndex].isDropOutDoor = false; break; } } } } //若为金豆荚篮子位置,则金豆荚方块中心掉落穿过篮子,则开始隐藏,并删除对象 if (mGridOfBeanPodList != null && mBasketDataList != null) { endCheckBeanPod = false; foreach (GridBean gridBean in mGridOfBeanPodList) { foreach (BasketBean basketBean in mBasketDataList) { if (gridBean.vertical == basketBean.basketVertical) { if (gridBean.gridObject.GetComponent <RectTransform>().position.y < basketBean.basket.GetComponent <RectTransform>().position.y + mGridSize * 0.4f / 2) { Destroy(gridBean.gridObject); mGridListManager[i].Remove(gridBean); mGridOfBeanPodList.Remove(gridBean); mDeleteCounts++; //更新目标板数据 GridConn.updateTargetCounts(mDeleteCounts); } endCheckBeanPod = true; break; } } if (endCheckBeanPod) { break; } } } continue; } else { mGridListManager[i][checkIndex].gridObject.GetComponent <RectTransform>().position += new Vector3(0.0f, -mGridListManager[i][checkIndex].dropHeight, 0.0f); mGridListManager[i][checkIndex].dropHeight = 0; mGridListManager[i][checkIndex].dropCounts = 0; //若为传送门入口列下移到最底部,则移除方块 isDelete = false; if (mDoorDataList != null) { foreach (DoorBean doorBean in mDoorDataList) { if (doorBean.inVertical == i) { if (mGridListManager[doorBean.inVertical][checkIndex].isDestroy) { Destroy(mGridListManager[doorBean.inVertical][checkIndex].gridObject); mGridListManager[doorBean.inVertical].RemoveAt(checkIndex); isDelete = true; break; } } } } if (isDelete) { continue; } } //[3.2]垂直掉落完后,进行横移 if (mGridListManager[i][checkIndex].moveCounts >= mGridListManager[i][checkIndex].dropHeightFromOtherCounts) { if (mGridListManager[i][checkIndex].moveCounts > 0) { if (mGridListManager[i][checkIndex].hasMoveWidth > moveX) { //往左边移动 if (mGridListManager[i][checkIndex].moveDirection == -1) { mGridListManager[i][checkIndex].gridObject.GetComponent <RectTransform>().position += new Vector3(-moveX, 0.0f, 0.0f); } //往右边移动 if (mGridListManager[i][checkIndex].moveDirection == 1) { mGridListManager[i][checkIndex].gridObject.GetComponent <RectTransform>().position += new Vector3(moveX, 0.0f, 0.0f); } mGridListManager[i][checkIndex].hasMoveWidth -= moveX; continue; } else { //往左边移动 if (mGridListManager[i][checkIndex].moveDirection == -1) { mGridListManager[i][checkIndex].gridObject.GetComponent <RectTransform>().position += new Vector3(-mGridListManager[i][checkIndex].hasMoveWidth, 0.0f, 0.0f); } //往右边移动 if (mGridListManager[i][checkIndex].moveDirection == 1) { mGridListManager[i][checkIndex].gridObject.GetComponent <RectTransform>().position += new Vector3(mGridListManager[i][checkIndex].hasMoveWidth, 0.0f, 0.0f); } if (mGridListManager[i][checkIndex].moveCounts > 0) { mGridListManager[i][checkIndex].moveCounts--; if (mGridListManager[i][checkIndex].moveCounts == 0) { mGridListManager[i][checkIndex].hasMoveWidth = 0; mGridListManager[i][checkIndex].moveHorizontal = 9; } else { mGridListManager[i][checkIndex].hasMoveWidth = mInterval; } } } } } //[3.3]横移后的掉落 if (mGridListManager[i][checkIndex].dropHeightFromOtherCounts > 0) { if (mGridListManager[i][checkIndex].hasDropHeight > dropY) { //执行掉落 mGridListManager[i][checkIndex].gridObject.GetComponent <RectTransform>().position += new Vector3(0.0f, -dropY, 0.0f); mGridListManager[i][checkIndex].hasDropHeight -= dropY; continue; } else { mGridListManager[i][checkIndex].gridObject.GetComponent <RectTransform>().position += new Vector3(0.0f, -mGridListManager[i][checkIndex].hasDropHeight, 0.0f); if (mGridListManager[i][checkIndex].dropHeightFromOtherCounts > 0) { mGridListManager[i][checkIndex].dropHeightFromOtherCounts--; if (mGridListManager[i][checkIndex].dropHeightFromOtherCounts == 0) { mGridListManager[i][checkIndex].hasDropHeight = 0; } else { mGridListManager[i][checkIndex].hasDropHeight = mInterval; } } } } //[3.4]横移掉落完毕后,若下方有空位执行的掉落 if (mGridListManager[i][checkIndex].dropAfterMoveHeight > dropY) { //执行掉落 mGridListManager[i][checkIndex].gridObject.GetComponent <RectTransform>().position += new Vector3(0.0f, -dropY, 0.0f); mGridListManager[i][checkIndex].dropAfterMoveHeight -= dropY; } else { mGridListManager[i][checkIndex].gridObject.GetComponent <RectTransform>().position += new Vector3(0.0f, -mGridListManager[i][checkIndex].dropAfterMoveHeight, 0.0f); mGridListManager[i][checkIndex].dropAfterMoveHeight = 0; } } } } } //判断是否为僵局 isCheckReset = true; for (int h = 18; h > 0; h--) { for (int i = 0; i < mGameData.vertical; i++) { if (mGridListManager[i].Count >= h) { checkIndex = h - 1; //如果还有任何需要移动的格子,则不检测僵局 if (mGridListManager[i][checkIndex].dropHeight > 0 || mGridListManager[i][checkIndex].hasMoveWidth > 0 || mGridListManager[i][checkIndex].hasDropHeight > 0 || mGridListManager[i][checkIndex].dropAfterMoveHeight > 0) { isCheckReset = false; break; } if (isCheckReset && h == 1 && i == 8) { //判断当前方块是否为僵局,方法调用位置仍需思考 GridReset.checkGameisConn(); } } } if (!isCheckReset) { break; } } }