Tasharen Entertainment Forum

Support => NGUI 3 Support => Topic started by: Ferazel on May 24, 2012, 11:07:41 AM

Title: UIDraggablePanel Deadspace
Post by: Ferazel on May 24, 2012, 11:07:41 AM
I'm looking for some recommendations on how to implement a "drag dead space" for the UIDraggablePanel. I have received feedback that the the list of checkboxes that I have is too sensitive for when you are selecting the items in the list. The drag event will fire too soon on the widget and it will start scrolling when all that was desired was a tap functionality. Is there a good way to implement this either in the UICamera or the UIDraggablePanel and turn it on or off?

Thanks!
Title: Re: UIDraggablePanel Deadspace
Post by: Ferazel on May 24, 2012, 12:07:27 PM
I will answer my own question, but I'd like to see if maybe this could be implemented into the full release.
I added a new float to the UICamera called scrollDeadSpace (in my application I set this to 15).

Then in the UICamera ProcessTouch() I added the following conditional
  1. if(currentTouch.totalDelta.magnitude > scrollDeadSpace) {
  2.       currentTouch.pressed.SendMessage("OnDrag", currentTouch.delta, SendMessageOptions.DontRequireReceiver);
  3. }
  4.  

Hopefully, this can be put into the main build and it doesn't cause any significant issues, but so far so good.
Title: Re: UIDraggablePanel Deadspace
Post by: ArenMook on May 24, 2012, 12:26:20 PM
Might be better if it was in UIDraggablePanel. I'll think about it.
Title: Re: UIDraggablePanel Deadspace
Post by: Ferazel on June 25, 2012, 11:31:20 AM
Sorry to necro a thread, but I just wanted to put some code in there that would remain within the UIDraggablePanel as ArenMook recommended and to remind you about this problem. The problem is that on touch devices when you have a drag panel even slightly touching the panel will usually cause the drag list to move as touches are very inexact.

I just created public float data member in the UIDraggablePanel called scrollingDeadspace and a Vector2 that will represent the total distance traveled by dragging. This vector will reset on every touch down. Then in the Press and OnDrag event handler methods I have. Existing functionality would work with a default value of 0 given to sensitivity.

  1. public void Press (bool pressed)
  2. {
  3. ...
  4.         if (pressed)
  5.         {
  6.                 // Remove all momentum on press
  7.                 mMomentum = Vector3.zero;
  8.                 mScroll = 0f;
  9.                 totalDistanceTravelled.x = totalDistanceTravelled.y = 0.0f; //Reset the distance dragged for sensitivity reason
  10.                 // Disable the spring movement
  11.                 DisableSpring();
  12.  
  13. ...
  14.  
  15. public void Drag (Vector2 delta)
  16. {
  17.         //We will only care if our sensitivity has cause our sensitivity to trigger
  18.         if(Mathf.Abs(scrollingDeadspace) > 0.01f) {
  19.                 totalDistanceTravelled.x += Mathf.Abs(delta.x);
  20.                 totalDistanceTravelled.y += Mathf.Abs(delta.y);
  21.                 if(totalDistanceTravelled.magnitude < scrollingDeadspace) {
  22.                         return; //Not travelled enough distance yet
  23.                 }
  24.         }
  25. ....
  26.  

Am I the only one who thinks this is helpful? I would like to get this integrated into NGUI so I don't have to redo the work when I update.  :P Thanks!