コード例 #1
0
ファイル: TouchThrow.cs プロジェクト: dashqasar/GoogleMap
    public void OnMultiTouch( dfControl control, dfTouchEventArgs touchData )
    {
        this.momentum = Vector2.zero;

        control.Color = Color.yellow;

        // Determine movement for each finger
        var touch1 = touchData.Touches[ 0 ];
        var touch2 = touchData.Touches[ 1 ];
        var dir1 = ( touch1.deltaPosition * ( Time.deltaTime / touch1.deltaTime ) ).Scale( 1, -1 );
        var dir2 = ( touch2.deltaPosition * ( Time.deltaTime / touch2.deltaTime ) ).Scale( 1, -1 );

        // Calculate size delta
        var pos1 = screenToGUI( touch1.position );
        var pos2 = screenToGUI( touch2.position );
        var currDist = pos1 - pos2;
        var prevDist = ( pos1 - dir1 ) - ( pos2 - dir2 );
        var delta = currDist.magnitude - prevDist.magnitude;

        if( Mathf.Abs( delta ) > float.Epsilon )
        {

            // Save relative position to restore after control's Size has changed
            var min = Vector3.Min( pos1, pos2 );
            var offset = min - control.RelativePosition;

            // Adjust the control's size according to the touch delta
            control.Size += Vector2.one * delta;

            // Put control back in relative position
            control.RelativePosition = min + offset;

        }
    }
コード例 #2
0
    public void OnMultiTouch( dfControl control, dfTouchEventArgs touchData )
    {
        var message = "Multi-Touch:\n";
        for( int i = 0; i < touchData.Touches.Count; i++ )
        {
            var touch = touchData.Touches[ i ];
            message += string.Format( "\tFinger {0}: {1}\n", i + 1, screenToGUI( touch.position ) );
        }

        display( message );
    }
コード例 #3
0
ファイル: dfRotateGesture.cs プロジェクト: Elringus/HajiJam
    public void OnMultiTouch(dfControl sender, dfTouchEventArgs args)
    {
        var touches = args.Touches;

        if (State == dfGestureState.None || State == dfGestureState.Cancelled || State == dfGestureState.Ended)
        {
            State            = dfGestureState.Possible;
            accumulatedDelta = 0f;
        }
        else if (State == dfGestureState.Possible)
        {
            if (isRotateMovement(args.Touches))
            {
                var angleDelta = getAngleDelta(touches) + accumulatedDelta;
                if (Mathf.Abs(angleDelta) < thresholdAngle)
                {
                    accumulatedDelta = angleDelta;
                    return;
                }

                State         = dfGestureState.Began;
                StartPosition = CurrentPosition = getCenter(touches);
                AngleDelta    = angleDelta;

                if (RotateGestureStart != null)
                {
                    RotateGestureStart(this);
                }
                gameObject.Signal("OnRotateGestureStart", this);
            }
        }
        else if (State == dfGestureState.Began || State == dfGestureState.Changed)
        {
            var angleDelta = getAngleDelta(touches);
            if (Mathf.Abs(angleDelta) <= float.Epsilon || Mathf.Abs(angleDelta) > 22.5f)
            {
                return;
            }

            State           = dfGestureState.Changed;
            AngleDelta      = angleDelta;
            CurrentPosition = getCenter(touches);

            if (RotateGestureUpdate != null)
            {
                RotateGestureUpdate(this);
            }
            gameObject.Signal("OnRotateGestureUpdate", this);
        }
    }
コード例 #4
0
	public void OnMultiTouch( dfControl sender, dfTouchEventArgs args )
	{

		var touches = args.Touches;

		if( State == dfGestureState.None || State == dfGestureState.Cancelled || State == dfGestureState.Ended )
		{
			State = dfGestureState.Possible;
			accumulatedDelta = 0f;
		}
		else if( State == dfGestureState.Possible )
		{
			if( isRotateMovement( args.Touches ) )
			{

				var angleDelta = getAngleDelta( touches ) + accumulatedDelta;
				if( Mathf.Abs( angleDelta ) < thresholdAngle )
				{
					accumulatedDelta = angleDelta;
					return;
				}

				State = dfGestureState.Began;
				StartPosition = CurrentPosition = getCenter( touches );
				AngleDelta = angleDelta;

				if( RotateGestureStart != null ) RotateGestureStart( this );
				gameObject.Signal( "OnRotateGestureStart", this );

			}
		}
		else if( State == dfGestureState.Began || State == dfGestureState.Changed )
		{

			var angleDelta = getAngleDelta( touches );
			if( Mathf.Abs( angleDelta ) <= float.Epsilon || Mathf.Abs( angleDelta ) > 22.5f )
				return;

			State = dfGestureState.Changed;
			AngleDelta = angleDelta;
			CurrentPosition = getCenter( touches );

			if( RotateGestureUpdate != null ) RotateGestureUpdate( this );
			gameObject.Signal( "OnRotateGestureUpdate", this );

		}

	}
コード例 #5
0
 public void OnMultiTouch(dfControl source, dfTouchEventArgs args)
 {
     if (State == dfGestureState.Began)
     {
         State = dfGestureState.Cancelled;
         if (HoldGestureEnd != null)
         {
             HoldGestureEnd(this);
         }
         gameObject.Signal("OnHoldGestureEnd", this);
     }
     else
     {
         State = dfGestureState.Failed;
     }
 }
コード例 #6
0
    public void OnMultiTouch(dfControl sender, dfTouchEventArgs args)
    {
        var touches = args.Touches;

        if (State == dfGestureState.None || State == dfGestureState.Cancelled || State == dfGestureState.Ended)
        {
            State = dfGestureState.Possible;
        }
        else if (State == dfGestureState.Possible)
        {
            if (isResizeMovement(args.Touches))
            {
                State = dfGestureState.Began;

                StartPosition = CurrentPosition = getCenter(touches);

                lastDistance = Vector2.Distance(touches[0].position, touches[1].position);
                SizeDelta    = 0;

                if (ResizeGestureStart != null)
                {
                    ResizeGestureStart(this);
                }
                gameObject.Signal("OnResizeGestureStart", this);
            }
        }
        else if (State == dfGestureState.Began || State == dfGestureState.Changed)
        {
            if (isResizeMovement(touches))
            {
                State = dfGestureState.Changed;

                CurrentPosition = getCenter(touches);

                var distance = Vector2.Distance(touches[0].position, touches[1].position);
                SizeDelta    = distance - lastDistance;
                lastDistance = distance;

                if (ResizeGestureUpdate != null)
                {
                    ResizeGestureUpdate(this);
                }
                gameObject.Signal("OnResizeGestureUpdate", this);
            }
        }
    }
コード例 #7
0
	public void OnMultiTouch( dfControl sender, dfTouchEventArgs args )
	{

		var touches = args.Touches;

		if( State == dfGestureState.None || State == dfGestureState.Cancelled || State == dfGestureState.Ended )
		{
			State = dfGestureState.Possible;
		}
		else if( State == dfGestureState.Possible )
		{
			if( isResizeMovement( args.Touches ) )
			{
				
				State = dfGestureState.Began;
				
				StartPosition = CurrentPosition = getCenter( touches );

				lastDistance = Vector2.Distance( touches[ 0 ].position, touches[ 1 ].position );
				SizeDelta = 0;

				if( ResizeGestureStart != null ) ResizeGestureStart( this );
				gameObject.Signal( "OnResizeGestureStart", this );

			}
		}
		else if( State == dfGestureState.Began || State == dfGestureState.Changed )
		{
			if( isResizeMovement( touches ) )
			{

				State = dfGestureState.Changed;

				CurrentPosition = getCenter( touches );

				var distance = Vector2.Distance( touches[ 0 ].position, touches[ 1 ].position );
				SizeDelta = distance - lastDistance;
				lastDistance = distance;

				if( ResizeGestureUpdate != null ) ResizeGestureUpdate( this );
				gameObject.Signal( "OnResizeGestureUpdate", this );

			}
		}

	}
コード例 #8
0
    public void OnMultiTouch(dfControl source, dfTouchEventArgs args)
    {
        var center = getCenter(args.Touches);

        if (!multiTouchMode)
        {
            endPanGesture();

            multiTouchMode = true;
            State          = dfGestureState.Possible;
            StartPosition  = center;
        }
        else if (State == dfGestureState.Possible)
        {
            if (Vector2.Distance(center, StartPosition) >= minDistance)
            {
                State = dfGestureState.Began;

                CurrentPosition = center;
                Delta           = CurrentPosition - StartPosition;

                if (PanGestureStart != null)
                {
                    PanGestureStart(this);
                }
                gameObject.Signal("OnPanGestureStart", this);
            }
        }
        else if (State == dfGestureState.Began || State == dfGestureState.Changed)
        {
            State = dfGestureState.Changed;

            Delta           = center - CurrentPosition;
            CurrentPosition = center;

            if (PanGestureMove != null)
            {
                PanGestureMove(this);
            }
            gameObject.Signal("OnPanGestureMove", this);
        }
    }
コード例 #9
0
            /// <summary>
            /// Processes touch information for a single control
            /// </summary>
            /// <param name="info">The touch/raycast data to be processed</param>
            /// <returns>Returns TRUE if the touch information was processed</returns>
            public bool Process( TouchRaycast info )
            {

                #region Drag / Drop

                if( IsDragging )
                {

                    // Not interested in any fingers other than the one that
                    // started the drag operation
                    if( !capture.Contains( info.FingerID ) )
                        return false;

                    // Nothing to do if there's no user action
                    if( info.Phase == TouchPhase.Stationary )
                        return true;

                    // If the touch was cancelled, raise OnDragEnd event
                    if( info.Phase == TouchPhase.Canceled )
                    {

                        control.OnDragEnd( new dfDragEventArgs( control, dfDragDropState.Cancelled, dragData, info.ray, info.position ) );
                        dragState = dfDragDropState.None;

                        touches.Clear();
                        capture.Clear();

                        return true;
                    }

                    // If the finger was lifted, attempt drop
                    if( info.Phase == TouchPhase.Ended )
                    {

                        // Dropped on nothing
                        if( info.control == null || info.control == control )
                        {

                            control.OnDragEnd( new dfDragEventArgs( control, dfDragDropState.CancelledNoTarget, dragData, info.ray, info.position ) );
                            dragState = dfDragDropState.None;

                            touches.Clear();
                            capture.Clear();

                            return true;

                        }

                        // Dropped on another control
                        var dropArgs = new dfDragEventArgs( info.control, dfDragDropState.Dragging, dragData, info.ray, info.position );
                        info.control.OnDragDrop( dropArgs );

                        // If there was no event consumer, or if the event consumer did not
                        // change the state from Dragging (which is not a valid state for
                        // a drop event) then just cancel the operation
                        if( !dropArgs.Used || dropArgs.State != dfDragDropState.Dropped )
                        {
                            dropArgs.State = dfDragDropState.Cancelled;
                        }

                        // Let the control know that it is no longer being dragged
                        var endArgs = new dfDragEventArgs( control, dropArgs.State, dragData, info.ray, info.position );
                        endArgs.Target = info.control;
                        control.OnDragEnd( endArgs );

                        // Clear state
                        dragState = dfDragDropState.None;
                        touches.Clear();
                        capture.Clear();

                        return true;

                    }

                    return true;

                }

                #endregion

                #region New touch for this control

                if( !touches.ContainsKey( info.FingerID ) )
                {

                    // Touch is not over control, and is not "captured" by control
                    if( info.control != control )
                        return false;

                    // Start tracking this finger
                    touches[ info.FingerID ] = info;

                    // See if this is the first touch to be tracked for this control
                    if( touches.Count == 1 )
                    {

                        // This is the first Touch to be associated with the control
                        control.OnMouseEnter( info );

                        // If the touch was also started while over the control,
                        // then raise the OnMouseDown event
                        if( info.Phase == TouchPhase.Began )
                        {

                            capture.Add( info.FingerID );
                            controlStartPosition = control.transform.position;

                            control.OnMouseDown( info );

                            // Prevent "click-through"
                            if( Event.current != null )
                                Event.current.Use();

                        }

                        return true;

                    }

                    // Switch control to "multi-touch" mode if touch began on control,
                    // otherwise ignore the new touch info
                    if( info.Phase == TouchPhase.Began )
                    {

                        // Send multi-touch event
                        var activeTouches = getActiveTouches();
                        var multiTouchArgs = new dfTouchEventArgs( control, activeTouches, info.ray );
                        control.OnMultiTouch( multiTouchArgs );

                    }

                    return true;

                }

                #endregion

                #region Previously tracked touch has now ended

                if( info.Phase == TouchPhase.Canceled || info.Phase == TouchPhase.Ended )
                {

                    var phase = info.Phase;
                    var touch = touches[ info.FingerID ];

                    // Remove the finger from the list of touches
                    touches.Remove( info.FingerID );

                    if( touches.Count == 0 && phase != TouchPhase.Canceled )
                    {

                        if( capture.Contains( info.FingerID ) )
                        {

                            if( canFireClickEvent( info, touch ) )
                            {

                                if( info.control == this.control )
                                {
                                    if( info.touch.tapCount > 1 )
                                        control.OnDoubleClick( info );
                                    else
                                        control.OnClick( info );
                                }

                            }

                            info.control = this.control;
                            this.control.OnMouseUp( info );

                        }

                        capture.Remove( info.FingerID );

                        return true;

                    }
                    else
                    {
                        capture.Remove( info.FingerID );
                    }

                    if( touches.Count == 1 )
                    {

                        // Explicitly notify control that multi-touch state has ended
                        control.OnMultiTouchEnd();

                        return true;

                    }

                }

                #endregion

                #region Multi-touch events

                // If there is more than one touch active for this control,
                // then raise the OnMultiTouch event instead of converting
                // the touch info to mouse events
                if( touches.Count > 1 )
                {

                    var activeTouches = getActiveTouches();
                    var multiTouchArgs = new dfTouchEventArgs( control, activeTouches, info.ray );

                    control.OnMultiTouch( multiTouchArgs );

                    return true;

                }

                #endregion

                // If the touch has not moved, send hover message
                if( !IsDragging && info.Phase == TouchPhase.Stationary )
                {
                    if( info.control == this.control )
                    {
                        control.OnMouseHover( info );
                        return true;
                    }
                    return false;
                }

                #region See if the control supports (and allows) drag-and-drop

                var canStartDrag =
                    capture.Contains( info.FingerID ) &&
                    dragState == dfDragDropState.None &&
                    info.Phase == TouchPhase.Moved;

                if( canStartDrag )
                {

                    // Query the control to see if drag-and-drop is allowed
                    var dragStartArgs = (dfDragEventArgs)info;
                    control.OnDragStart( dragStartArgs );

                    // If control set State and Used properties to the correct values,
                    // enter drag-and-drop mode
                    if( dragStartArgs.State == dfDragDropState.Dragging && dragStartArgs.Used )
                    {

                        this.dragState = dfDragDropState.Dragging;
                        this.dragData = dragStartArgs.Data;

                        return true;

                    }

                    // Flag that we've already tried drag and drop
                    this.dragState = dfDragDropState.Denied;

                }

                #endregion

                // Check for mouse leave
                if( info.control != this.control )
                {

                    // If "capture" is not active, fire the OnMouseLeave event
                    if( !capture.Contains( info.FingerID ) )
                    {

                        info.control = this.control;
                        this.control.OnMouseLeave( info );

                        this.touches.Remove( info.FingerID );

                        return true;

                    }

                }

                // At this point, the only remaining option is to send OnMouseMove event
                info.control = this.control;
                this.control.OnMouseMove( info );

                return true;

            }
コード例 #10
0
ファイル: dfTapGesture.cs プロジェクト: Elringus/HajiJam
	public void OnMultiTouch( dfControl source, dfTouchEventArgs args )
	{
		State = dfGestureState.Failed;
	}
コード例 #11
0
 public void OnMultiTouch(dfControl source, dfTouchEventArgs args)
 {
     State = dfGestureState.Failed;
 }
コード例 #12
0
ファイル: dfHoldGesture.cs プロジェクト: Elringus/HajiJam
	public void OnMultiTouch( dfControl source, dfTouchEventArgs args )
	{

		if( State == dfGestureState.Began )
		{
			State = dfGestureState.Cancelled;
			if( HoldGestureEnd != null ) HoldGestureEnd( this );
			gameObject.Signal( "OnHoldGestureEnd", this );
		}
		else
		{
			State = dfGestureState.Failed;
		}

	}
コード例 #13
0
ファイル: dfPanGesture.cs プロジェクト: AhrenLi/2048
    public void OnMultiTouch( dfControl source, dfTouchEventArgs args )
    {
        var center = getCenter( args.Touches );

        if( !multiTouchMode )
        {

            endPanGesture();

            multiTouchMode = true;
            State = dfGestureState.Possible;
            StartPosition = center;

        }
        else if( State == dfGestureState.Possible )
        {
            if( Vector2.Distance( center, StartPosition ) >= minDistance )
            {

                State = dfGestureState.Began;

                CurrentPosition = center;
                Delta = CurrentPosition - StartPosition;

                if( PanGestureStart != null ) PanGestureStart( this );
                gameObject.Signal( "OnPanGestureStart", this );

            }
        }
        else if( State == dfGestureState.Began || State == dfGestureState.Changed )
        {

            State = dfGestureState.Changed;

            Delta = center - CurrentPosition;
            CurrentPosition = center;

            if( PanGestureMove != null ) PanGestureMove( this );
            gameObject.Signal( "OnPanGestureMove", this );

        }
    }
コード例 #14
0
ファイル: dfInputManager.cs プロジェクト: sknchan/LegacyRust
 public bool Process(dfInputManager.TouchInputManager.TouchRaycast info)
 {
     if (this.IsDragging)
     {
         if (!this.capture.Contains(info.FingerID))
         {
             return(false);
         }
         if (info.Phase == TouchPhase.Stationary)
         {
             return(true);
         }
         if (info.Phase == TouchPhase.Canceled)
         {
             this.control.OnDragEnd(new dfDragEventArgs(this.control, dfDragDropState.Cancelled, this.dragData, info.ray, info.position));
             this.dragState = dfDragDropState.None;
             this.touches.Clear();
             this.capture.Clear();
             return(true);
         }
         if (info.Phase != TouchPhase.Ended)
         {
             return(true);
         }
         if (info.control == null || info.control == this.control)
         {
             this.control.OnDragEnd(new dfDragEventArgs(this.control, dfDragDropState.CancelledNoTarget, this.dragData, info.ray, info.position));
             this.dragState = dfDragDropState.None;
             this.touches.Clear();
             this.capture.Clear();
             return(true);
         }
         dfDragEventArgs dfDragEventArg = new dfDragEventArgs(info.control, dfDragDropState.Dragging, this.dragData, info.ray, info.position);
         info.control.OnDragDrop(dfDragEventArg);
         if (!dfDragEventArg.Used || dfDragEventArg.State != dfDragDropState.Dropped)
         {
             dfDragEventArg.State = dfDragDropState.Cancelled;
         }
         dfDragEventArgs dfDragEventArg1 = new dfDragEventArgs(this.control, dfDragEventArg.State, this.dragData, info.ray, info.position)
         {
             Target = info.control
         };
         this.control.OnDragEnd(dfDragEventArg1);
         this.dragState = dfDragDropState.None;
         this.touches.Clear();
         this.capture.Clear();
         return(true);
     }
     if (!this.touches.ContainsKey(info.FingerID))
     {
         if (info.control != this.control)
         {
             return(false);
         }
         this.touches[info.FingerID] = info;
         if (this.touches.Count == 1)
         {
             this.control.OnMouseEnter(info);
             if (info.Phase == TouchPhase.Began)
             {
                 this.capture.Add(info.FingerID);
                 this.control.OnMouseDown(info);
             }
             return(true);
         }
         if (info.Phase == TouchPhase.Began)
         {
             this.control.OnMouseUp(info);
             this.control.OnMouseLeave(info);
             List <Touch>     activeTouches   = this.getActiveTouches();
             dfTouchEventArgs dfTouchEventArg = new dfTouchEventArgs(this.control, activeTouches, info.ray);
             this.control.OnMultiTouch(dfTouchEventArg);
         }
         return(true);
     }
     if (info.Phase == TouchPhase.Canceled || info.Phase == TouchPhase.Ended)
     {
         dfInputManager.TouchInputManager.TouchRaycast item = this.touches[info.FingerID];
         this.touches.Remove(info.FingerID);
         if (this.touches.Count == 0)
         {
             if (this.capture.Contains(info.FingerID))
             {
                 if (this.canFireClickEvent(info, item) && info.control == this.control)
                 {
                     if (info.touch.tapCount <= 1)
                     {
                         this.control.OnClick(info);
                     }
                     else
                     {
                         this.control.OnDoubleClick(info);
                     }
                 }
                 this.control.OnMouseUp(info);
             }
             this.control.OnMouseLeave(info);
             this.capture.Remove(info.FingerID);
             return(true);
         }
         this.capture.Remove(info.FingerID);
         if (this.touches.Count == 1)
         {
             dfTouchEventArgs dfTouchEventArg1 = this.touches.Values.First <dfInputManager.TouchInputManager.TouchRaycast>();
             this.control.OnMouseEnter(dfTouchEventArg1);
             this.control.OnMouseDown(dfTouchEventArg1);
             return(true);
         }
     }
     if (this.touches.Count > 1)
     {
         List <Touch>     touches          = this.getActiveTouches();
         dfTouchEventArgs dfTouchEventArg2 = new dfTouchEventArgs(this.control, touches, info.ray);
         this.control.OnMultiTouch(dfTouchEventArg2);
         return(true);
     }
     if (!this.IsDragging && info.Phase == TouchPhase.Stationary)
     {
         if (info.control != this.control)
         {
             return(false);
         }
         this.control.OnMouseHover(info);
         return(true);
     }
     if ((!this.capture.Contains(info.FingerID) || this.dragState != dfDragDropState.None ? false : info.Phase == TouchPhase.Moved))
     {
         dfDragEventArgs dfDragEventArg2 = info;
         this.control.OnDragStart(dfDragEventArg2);
         if (dfDragEventArg2.State == dfDragDropState.Dragging && dfDragEventArg2.Used)
         {
             this.dragState = dfDragDropState.Dragging;
             this.dragData  = dfDragEventArg2.Data;
             return(true);
         }
         this.dragState = dfDragDropState.Denied;
     }
     if (!(info.control != this.control) || this.capture.Contains(info.FingerID))
     {
         this.control.OnMouseMove(info);
         return(true);
     }
     this.control.OnMouseLeave(info);
     this.touches.Remove(info.FingerID);
     return(true);
 }