private void YAxisStateUpdated(GestureRecognizer r) { if (TransformToScale == null) { return; } else if (r.State == GestureRecognizerState.Began) { // if moved too much left/right, reset gesture float horizUnits = DeviceInfo.PixelsToUnits(r.DistanceX); if (horizUnits > 0.15f) { r.Reset(); } else { // reset x axis gesture, we only want one scale direction at a time XAxisScaleGesture.Reset(); } } else if (r.State == GestureRecognizerState.Executing) { Vector3 scale = TransformToScale.localScale; scale.y *= YAxisScaleGesture.ScaleMultiplierY; TransformToScale.localScale = scale; } }
private void XAxisStateUpdated(GestureRecognizer r) { if (TransformToScale == null) { return; } else if (r.State == GestureRecognizerState.Began) { // if moved too much up/down, reset gesture float vertUnits = DeviceInfo.PixelsToUnits(r.DistanceY); if (vertUnits > 0.15f) { r.Reset(); } else { // reset y axis gesture, we only want one scale direction at a time YAxisScaleGesture.Reset(); } } else if (r.State == GestureRecognizerState.Executing) { Vector3 scale = TransformToScale.localScale; scale.x *= XAxisScaleGesture.ScaleMultiplierX; TransformToScale.localScale = scale; } }
private void Pan_StateUpdated(GestureRecognizer gesture) { switch (gesture.State) { case GestureRecognizerState.Began: { // check if we hit something, if so start dragging it otherwise reset the gesture Vector2 worldPos = Camera.main.ScreenToWorldPoint(new Vector3(gesture.FocusX, gesture.FocusY, 0.0f)); Collider2D[] hits = Physics2D.OverlapCircleAll(worldPos, 1.0f); bool foundOne = false; foreach (Collider2D hit in hits) { if (CanDrag(hit.gameObject)) { // store the drag state along with an offset to reposition relative to the touch point and object center DragState state = new DragState { Gesture = gesture, GameObject = hit.gameObject, Offset = (Vector2)hit.transform.position - worldPos }; draggingObjects[hit.gameObject] = state; draggingObjectsGesture[gesture] = state; foundOne = true; break; } } if (!foundOne) { gesture.Reset(); } } break; case GestureRecognizerState.Executing: { DragState state; if (draggingObjectsGesture.TryGetValue(gesture, out state)) { // position the object relative to the touch location and offset Vector2 worldPos = Camera.main.ScreenToWorldPoint(new Vector3(gesture.FocusX, gesture.FocusY, 0.0f)); state.GameObject.transform.position = (Vector3)(worldPos + state.Offset); } } break; case GestureRecognizerState.Ended: { // finish dragging, remove state DragState state; if (draggingObjectsGesture.TryGetValue(gesture, out state)) { draggingObjectsGesture.Remove(gesture); draggingObjects.Remove(state.GameObject); } } break; } }
private void ScaleGestureUpdated(GestureRecognizer gesture, ICollection <GestureTouch> touches) { if (gesture.State == GestureRecognizerState.Began && !GestureIntersectsSprite(gesture, ScaleIcon)) { gesture.Reset(); } else if (gesture.State == GestureRecognizerState.Executing) { Earth.transform.localScale *= scaleGesture.ScaleMultiplier; } }
private void RotationGestureUpdated(GestureRecognizer gesture, ICollection <GestureTouch> touches) { if (gesture.State == GestureRecognizerState.Began && !GestureIntersectsSprite(gesture, RotateIcon)) { gesture.Reset(); } else if (gesture.State == GestureRecognizerState.Executing) { Earth.transform.Rotate(0.0f, 0.0f, rotationGesture.RotationDegreesDelta); } }
private void LongPressGestureStateUpdated(GestureRecognizer gesture) { if (gesture.State == GestureRecognizerState.Began) { Debug.Log("Long tap on fingers pan ar component script began"); if (LongPressGestureBegan != null) { LongPressGestureBegan.Invoke(this); } gesture.Reset(); } }
public static void StartOrResetGesture(GestureRecognizer r, bool bringToFront, Camera camera, GameObject obj, SpriteRenderer spriteRenderer) { if (r.State == GestureRecognizerState.Began) { if (GestureIntersectsObject(r, camera, obj)) { if (bringToFront && spriteRenderer != null) { spriteRenderer.sortingOrder = 1000; } } else { r.Reset(); } } }
public void ImageGestureExecuted(GestureRecognizer gesture) { ImageGestureRecognizer imgGesture = gesture as ImageGestureRecognizer; if (gesture.State == GestureRecognizerState.Ended) { if (imgGesture.MatchedGestureImage == null) { Debug.Log("Image gesture failed to match."); } else { Debug.Log("Image gesture matched!"); } gesture.Reset(); } }
private void LongPressGestureStateUpdated(GestureRecognizer gesture) { if (gesture.State == GestureRecognizerState.Began) { Debug.Log("Long tap on fingers pan ar component script began"); SelectCurrentTarget(gesture.FocusX, gesture.FocusY); PushGesture(gesture); if (LongPressGestureBegan != null) { LongPressGestureBegan.Invoke(this); } gesture.Reset(); } else if (gesture.State == GestureRecognizerState.Ended) { PopGesture(gesture); } }
public static GameObject StartOrResetGesture(GestureRecognizer r, bool bringToFront, Camera camera, GameObject obj, SpriteRenderer spriteRenderer, GestureRecognizerComponentScriptBase.GestureObjectMode mode) { GameObject result = null; if (r.State == GestureRecognizerState.Began) { if ((result = GestureIntersectsObject(r, camera, obj, mode)) != null) { if (bringToFront && spriteRenderer != null) { spriteRenderer.sortingOrder = 1000; } } else { r.Reset(); } } return(result); }
private void LetterGestureUpdated(GestureRecognizer gesture) { Debug.Log("Pan state " + gesture.State); if (gesture.State == GestureRecognizerState.Began) { PointerEventData p = new PointerEventData(EventSystem.current); p.position = new Vector2(gesture.FocusX, gesture.FocusY); raycast.Clear(); EventSystem.current.RaycastAll(p, raycast); foreach (RaycastResult result in raycast) { if (result.gameObject.name.IndexOf("LetterPrefab", System.StringComparison.OrdinalIgnoreCase) >= 0) { // we have a letter! Vector2 dragPos = FingersUtility.ScreenToCanvasPoint(canvas, new Vector2(gesture.FocusX, gesture.FocusY)); draggingLetter = result.gameObject.transform; dragOffset = (Vector2)draggingLetter.position - dragPos; break; } } if (draggingLetter == null) { gesture.Reset(); } } else if (gesture.State == GestureRecognizerState.Executing) { Vector2 dragPos = FingersUtility.ScreenToCanvasPoint(canvas, new Vector2(gesture.FocusX, gesture.FocusY)); Vector3 pos = draggingLetter.transform.position; // don't mess with the z pos.x = dragPos.x + dragOffset.x; pos.y = dragPos.y + dragOffset.y; draggingLetter.transform.position = pos; } else if (gesture.State == GestureRecognizerState.Ended) { draggingLetter = null; } }
public static void StartOrResetGesture(GestureRecognizer r, bool bringToFront, Camera camera, GameObject obj, SpriteRenderer spriteRenderer) { if (r.State == GestureRecognizerState.Began) { if (GestureIntersectsObject(r, camera, obj)) { AppController.FingersGestureInProgress = 1; // ################ OWENEDIT ################ if (bringToFront) { if (spriteRenderer != null) { spriteRenderer.sortingOrder = 1000; } } } else { r.Reset(); AppController.FingersGestureInProgress = 0; // ################ OWENEDIT ################ } } }
private void LetterGestureUpdated(GestureRecognizer gesture) { //Debug.Log("Pan state " + gesture.State); if (gesture.State == GestureRecognizerState.Began) { PointerEventData p = new PointerEventData(EventSystem.current); p.position = new Vector2(gesture.FocusX, gesture.FocusY); raycast.Clear(); EventSystem.current.RaycastAll(p, raycast); foreach (RaycastResult result in raycast) { if (result.gameObject.name.IndexOf("BlockDraggable", System.StringComparison.OrdinalIgnoreCase) >= 0) { print("DRAGGABLE FOUND BOUNDARIES"); // we have a letter! this.boundaries = this.blockDragManager.NotifyDraggingBlockStart(result.gameObject); //print("BOUNDARIES:" + this.boundaries[0]); //print("BOUNDARIES:" + this.boundaries[1]); Vector2 dragPos = FingersUtility.ScreenToCanvasPoint(canvas, new Vector2(gesture.FocusX, gesture.FocusY)); draggingLetter = result.gameObject.transform; dragOffset = (Vector2)draggingLetter.position - dragPos; break; } } if (draggingLetter == null) { gesture.Reset(); } } else if (gesture.State == GestureRecognizerState.Executing) { this.boundaries = this.blockDragManager.CalculateBlockBoundaries(this.draggingLetter.gameObject); Vector2 dragPos = FingersUtility.ScreenToCanvasPoint(canvas, new Vector2(gesture.FocusX, gesture.FocusY)); Vector3 pos = draggingLetter.transform.position; // don't mess with the z float newPosition = dragPos.x + dragOffset.x; float containerX = this.container.GetComponent <RectTransform>().position.x; if (newPosition >= this.boundaries[0] + containerX && newPosition <= this.boundaries[1] + containerX) { this.lastDelta = newPosition - pos.x; pos.x = newPosition; //pos.y = dragPos.y + dragOffset.y; draggingLetter.transform.position = pos; } else { //print("DRAGGABLE BOUNDARIES BLOCK"); //print("BOUNDARIES:" + this.boundaries[0]); //print("BOUNDARIES:" + this.boundaries[1]); } } else if (gesture.State == GestureRecognizerState.Ended) { this.blockDragManager.NotifyDraggingBlockEnd(draggingLetter.gameObject, this.lastDelta); GameObject gameObject = draggingLetter.gameObject; draggingLetter = null; } }
private void LongPress_StateUpdated(GestureRecognizer gesture) { if (gesture.State == GestureRecognizerState.Began) { // raycast out for the card - this let's us have multiple cards Vector3 gestureWorldPos = Camera.main.ScreenToWorldPoint(new Vector3(gesture.FocusX, gesture.FocusY, 0.0f)); Collider2D hit = Physics2D.OverlapPoint(gestureWorldPos); // see if we found a card if (hit != null && !swipedCards.Contains(hit.transform)) { // set the draggingCard variable to the card transform, this let's us move it around in the "Executing" state Debug.Log("Found card, beginning drag..."); draggingCard = hit.GetComponent <Transform>(); draggingCard.localScale = Vector3.one * 1.2f; } else { // no card, reset the gesture and they must lift the touch and try again Debug.Log("No card under gesture, resetting..."); gesture.Reset(); } // apply an offset from the center of the card so it drags from wherever it was touched on the card dragOffset = draggingCard.position - Camera.main.ScreenToWorldPoint(new Vector3(gesture.FocusX, gesture.FocusY, 0.0f)); dragOffset.z = 0.0f; } else if (gesture.State == GestureRecognizerState.Executing) { // if the gesture velocity is high enough, fling the card off screen float speed = longPress.Distance(gesture.VelocityX, gesture.VelocityY); if (speed >= SwipeAwaySpeed) { // convert the screen units velocity to world velocity and apply to the card draggingCard.localScale = Vector3.one; Vector3 worldVelocityZero = Camera.main.ScreenToWorldPoint(Vector3.zero); Vector3 worldVelocityGesture = Camera.main.ScreenToWorldPoint(new Vector3(gesture.VelocityX, gesture.VelocityY, 0.0f)); Vector3 worldVelocity = (worldVelocityGesture - worldVelocityZero) * 0.5f; worldVelocity.z = 0.0f; Rigidbody2D rb = draggingCard.GetComponent <Rigidbody2D>(); rb.velocity = worldVelocity; // apply some random spin for fun rb.angularVelocity = Random.Range(-1000.0f, 1000.0f); // don't allow the card to be re-dragged while it flings away swipedCards.Add(draggingCard); draggingCard = null; // reset gesture, the swipe away finishes the gesture gesture.Reset(); Debug.LogFormat("Swiping card away at world velocity {0} (screen velocity units {1})", (Vector2)worldVelocity, new Vector2(gesture.VelocityX, gesture.VelocityY)); } else { // drag the card Vector3 dragCurrent = Camera.main.ScreenToWorldPoint(new Vector3(gesture.FocusX, gesture.FocusY, 0.0f)); dragCurrent.z = draggingCard.transform.position.z; draggingCard.position = dragCurrent + dragOffset; } } else { // if not begin or execute state, null out the dragging card if (draggingCard != null) { draggingCard.localScale = Vector3.one; } draggingCard = null; } }