void _UpdateTouches()
    {
        int numTouches = Input.touchCount;

        for (int touchIndex = 0; touchIndex < numTouches; ++touchIndex)
        {
            Touch touch = Input.touches[touchIndex];
            if (touch.phase == TouchPhase.Began)
            {
                Debug.Log("Touch " + touch.fingerId + "Started at : " + touch.position);
                TrackedTouch newTouch = new TrackedTouch();
                newTouch.startPos   = touch.position;
                newTouch.currentPos = touch.position;
                _touches.Add(touch.fingerId, newTouch);
            }
            else if (touch.phase == TouchPhase.Canceled || touch.phase == TouchPhase.Ended)
            {
                Debug.Log("Touch " + touch.fingerId + "Ended at : " + touch.position);
                _touches.Remove(touch.fingerId);
            }
            else
            {
                TrackedTouch currentTouch;
                if (_touches.TryGetValue(touch.fingerId, out currentTouch))
                {
                    currentTouch.currentPos = touch.position;
                }
            }
        }
    }
Esempio n. 2
0
 TrackedTouch[] GetValidPartnerSwipes(TrackedTouch baseTouch, ICollection <TrackedTouch> selection, float targetDot, float maxDeviation)
 {
     return((
                from touch in selection
                where touch != baseTouch &&
                Mathf.Abs(targetDot - Vector2.Dot(baseTouch.Travel.normalized, touch.Travel.normalized)) < maxDeviation
                orderby Mathf.Abs(targetDot - Vector2.Dot(baseTouch.Travel.normalized, touch.Travel.normalized)) ascending
                select touch
                ).ToArray());
 }
Esempio n. 3
0
    void Record()
    {
        MouseRecord();

        foreach (Touch touch in Input.touches)
        {
            if (trackedTouches.ContainsKey(touch.fingerId))
            {
                if (Time.time - trackedTouches[touch.fingerId].startTime > maxDuration)
                {
                    trackedTouches.Remove(touch.fingerId);
                }
                else
                {
                    switch (touch.phase)
                    {
                    case TouchPhase.Ended:
                        TrackedTouch trackedTouch = trackedTouches[touch.fingerId];

                        if (
                            Time.time - trackedTouch.startTime < maxTapDuration &&
                            trackedTouch.NormalizedTravel.magnitude < maxTapScreenTravel
                            )
                        {
                            SendGesture(GestureType.Tap, trackedTouch.Start, trackedTouch.Travel);
                        }

                        trackedTouches.Remove(touch.fingerId);
                        break;

                    case TouchPhase.Canceled:
                        trackedTouches.Remove(touch.fingerId);
                        break;

                    case TouchPhase.Moved:
                        trackedTouches[touch.fingerId].positions.Add(touch.position);
                        break;
                    }
                }
            }
            else if (touch.phase == TouchPhase.Began)
            {
                trackedTouches[touch.fingerId] = new TrackedTouch(touch.fingerId, touch.position);
            }
        }
    }
Esempio n. 4
0
    void MouseRecord()
    {
        if (trackedTouches.ContainsKey(kMouseButtonID))
        {
            if (Time.time - trackedTouches[kMouseButtonID].startTime > maxDuration)
            {
                trackedTouches.Remove(kMouseButtonID);
            }
            else
            {
                TrackedTouch trackedTouch = trackedTouches[kMouseButtonID];

                if (Input.GetMouseButtonUp(0))             // TouchPhase.Ended
                {
                    if (trackedTouch.NormalizedTravel.magnitude < maxTapScreenTravel)
                    {
                        SendGesture(GestureType.Tap, trackedTouch.Start, trackedTouch.Travel);
                    }

                    trackedTouches.Remove(kMouseButtonID);
                }
                else if (System.Math.Abs(Input.mousePosition.x - trackedTouch.End.x) > 0.01 ||
                         System.Math.Abs(Input.mousePosition.y - trackedTouch.End.y) > 0.01)             // TouchPhase.Moved
                {
                    Vector2 position = new Vector2(Input.mousePosition.x, Input.mousePosition.y);

                    trackedTouches[kMouseButtonID].positions.Add(position);
                }
            }
        }
        else if (Input.GetMouseButtonDown(0))
        {
            Vector2 position = new Vector2(Input.mousePosition.x, Input.mousePosition.y);

            trackedTouches[kMouseButtonID] = new TrackedTouch(kMouseButtonID, position);
        }
    }
		TrackedTouch[] GetValidPartnerSwipes (TrackedTouch baseTouch, ICollection<TrackedTouch> selection, float targetDot, float maxDeviation)
		{
			return (
				from touch in selection
					where touch != baseTouch &&
						Mathf.Abs (targetDot - Vector2.Dot (baseTouch.Travel.normalized, touch.Travel.normalized)) < maxDeviation
					orderby Mathf.Abs (targetDot - Vector2.Dot (baseTouch.Travel.normalized, touch.Travel.normalized)) ascending
				select touch
			).ToArray ();
		}
Esempio n. 6
0
	        void MouseRecord ()
	        {
	            if (trackedTouches.ContainsKey(kMouseButtonID))
	            {
	                if (Time.time - trackedTouches[kMouseButtonID].startTime > maxDuration)
	                {
	                    trackedTouches.Remove(kMouseButtonID);
	                }
	                else
	                {
	                    TrackedTouch trackedTouch = trackedTouches[kMouseButtonID];
	
	                    if (Input.GetMouseButtonUp(0)) // TouchPhase.Ended
	                    {
	                        if (trackedTouch.NormalizedTravel.magnitude < maxTapScreenTravel)
	                        {
	                            SendGesture(GestureType.Tap, trackedTouch.Start, trackedTouch.Travel);
	                        }
	
	                        trackedTouches.Remove(kMouseButtonID);
	                    }
	                    else if (System.Math.Abs(Input.mousePosition.x - trackedTouch.End.x) > 0.01
	                          || System.Math.Abs(Input.mousePosition.y - trackedTouch.End.y) > 0.01) // TouchPhase.Moved
	                    {
	                        Vector2 position = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
	
	                        trackedTouches[kMouseButtonID].positions.Add(position);
	                    }
	                }
	            }
	            else if (Input.GetMouseButtonDown(0))
	            {
	                Vector2 position = new Vector2(Input.mousePosition.x, Input.mousePosition.y);
	
	                trackedTouches[kMouseButtonID] = new TrackedTouch(kMouseButtonID, position);
	            }
	        }
Esempio n. 7
0
	void _UpdateTouches()
	{
		int numTouches = Input.touchCount;
		for(int touchIndex = 0; touchIndex < numTouches; ++touchIndex)
		{
			Touch touch = Input.touches[touchIndex];
			if(touch.phase == TouchPhase.Began)
			{
				Debug.Log("Touch " + touch.fingerId + "Started at : " + touch.position);
				TrackedTouch newTouch = new TrackedTouch();
				newTouch.startPos = touch.position;
				newTouch.currentPos = touch.position;
				_touches.Add(touch.fingerId, newTouch);
			}
			else if(touch.phase == TouchPhase.Canceled || touch.phase == TouchPhase.Ended)
			{
				Debug.Log("Touch " + touch.fingerId + "Ended at : " + touch.position);
				_touches.Remove(touch.fingerId);
			}
			else
			{
				TrackedTouch currentTouch;
				if(_touches.TryGetValue(touch.fingerId, out currentTouch))
				{
					currentTouch.currentPos = touch.position;
				}
			}
		}

	}