Author Topic: DraggablePanel issues  (Read 5952 times)

nah0y

  • Sr. Member
  • ****
  • Thank You
  • -Given: 1
  • -Receive: 2
  • Posts: 430
  • \o/
    • View Profile
DraggablePanel issues
« on: July 31, 2012, 12:31:18 PM »
Hi !

I have three issues using the DraggablePanel on a UIPanel with clipping.

1. Touch detection OUTSIDE the soft clip
Imagine I have a list of objects inside a panel with clipping, when I scroll the list, some of the items became invisible (because they are outside the clip). But when I touch them even if they're outside, I can drag the list and make it scroll (ie. the colliders of those objects are not disabled).
Is it a normal behavior ?

2. Really sensitive scroll on iOS (maybe Android ?)
Another issue is that on that list of items, I want to click on an item, and A LOT of times, it does not take it as a click but a scroll and so starts scrolling... some times it's really hard to have a correct click on an object :(
Maybe we can add an amount of drag before we start scrolling and instead just throw a click/press event ?

Or maybe I'm doing something wrong ?

3. Press state when scrolling
I have a row of images, and if I press one of them, I change the sprite for the pressed state,
When I scroll and I'm pressing on an item, it register the pressed state, and so display the pressed sprite, but I'm scrolling, I don't want to have the pressed state triggered. I understand this is the correct behavior because well... I have pressed the item ! But how can I override this ?
I mean, in the settings panel of iOS for example, if you scroll, there i no item of the list that become blue, we're only scrolling. But if you stay a little more longer on an item, it becomes blue (maybe 200ms ?).
But if you just click it and release your finger, it register the pressed & clicked state.

Maybe 2 and 3 are connected and we must just add a small amount of time to detect if we're scrolling or really pressing the item. And maybe trigger the click if there is a press (<200ms) AND release.

Thanks !

PS : If needed I can make you a video.
« Last Edit: July 31, 2012, 12:38:37 PM by nah0y »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: DraggablePanel issues
« Reply #1 on: July 31, 2012, 10:19:57 PM »
1. Check what I did in the scroll view example. Put large colliders covering the drag area outside of the window so that they intercept the events.

2. This got fixed in 2.1.3. You'll see it live soon-ish.

3. You can add logic that un-highlights your sprite when it gets the drag event.

nah0y

  • Sr. Member
  • ****
  • Thank You
  • -Given: 1
  • -Receive: 2
  • Posts: 430
  • \o/
    • View Profile
Re: DraggablePanel issues
« Reply #2 on: August 01, 2012, 06:17:36 AM »
Thanks for the answers !

1. Why don't you just disable the colliders when they're outside the clipping area ? Is there a reason ?

2. Can you explain what was the problem ? If it's too long, I'll check comparing files of the next release, no problem :D

3. But, let's say I want to make this 200ms behavior (once again, this is natively done in Android and iOS lists), how could I do that ?
Because if I send an event, saying to disable the press state, I'll still have for x ms the pressed state.
I think I'll have to modify the ProcessTouch method of the UICamera, to delay the send of the "OnPress", but that would do that for EVERY other things, not just items of the list...

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: DraggablePanel issues
« Reply #3 on: August 01, 2012, 06:20:38 AM »
1. Because you can't disable a collider partially. There is no culling in Physics.Raycast.

2. Drag event won't be sent until there has been enough dragging to exceed a threshold set on UICamera.

3. SendMessage("OnPress", false);

nah0y

  • Sr. Member
  • ****
  • Thank You
  • -Given: 1
  • -Receive: 2
  • Posts: 430
  • \o/
    • View Profile
Re: DraggablePanel issues
« Reply #4 on: August 01, 2012, 06:23:45 AM »
1. Yes ok ! So maybe disable if entirely invisible ? And if it's not entirely visible, compare the touch position to the clipping position and see if it's in it ? :D Maybe too much work for something that can be fixed by using external colliders.

2. Thanks

3. Hum... I'm getting pretty familiar with the NGUI plugin, but still don't master it :D
What do you mean by SendMessage(false) ?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: DraggablePanel issues
« Reply #5 on: August 01, 2012, 06:35:00 AM »
You can write a tiny script to do just that. If widget is not visible, collider.enabled = false.

SendMessage is a Unity function. Look inside UICamera to see how it's used. That's how all events are sent out in NGUI.

nah0y

  • Sr. Member
  • ****
  • Thank You
  • -Given: 1
  • -Receive: 2
  • Posts: 430
  • \o/
    • View Profile
Re: DraggablePanel issues
« Reply #6 on: August 01, 2012, 06:36:37 AM »
Well yes, I know how it's used and how it works, but I mean, if I delay the send in UICamera, it will be delayed for everything, not just items in a draggable panel.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: DraggablePanel issues
« Reply #7 on: August 01, 2012, 10:05:42 AM »
Yup, but I never mentioned modifying the camera ;)

I mean write a small script that will go on the collider you wish to disable, referencing some widget. Inside the script check UIWidget.visibleFlag -- '0' means it's not visible. Enable/disable the collider accordingly. It's all just 1 line of code.

nah0y

  • Sr. Member
  • ****
  • Thank You
  • -Given: 1
  • -Receive: 2
  • Posts: 430
  • \o/
    • View Profile
Re: DraggablePanel issues
« Reply #8 on: August 01, 2012, 10:07:59 AM »
lol, I believe you're talking about 1, but I'm talking about 3 :S

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: DraggablePanel issues
« Reply #9 on: August 01, 2012, 10:40:38 AM »
As am I.

nah0y

  • Sr. Member
  • ****
  • Thank You
  • -Given: 1
  • -Receive: 2
  • Posts: 430
  • \o/
    • View Profile
Re: DraggablePanel issues
« Reply #10 on: August 01, 2012, 11:08:07 AM »
I want to not register the OnPress on a collider for the first 200ms, and you're telling me to disable a collider if it's not visible :o

I'm lost :-[

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: DraggablePanel issues
« Reply #11 on: August 01, 2012, 11:12:04 AM »
Ok, broken telephone there somewhere.

For disabling of a press state, you can simply do this:

  1.         void OnPress (bool isPressed)
  2.         {
  3.                 if (isPressed)
  4.                 {
  5.                         StartCoroutine(DelayedUnpress());
  6.                 }
  7.         }
  8.  
  9.         IEnumerator DelayedUnpress ()
  10.         {
  11.                 yield return new WaitForSeconds(0.2f);
  12.                 SendMessage("OnPress", false);
  13.         }

nah0y

  • Sr. Member
  • ****
  • Thank You
  • -Given: 1
  • -Receive: 2
  • Posts: 430
  • \o/
    • View Profile
Re: DraggablePanel issues
« Reply #12 on: August 01, 2012, 12:45:35 PM »
Oh okay !

So, there is no collider in there :)


It works as expected now !
What I do is not SendMessage("OnPress", false), but I do that :

  1. void OnPress(bool pressed)
  2. {
  3.         if (checkTweenerDelay > 0f)
  4.         {
  5.                 StartCoroutine(delayedOnPess(pressed));
  6.         }
  7.         else
  8.         {
  9.                 reactToPress(pressed);
  10.         }
  11. }
  12.        
  13. IEnumerator delayedOnPess(bool pressed)
  14. {
  15.         yield return new WaitForSeconds(checkTweenerDelay);
  16.         reactToPress(pressed);
  17. }
  18.  
  19. private void reactToPress(bool pressed)
  20. {
  21.         // Here I do what I want with the pressed state
  22. }
  23.  

And also, very important, with the OnDrag and OnClick :
  1. void OnDrag()
  2. {
  3.         StopAllCoroutines();
  4.  
  5.         // Here I set the opposite of what the pressed state do
  6. }
  7.  

  1. void OnClick()
  2. {
  3.         StopAllCoroutines();
  4. }
  5.  


Does this seems something correct to you ?
« Last Edit: August 01, 2012, 12:50:20 PM by nah0y »

nah0y

  • Sr. Member
  • ****
  • Thank You
  • -Given: 1
  • -Receive: 2
  • Posts: 430
  • \o/
    • View Profile
Re: DraggablePanel issues
« Reply #13 on: August 01, 2012, 01:31:57 PM »
Also, sorry to insist, but for the second point, the drag list that is really weird on iOS, can you post the fix here if it's fast ? So I can modify the code ?
I have to make some users test the game, and can't do it with this behavior :s

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: DraggablePanel issues
« Reply #14 on: August 01, 2012, 04:10:45 PM »
I can't post UICamera here, but if you sent me an email, I'll send it as an attachment: support at tasharen.com