IEnumerator PuzzleDownMove(GameObject puzzle, float distance, float time, UnityAction afterAnimAction) { Vector3 finalPos = puzzle.transform.position; puzzle.transform.position = puzzle.transform.position + Vector3.up * distance; puzzle.SetActive(true); Vector3 originPos = puzzle.transform.position; Vector3 moveVec = finalPos - originPos; Vector3 normMoveVec = moveVec.normalized; float speed = distance / time; while (time > 0) { time -= Time.deltaTime; puzzle.transform.position = puzzle.transform.position + normMoveVec * speed * Time.deltaTime; yield return(null); } puzzle.transform.position = finalPos; // Debug.Log("finalPos:" + finalPos + " " + Camera.main.WorldToScreenPoint(finalPos)); puzzle.GetComponent <PuzzleItemUI>().PlaySettleAnim(); // sparkParticleEffect.transform.position = puzzle.transform.position; // sparkParticleEffect.Play(); DragController.VibrateFeedbackIntern(); afterAnimAction(); }
public void StopSettleAnim() { GetComponent <Animator>().enabled = false; DragController.VibrateFeedbackIntern(); generalPanelUI.CheckOver(); }
public void OnEndDrag(PointerEventData pointerEventData, PuzzleItemUI puzzleItemUI, GeneralPanelUI generalPanelUI) { if (gameOverFlag) { return; } if (puzzleItemUI.puzzleItemData.Plockstate) { return; } if (!puzzleItemUI.DraggedState) { return; } if (firstDragPointerID != pointerEventData.pointerId)//限制手指pointerId不同的不可被放置,可用于限制只能单指操作 { return; } miniMapController.RefreshFlag = true; //拖动结束后,满足一定条件时拼图可以被插进面板,否则移除生成的拼图(隐藏显示) PuzzleItemData puzzleItemData = puzzleItemUI.puzzleItemData; Debug.Log("End Drag At:" + pointerEventData.position); puzzleItemUI.cloneForMove.SetActive(false); int gridIndex = -1; int[] blankLayout = null; int interactRet = generalPanelUI.InteractWithPuzzle(puzzleItemUI.cloneForMove.GetComponent <PuzzleItemUI>(), out gridIndex, out blankLayout); puzzleItemData.PanelGridIndex = gridIndex; generalPanelUI.ShowPreCheckResult(2); //FINISH:进行操作记录,interactRet为0时,进行填充记录或位置移动记录;interactRet为3时,进行删除记录(操作历史记录的实现写于GeneralPanelUI中) if (interactRet == 0)//如果拼图在满足填充条件的位置 { //把拼图插入 generalPanelUI.InsertPuzzle(puzzleItemUI.gameObject); } else if (interactRet == 1 || interactRet == 2) //如果拼图在不满足填充条件以及不在删除区的其他位置 { if (!puzzleItemData.NotSettleFlag) //如果被开始拖的拼图已经放置了 { puzzleItemData.PanelGridIndex = puzzleItemData.LastPanelGridIndex; generalPanelUI.InsertPuzzle(puzzleItemUI.gameObject, false); } Debug.Log("not fit " + interactRet); } else if (interactRet == 3)//如果拼图在删除区 { //删除 if (!puzzleItemData.NotSettleFlag) { Debug.Log("删除拼图"); puzzleItemData.PanelGridIndex = puzzleItemData.LastPanelGridIndex; generalPanelUI.RemovePuzzle(puzzleItemUI.gameObject); } generalPanelUI.deleteParticleEffect.Play(); DragController.VibrateFeedbackIntern(); } //FINISH:deleteArea缩小为1 generalPanelUI.OnDeleteAreaFlag = false; StartCoroutine(generalPanelUI.DeleteAreaLinearScaleDown()); // generalPanelUI.deleteArea.transform.localScale = Vector3.one; puzzleItemUI.DraggedState = false; generalDragFlag = false; //TODO:deleteArea置為透明 generalPanelUI.SetDeleteAreaTransparent(true); }