protected void Update() { if (CustomInput.touchCount != 0 && !Match3BoardGameLogic.Instance.loseConditions.IsPaused) { touchInfo = CustomInput.GetTouch(0); // Debug.LogWarning("Touchphase: " + touchInfo.phase); float deltaMagnitude = touchInfo.deltaPosition.magnitude; // Debug.LogWarning("DELTA: " + deltaMagnitude + " " + lerpTreshold); if (interpolate && oldTouchPosition != POZ_UNASIGNED && deltaMagnitude > lerpTreshold) { float lerpAmount = lerpTreshold / deltaMagnitude; for (float lerpIndex = 0f; lerpIndex < 1; lerpIndex = Mathf.Clamp01(lerpIndex + lerpAmount)) { Vector3 lerpedPosition = Vector3.Lerp(oldTouchPosition, touchInfo.position, lerpIndex); // Debug.LogWarning("Lerped: " + lerpedPosition.ToString()); CheckBoardTouch(lerpedPosition, touchInfo); } } else { CheckBoardTouch(touchInfo.position, touchInfo); } oldTouchPosition = touchInfo.position; } }
/// <summary> /// Checks the input. Call this at every frame or just when you needed. Register to this instance's events to get notified when they happen. /// </summary> public void CheckInput() { for (int i = 0; i < CustomInput.touchCount; ++i) { CustomInput.TouchInfo touch = CustomInput.GetTouch(i); if (touch.phase == TouchPhase.Began) { if (OnTapBegan != null) { OnTapBegan(touch.position); } } else if (touch.phase == TouchPhase.Ended) { if (OnTapEnded != null) { OnTapEnded(touch.position); } if (Time.time - touch.beginTime < SWIPE_MAX_TIME) { if (OnSwipeLeftRight != null && touch.position.x - touch.beginPosition.x >= SWIPE_MIN_SCREEN * Screen.width) { OnSwipeLeftRight(touch.beginPosition, touch.position); } if (OnSwipeRightLeft != null && touch.position.x - touch.beginPosition.x <= -SWIPE_MIN_SCREEN * Screen.width) { OnSwipeRightLeft(touch.beginPosition, touch.position); } } } } }
protected void RaiseOnNewBoardPieceSelected(AbstractBoardPiece boardPiece, CustomInput.TouchInfo touchInfo) { if (OnNewBoardPieceSelected != null) { OnNewBoardPieceSelected(boardPiece, touchInfo); } }
//Coroutine for getting the input protected IEnumerator GetInput() { yield return(null); while (true) { if (CustomInput.touchCount != 0) { CustomInput.TouchInfo touch = CustomInput.GetTouch(0); if (touch.phase == TouchPhase.Ended && endPosition == Vector3.zero) { startPosition = Vector3.zero; } if (touch.phase == TouchPhase.Ended && endPosition != Vector3.zero) { touchController.StopInputController(); touchController.OnNewBoardPieceSelected -= OnNewBoardPieceSelected; OnInputReceived(); yield break; } } yield return(null); } }
protected void OnNewBoardPieceSelected(AbstractBoardPiece boardPiece, CustomInput.TouchInfo touchInfo) { if (isRunning || BoardShuffleController.Instance.IsBoardReshuffling) { return; } bool isLinked = false; AbstractBoardPiece lastSelection = null; //Cache reference to the last selection if (selectionList.Count > 0) { lastSelection = selectionList[selectionList.Count - 1]; } // if(boardPiece.GetType() != typeof(EmptyBoardPiece)) // { //Undo selection if (selectionList.Count >= 2 && selectionList[selectionList.Count - 2] == boardPiece) { RemoveSelection(selectionList.Count - 1); return; } //Check link between new and last selection if (lastSelection) { isLinked = lastSelection.IsAdjacentTo(boardPiece); } //Add current tile to the selection or start a new one if (selectionCount < maxNumberOfSelections) // && !selectionList.Contains(boardPiece) { if (!isLinked) { if (selectionList.Contains(boardPiece)) { return; } RemoveAllSelections(); } AddSelection(boardPiece); } if (selectionCount == maxNumberOfSelections || selectionList.Count == critNumberOfSelections) { touchController.StopInputController(); StartCoroutine(DoItemCoroutine()); isRunning = true; } // } }
protected void OnNewBoardPieceSelected(AbstractBoardPiece boardPiece, CustomInput.TouchInfo touchInfo) { // Debug.LogWarning("[OnNewBoardPieceSelect]"); if (BoardShuffleController.Instance.IsBoardReshuffling) { return; } if (startPosition == Vector3.zero) { startPosition = boardPiece.cachedTransform.position; } else { endPosition = boardPiece.cachedTransform.position; } }
protected void CheckBoardTouch(Vector3 position, CustomInput.TouchInfo touchInfo) { boardCoord = ConvertToBoardCoord(position); if (boardCoord.row < 0 || boardCoord.row >= Match3BoardRenderer.Instance.Board.NumRows || boardCoord.col < 0 || boardCoord.col >= Match3BoardRenderer.Instance.Board.NumColumns) { return; } CustomInput.TouchInfo modifiedTouchInfo = new CustomInput.TouchInfo(touchInfo); modifiedTouchInfo.position = position; if (prevBoardCoord != boardCoord) { boardPiece = Match3BoardRenderer.Instance.Board[boardCoord.row, boardCoord.col]; RaiseOnNewBoardPieceSelected(boardPiece, modifiedTouchInfo); prevBoardCoord = boardCoord; } }
public void OnNewBoardPieceSelected(AbstractBoardPiece boardPiece, CustomInput.TouchInfo touchInfo) { if (BoardShuffleController.Instance.IsBoardReshuffling) { return; } bool selectionSucces = false; selectedBoardPiece = boardPiece; tileToDestroy = boardPiece.Tile as Match3Tile; effectPosition = boardPiece.cachedTransform; //Decide wether this selection is icepick worthy or not if (boardPiece.Tile == null) { if (boardPiece is LayeredBoardPiece && (boardPiece as LayeredBoardPiece).NumLayers > 0) { selectionSucces = true; } } else if (!tileToDestroy.IsMoving && tileToDestroy.IsDestructible && !tileToDestroy.IsDestroying && !(tileToDestroy as NormalTile).IsFrozen()) { selectionSucces = true; } if (selectionSucces) { SoundManager.Instance.PlayOneShot("icepick_sfx"); touchController.StopInputController(); touchController.OnNewBoardPieceSelected -= OnNewBoardPieceSelected; StartItemEffects(); } }
protected void CheckBoardTouch(Vector3 position, CustomInput.TouchInfo touchInfo) { boardCoord = ConvertToBoardCoord(position); if(boardCoord.row < 0 || boardCoord.row >= Match3BoardRenderer.Instance.Board.NumRows || boardCoord.col < 0 || boardCoord.col >= Match3BoardRenderer.Instance.Board.NumColumns) { return; } CustomInput.TouchInfo modifiedTouchInfo = new CustomInput.TouchInfo(touchInfo); modifiedTouchInfo.position = position; if(prevBoardCoord != boardCoord) { boardPiece = Match3BoardRenderer.Instance.Board[boardCoord.row, boardCoord.col]; RaiseOnNewBoardPieceSelected(boardPiece, modifiedTouchInfo); prevBoardCoord = boardCoord; } }
protected void Update () { if(CustomInput.touchCount != 0 && !Match3BoardGameLogic.Instance.loseConditions.IsPaused) { touchInfo = CustomInput.GetTouch(0); // Debug.LogWarning("Touchphase: " + touchInfo.phase); float deltaMagnitude = touchInfo.deltaPosition.magnitude; // Debug.LogWarning("DELTA: " + deltaMagnitude + " " + lerpTreshold); if(interpolate && oldTouchPosition != POZ_UNASIGNED && deltaMagnitude > lerpTreshold) { float lerpAmount = lerpTreshold / deltaMagnitude; for(float lerpIndex = 0f; lerpIndex < 1; lerpIndex = Mathf.Clamp01(lerpIndex + lerpAmount)) { Vector3 lerpedPosition = Vector3.Lerp(oldTouchPosition, touchInfo.position, lerpIndex); // Debug.LogWarning("Lerped: " + lerpedPosition.ToString()); CheckBoardTouch(lerpedPosition, touchInfo); } } else { CheckBoardTouch(touchInfo.position, touchInfo); } oldTouchPosition = touchInfo.position; } }