/// <summary> /// Detect swipe type in a movement /// </summary> eSwipeType DetectSwipeType(Vector2 theMovement) { eSwipeType aType = eSwipeType.None; if (theMovement.x > itsMinSwipeDistance) { aType = eSwipeType.Right; } else if (theMovement.x < -itsMinSwipeDistance) { aType = eSwipeType.Left; } else if (theMovement.y > itsMinSwipeDistance) { aType = eSwipeType.Up; } else if (theMovement.y < -itsMinSwipeDistance) { aType = eSwipeType.Down; } return(aType); }
public SwipeArgs(int theAreaID,Vector2 theDelta,eSwipeType theType) { itsAreaID = theAreaID; itsDelta = theDelta; itsType = theType; }
/// <summary> /// Check for swipe movement /// </summary> void CheckSwipeGestures() { if (EventSwipe == null) { return; } #if UNITY_EDITOR || UNITY_STANDALONE || UNITY_WEBPLAYER if (itsEmulateTouchWithMouse) { if (Input.GetMouseButtonDown(0)) { // init sum on new touch itsSwipeSumByFingerID[0] = Vector2.zero; itsSwipeAlreadyDetected[0] = false; } else if (Input.GetMouseButtonUp(0) || !itsSwipeWaitForTouchRelease) { if (itsSwipeAlreadyDetected.ContainsKey(0)) { if (!itsSwipeAlreadyDetected[0]) { // detect swipe on touch end eSwipeType aType = DetectSwipeType(itsSwipeSumByFingerID[0]); if (aType != eSwipeType.None) { // don't send swipe events again if already sent for this gesture itsSwipeAlreadyDetected[0] = true; if (itsFingerToAreaID.ContainsKey(0)) { OnEventSwipe(new SwipeArgs(itsFingerToAreaID[0], itsSwipeSumByFingerID[0], aType)); } else { OnEventSwipe(new SwipeArgs(AreaIDFullScreen, itsSwipeSumByFingerID[0], aType)); } // init sum on new touch itsSwipeSumByFingerID[0] = Vector2.zero; } } } } if (Input.GetMouseButton(0)) { // else sum delta itsSwipeSumByFingerID[0] += (itsMousePosition - itsMousePositionOld); } } #endif for (int i = 0; i < Input.touchCount; i++) { Touch aTouch = Input.GetTouch(i); if (aTouch.phase == TouchPhase.Began) { // init sum on new touch itsSwipeSumByFingerID[aTouch.fingerId] = Vector2.zero; itsSwipeAlreadyDetected[aTouch.fingerId] = false; } else if ((aTouch.phase == TouchPhase.Ended) || !itsSwipeWaitForTouchRelease) { if (!itsSwipeAlreadyDetected[aTouch.fingerId]) { // detect swipe on touch end eSwipeType aType = DetectSwipeType(itsSwipeSumByFingerID[aTouch.fingerId]); if (aType != eSwipeType.None) { // don't send swipe events again if already sent for this gesture itsSwipeAlreadyDetected[aTouch.fingerId] = true; if (itsFingerToAreaID.ContainsKey(aTouch.fingerId)) { OnEventSwipe(new SwipeArgs(itsFingerToAreaID[aTouch.fingerId], itsSwipeSumByFingerID[aTouch.fingerId], aType)); } else { OnEventSwipe(new SwipeArgs(AreaIDFullScreen, itsSwipeSumByFingerID[aTouch.fingerId], aType)); } // init sum on new touch itsSwipeSumByFingerID[aTouch.fingerId] = Vector2.zero; } } } { // else sum delta itsSwipeSumByFingerID[aTouch.fingerId] += aTouch.deltaPosition; } } }
public SwipeArgs(int theAreaID, Vector2 theDelta, eSwipeType theType) { itsAreaID = theAreaID; itsDelta = theDelta; itsType = theType; }