Hello Guest

Author Topic: Button Colliders and Swipe Detection  (Read 10106 times)

fryza

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 22
    • View Profile
Button Colliders and Swipe Detection
« on: April 30, 2013, 12:55:23 am »
I have 10 tk2dButtons inside a container game object.  What should happen is if I swipe the container object all the buttons should move left or right horizontally.  I have that set up just fine. The problem is the collider on the slider is in front of the buttons and always gets "Hit" even on a touch event.

So this prevents my tk2dButtons from working (or being hit by the raycast).

What I would like to do:

When a touch event happens we capture BOTH the colliders of the button and the container. On TouchPhase.Began the button will start to expand scale as if it was touched (which it was) - however, if the user starts swiping the button would retract back to normal and the container would start swiping and the button collider would be ignored.

The only time the button would work is if it was tapped and no "swipe" movement was detected. How do I go about doing this with the tk2dButton class? I can get buttons to work by themselves, and I can get the container object to swipe by itself, but I can't get these two to work together as desired.

Any thoughts?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Button Colliders and Swipe Detection
« Reply #1 on: April 30, 2013, 10:15:19 am »
You could take a look at the 2D Toolkit UI system.
That supports swipeable lists + buttons...

You can download a beta from the Releases forum.

fryza

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Button Colliders and Swipe Detection
« Reply #2 on: April 30, 2013, 08:29:28 pm »
You could take a look at the 2D Toolkit UI system.
That supports swipeable lists + buttons...

You can download a beta from the Releases forum.

Hi - I implemented your UIScrollableArea and it works GREAT! Good work with that. I do have one request and am wondering if you can help me make the proper code modification. Currently if you touch down on an "button" in the content area, then start swiping/drag your finger off it doesn't fire - which is great. But what I also think should happen that when you touch down, the instant you start swiping the button no longer is active. I keep getting tons of accidental button fires.  I am using tk2dButtons in the content area. Do you have a different button I should use? I do need to call a method on an object.

So again - is there a way to make it so when an item is touched down, and the user starts swiping that the button can no longer be fired until the swipe has stopped and the user completes a touch up event.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Button Colliders and Swipe Detection
« Reply #3 on: April 30, 2013, 09:41:27 pm »
I suggest trying the button from the tk2d UI system. It should work a lot better - there is a prefab in the UI system you can simply drag into your scene and customize.

fryza

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Button Colliders and Swipe Detection
« Reply #4 on: April 30, 2013, 11:53:53 pm »
I have done what you mentioned but am still having the same problem. Please see attached video. Notice how I click on the icon and drag it around. Then I fling/release it. It should NOT load the next screen - but it does - it registers the event and it shouldn't.

It is a Tk2dUIitem. I have tried "On Up Method Name" as well as "On Release Method Name" - they both still call the function when dragging.

Like on a native iOS app - if I touch a button on a scrollview, but then drag it - the button no longer recognizes the touch event. On iOS for the touch event to be fired, it must be a distinct tap.

How do I achieve the desired result? Your scrollview works beautifully - but I need to figure out this one problem - I can't swipe buttons without their method calls being triggered.

Here is the video: https://dl.dropboxusercontent.com/u/109152337/Scroll_Problem.MOV

If the feature I need doesn't exist - can we just hack it for the time being? Maybe I can insert a static bool in your code somewhere that says, "isDragging" - then when the method is called, if "isDraggin" was true then I don't call the method.
« Last Edit: April 30, 2013, 11:58:36 pm by fryza »

fryza

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Button Colliders and Swipe Detection
« Reply #5 on: May 01, 2013, 03:29:25 pm »
I suggest trying the button from the tk2d UI system. It should work a lot better - there is a prefab in the UI system you can simply drag into your scene and customize.

I've been playin around with this still for quite a few hours with no luck. What am I doing wrong here to get this to work?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Button Colliders and Swipe Detection
« Reply #6 on: May 01, 2013, 04:22:49 pm »
Just so I understand this correctly (I think I misunderstood your earlier request) - you click on the button, drag and then let go and it fires the button click?

fryza

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Button Colliders and Swipe Detection
« Reply #7 on: May 01, 2013, 04:24:21 pm »
Just so I understand this correctly (I think I misunderstood your earlier request) - you click on the button, drag and then let go and it fires the button click?

That is correct - and that is what I DONT want it to do. I want it to work like a native iOS UIScrollview - where if you select a button in the scrollview but drag it, then let go, the button does NOT fire.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Button Colliders and Swipe Detection
« Reply #8 on: May 01, 2013, 05:22:18 pm »
I'll get that checked out.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Button Colliders and Swipe Detection
« Reply #9 on: May 01, 2013, 10:11:51 pm »
Ahaa. I think I've found the issue. I kept clicking and dragging in the demo scene, and in the demo scene, it very quickly goes out of view. It breaks reliably when I drag just a tiny amount, and then let go - an event is fired then.

You should probably hack in a fix for now - I'll get it fixed properly in the next version.

fryza

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 22
    • View Profile
Re: Button Colliders and Swipe Detection
« Reply #10 on: May 02, 2013, 06:52:20 pm »
Ahaa. I think I've found the issue. I kept clicking and dragging in the demo scene, and in the demo scene, it very quickly goes out of view. It breaks reliably when I drag just a tiny amount, and then let go - an event is fired then.

You should probably hack in a fix for now - I'll get it fixed properly in the next version.

Ive got a bandaid solution that makes this work and just wanted to share it with you for your reference - I'm not an elegant coder FYI.

In tk2dUIScrollableArea.cs in the method UpdateSwipeScrollDestinationPostion() if currTouchPosLocal.x equals swipeScrollingPressDownStartLocalPos - you are still counting this as a swipe, when no swiping is taking place - the coords are the same which indicate a "button click" with no swipe. So now I have put in a check to see if these two values are equal - if they are equal then it is a button press, if they are not equal it means we are swiping and we should not fire the button event.

Thanks for the awesome UI system!

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Button Colliders and Swipe Detection
« Reply #11 on: May 02, 2013, 07:31:52 pm »
Thanks :)

I'll get it fixed properly in the next release, but in the mean time thanks for sharing your fix :)