void OnEnable() { instances.Add(this); if (OnActivate == null) { OnActivate = new UnityEvent(); } if (OnDeactivate == null) { OnDeactivate = new UnityEvent(); } if (OnSwipeAnimStarted == null) { OnSwipeAnimStarted = new UnityEvent(); } if (OnSwipeAnimCompleted == null) { OnSwipeAnimCompleted = new UnityEvent(); } if (OnSwipe == null) { OnSwipe = new SwipeEvent(); } if (OnMove == null) { OnMove = new MoveEvent(); } }
public static void OnSwipeEvent(bool isSwipe) { SwipeEvent handler = OnSwipe; if (handler != null) { handler(isSwipe); } }
private void Awake() { onStartedSwipe = new SwipeEvent(); onSwiping = new SwipeEvent(); onEndedSwipe = new SwipeEvent(); basePixel = Mathf.Min(Screen.width, Screen.height); }
void Awake() { if (!Instance) { Instance = this; } OnSwipeTopEvent = new SwipeEvent(); OnSwipeDownEvent = new SwipeEvent(); OnSwipeLeftEvent = new SwipeEvent(); OnSwipeRightEvent = new SwipeEvent(); }
public bool AxisSwipeChange(SwipeEvent e) { return(((direction == Swipe.Direction.LEFT || direction == Swipe.Direction.RIGHT) && (e.gesture.CurrentDirection == Swipe.Direction.UP || e.gesture.CurrentDirection == Swipe.Direction.DOWN)) || ((direction == Swipe.Direction.UP || direction == Swipe.Direction.DOWN) && (e.gesture.CurrentDirection == Swipe.Direction.LEFT || e.gesture.CurrentDirection == Swipe.Direction.RIGHT)) || (direction == Swipe.Direction.NONE && e.gesture.CurrentDirection != Swipe.Direction.NONE)); }
protected void OnSwipe(SwipeEvent e) { if (AxisSwipeChange(e)) { float xPos = Mathf.Round(transform.position.x); float yPos = Mathf.Round(transform.position.y); transform.position = new Vector3(xPos, yPos, transform.position.z); Ink.Intensity--; if (Ink.Intensity == 0) { Ink.Intensity = 0; CurrentColorMode = ColorMode.NONE; } } direction = e.gesture.CurrentDirection; }
public void OnEndDrag(PointerEventData eventData) { Vector3 drag = (eventData.position - eventData.pressPosition).normalized; Direction direction; if (Mathf.Abs(drag.x) > Mathf.Abs(drag.y)) { direction = (drag.x > 0) ? Direction.Right : Direction.Left; } else { direction = (drag.y > 0) ? Direction.Up : Direction.Down; } Debug.Log("Dragged: " + direction); SwipeEvent.Invoke(direction); }
private void OnSwipe() { SwipeEvent?.Invoke(_touchMovement); }
/// <summary> /// Gets the inputs /// </summary> private void Update() { bool tap = false; #region Standalone Inputs if (Input.GetMouseButtonDown(0)) { tap = true; startTouch = Input.mousePosition; } else if (Input.GetMouseButtonUp(0)) { startTouch = swipeDelta = Vector2.zero; return; } if (Input.GetKeyUp(KeyCode.LeftArrow)) { SwipeEvent?.Invoke(Enums.Direction.Left); } else if (Input.GetKeyUp(KeyCode.RightArrow)) { SwipeEvent?.Invoke(Enums.Direction.Right); return; } else if (Input.GetKeyUp(KeyCode.UpArrow)) { SwipeEvent?.Invoke(Enums.Direction.Up); return; } else if (Input.GetKeyUp(KeyCode.DownArrow)) { SwipeEvent?.Invoke(Enums.Direction.Down); return; } else { if (tap) { TapEvent?.Invoke(); } } #endregion #region Mobile Inputs tap = false; if (Input.touches.Length != 0) { if (Input.touches[0].phase == TouchPhase.Began) { tap = true; startTouch = Input.mousePosition; } else if (Input.touches[0].phase == TouchPhase.Ended || Input.touches[0].phase == TouchPhase.Canceled) { startTouch = swipeDelta = Vector2.zero; } } #endregion //Calculate distance swipeDelta = Vector2.zero; if (startTouch != Vector2.zero) { //Check with mobile if (Input.touches.Length != 0) { swipeDelta = Input.touches[0].position - startTouch; } //Check with standalone else if (Input.GetMouseButton(0)) { swipeDelta = (Vector2)(Input.mousePosition) - startTouch; } } //Check if we're beyong the deadzone if (swipeDelta.magnitude > DEADZONE) { //This is a confirmed swipe float x = swipeDelta.x; float y = swipeDelta.y; if (Mathf.Abs(x) > Mathf.Abs(y)) { //Left or Right if (x < 0) {//Left SwipeEvent?.Invoke(Enums.Direction.Left); } else {//Right SwipeEvent?.Invoke(Enums.Direction.Right); } } else { //Up or Down if (y < 0) {//Down SwipeEvent?.Invoke(Enums.Direction.Down); } else {//Up SwipeEvent?.Invoke(Enums.Direction.Up); } } startTouch = swipeDelta = Vector2.zero; } else { if (tap) { TapEvent?.Invoke(); } } }
void OnSwipeEnd() { SwipeEvent?.Invoke(m_touchStartPosition, m_touchEndPosition); }