public static Vector3 GetAveragePosition(ExGestureObject g1, ExGestureObject g2)
        {
            float xavg, yavg;

            xavg = (g1.EndPosition.x + g2.EndPosition.x) / 2;
            yavg = (g1.EndPosition.y + g2.EndPosition.y) / 2;

            return new Vector3(xavg, yavg, 0.0f);
        }
 public virtual bool OnTap(ExGestureObject g)
 {
     return false;
 }
 public virtual bool OnPinch(ExGestureObject g)
 {
     return false;
 }
 public bool Equals(ExGestureObject g)
 {
     return (g.Id == this.Id);
 }
        private void ConvertMouseToExGestureObject()
        {
            ExGestureObject mouseGesture;
              try
              {
            gestures.TryGetValue( -1, out mouseGesture );

            if ( Input.GetMouseButton( 1 ) )
            {
              Vector3 worldStartPosition = Camera.main.ScreenToWorldPoint( Input.mousePosition );
              mouseGesture = new ExGestureObject();
              mouseGesture.Initialize( ExGestureObject.GameGestureType.Pinch, worldStartPosition, worldStartPosition, Input.mousePosition, Input.mousePosition, Time.time, -1 );
              gestures.Add( mouseGesture.Id, mouseGesture );
            }
            else if ( Input.GetMouseButton( 0 ) )
            {
              Vector3 worldEndPosition = Camera.main.ScreenToWorldPoint( Input.mousePosition );
              if ( mouseGesture == null )
              {
            mouseGesture = new ExGestureObject();
            mouseGesture.Initialize( ExGestureObject.GameGestureType.Down, worldEndPosition, worldEndPosition, Input.mousePosition, Input.mousePosition, Time.time, -1 );
            gestures.Add( mouseGesture.Id, mouseGesture );
              }
              else
              {
            if ( !worldEndPosition.Equals( mouseGesture.StartPosition ) )
            {
              mouseGesture.GameGesture = ExGestureObject.GameGestureType.Drag;
            }
            else
            {
              if ( Time.time - mouseGesture.StartTime > 2 )
              {
                mouseGesture.GameGesture = ExGestureObject.GameGestureType.Hold;
              }
              else
              {
                mouseGesture.GameGesture = ExGestureObject.GameGestureType.Down;
              }
            }
            mouseGesture.EndPosition = worldEndPosition;
            mouseGesture.ScreenEnd = Input.mousePosition;
              }
            }
            else if ( Input.GetMouseButtonUp( 0 ) )
            {
              Vector3 worldEndPosition = Camera.main.ScreenToWorldPoint( Input.mousePosition );
              if ( mouseGesture.GameGesture == ExGestureObject.GameGestureType.Drag )
              {
            mouseGesture.GameGesture = ExGestureObject.GameGestureType.Pull;
            mouseGesture.EndPosition = worldEndPosition;
            mouseGesture.ScreenEnd = Input.mousePosition;
              }
              else if ( mouseGesture.GameGesture == ExGestureObject.GameGestureType.Down
                || mouseGesture.GameGesture == ExGestureObject.GameGestureType.Hold )
              {
            mouseGesture.GameGesture = ExGestureObject.GameGestureType.Tap;
            mouseGesture.EndPosition = worldEndPosition;
            mouseGesture.ScreenEnd = Input.mousePosition;
              }
            }
              }
              catch
              {
            mouseGesture = null;
              }
        }
        protected ExGestureObject ConvertToExGestureObject( Touch t )
        {
            if ( t.phase == TouchPhase.Began )
              {
            Vector3 worldStartPosition = Camera.main.ScreenToWorldPoint( t.position );
            ExGestureObject g = new ExGestureObject();
            g.Initialize( ExGestureObject.GameGestureType.Down, worldStartPosition, worldStartPosition, t.position, t.position, Time.time, t.fingerId );
            gestures.Add( g.Id, g );
            return g;
              }
              else
              {
            ExGestureObject g;
            gestures.TryGetValue( t.fingerId, out g );

            Vector3 worldEndPosition = Camera.main.ScreenToWorldPoint( t.position );
            if ( g != null )
            {
              if ( t.phase == TouchPhase.Ended )
              {
            if ( g.GameGesture == ExGestureObject.GameGestureType.Down || g.GameGesture == ExGestureObject.GameGestureType.Hold
            || g.GameGesture == ExGestureObject.GameGestureType.None )
            {
              g.GameGesture = ExGestureObject.GameGestureType.Tap;
            }
            else if ( g.GameGesture == ExGestureObject.GameGestureType.Drag )
            {
              g.GameGesture = ExGestureObject.GameGestureType.Pull;
              g.EndPosition = worldEndPosition;
              g.ScreenEnd = t.position;
            }
              }
              else if ( t.phase == TouchPhase.Moved )
              {
            if ( g.GameGesture == ExGestureObject.GameGestureType.Down ||
                g.GameGesture == ExGestureObject.GameGestureType.Drag ||
                g.GameGesture == ExGestureObject.GameGestureType.None )
            {
              g.GameGesture = ExGestureObject.GameGestureType.Drag;
              g.EndPosition = worldEndPosition;
              g.ScreenEnd = t.position;
            }
              }
              else if ( t.phase == TouchPhase.Stationary )
              {
            if ( g.GameGesture == ExGestureObject.GameGestureType.Down ||
                g.GameGesture == ExGestureObject.GameGestureType.None )
            {
              if ( Time.time - g.StartTime > 2 )
              {
                g.GameGesture = ExGestureObject.GameGestureType.Hold;
              }
              else
              {
                g.GameGesture = ExGestureObject.GameGestureType.Down;
              }
              g.EndPosition = worldEndPosition;
              g.ScreenEnd = t.position;
            }
              }
            }
            else
            {
              g = new ExGestureObject();
              g.Initialize( ExGestureObject.GameGestureType.None, worldEndPosition, worldEndPosition, t.position, t.position, Time.time, t.fingerId );
              gestures.Add( g.Id, g );
            }

            return g;
              }
        }