Author Topic: How to make a button release when finger slides off it (mobile)  (Read 37412 times)

arkon3

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 71
    • View Profile
How to make a button release when finger slides off it (mobile)
« on: October 15, 2014, 10:55:37 PM »
I have 2 buttons on screen (Left & Right) each button send an onPress and OnReleased event and this works fine but I need to be able to have the player slide his finger from one button to the next or even off the button. When the player slides off the button I need to send an event telling my script the player no longer is pressing the button.

Currently nothing is sent when you slide off a button. OnHover out kind of does it but it only works on desktop. I need a mobile solution.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How to make a button release when finger slides off it (mobile)
« Reply #1 on: October 16, 2014, 06:47:00 AM »
NGUI sents OnDragOut when you do that, and OnDragOver when you move your finger back. Make use of those events and you should be fine.

arkon3

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 71
    • View Profile
Re: How to make a button release when finger slides off it (mobile)
« Reply #2 on: October 16, 2014, 07:07:36 AM »
This doesn't seem to work. If I press on a button I get the pressed event BUT when I start moving my finger it fires the DragOut event continuously as I swipe over the button. Shouldn't the DragOut event only fire when you leave the button?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How to make a button release when finger slides off it (mobile)
« Reply #3 on: October 16, 2014, 07:11:53 AM »
OnDragOut is only sent every time you leave the button. Re-entering it gives OnDragOver, and leaving it again will result in another OnDragOut, etc.

arkon3

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 71
    • View Profile
Re: How to make a button release when finger slides off it (mobile)
« Reply #4 on: October 16, 2014, 07:14:33 AM »
Thats not what it's doing though. The OnDragOut is firing as I move across the button and still firing as I leave the button.
it doesn't stop firing the event until I let go. I should add I'm using UIEventTrigger to send the events to a script.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How to make a button release when finger slides off it (mobile)
« Reply #5 on: October 16, 2014, 07:16:32 AM »
In what version of NGUI? What's underneath the mouse when it happens? UICamera.hoveredObject

arkon3

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 71
    • View Profile
Re: How to make a button release when finger slides off it (mobile)
« Reply #6 on: October 16, 2014, 07:26:46 AM »
Very recent, within the last few days from the asset store. The readme says 3.7.4
The item under the even is the button itself all the time I'm dragging across the button. Seems like a definite bug to me. Do you want a repo project for it? Actually here is a debug log of every event as I first press then slide across the button then out of it into empty space if that helps:-

QED 5 OnLeftPressed
QED 6 OnLeftDragOver ButtonLeft (UnityEngine.GameObject)
QED 7 OnLeftDragOut ButtonLeft (UnityEngine.GameObject)
QED 8 OnLeftDragOut ButtonLeft (UnityEngine.GameObject)
QED 9 OnLeftDragOut ButtonLeft (UnityEngine.GameObject)
QED 10 OnLeftDragOut ButtonLeft (UnityEngine.GameObject)
QED 11 OnLeftDragOut ButtonLeft (UnityEngine.GameObject)
QED 12 OnLeftDragOut ButtonLeft (UnityEngine.GameObject)
QED 13 OnLeftDragOut ButtonLeft (UnityEngine.GameObject)
QED 14 OnLeftDragOut ButtonLeft (UnityEngine.GameObject)
QED 15 OnLeftDragOut ButtonLeft (UnityEngine.GameObject)
QED 16 OnLeftDragOut ButtonLeft (UnityEngine.GameObject)
QED 17 OnLeftDragOut ButtonLeft (UnityEngine.GameObject)
QED 18 OnLeftDragOut ButtonLeft (UnityEngine.GameObject)
QED 19 OnLeftDragOut ButtonLeft (UnityEngine.GameObject)
QED 20 OnLeftDragOut ButtonLeft (UnityEngine.GameObject)
QED 21 OnLeftDragOut ButtonLeft (UnityEngine.GameObject)
QED 22 OnLeftDragOut UI Root (UnityEngine.GameObject)
QED 23 OnLeftDragOut UI Root (UnityEngine.GameObject)
QED 24 OnLeftDragOut UI Root (UnityEngine.GameObject)
QED 25 OnLeftDragOut UI Root (UnityEngine.GameObject)
QED 26 OnLeftDragOut UI Root (UnityEngine.GameObject)
QED 27 OnLeftDragOut UI Root (UnityEngine.GameObject)
QED 28 OnLeftDragOut UI Root (UnityEngine.GameObject)
QED 29 OnLeftDragOut UI Root (UnityEngine.GameObject)
QED 30 OnLeftDragOut UI Root (UnityEngine.GameObject)
QED 31 OnLeftDragOut UI Root (UnityEngine.GameObject)
QED 32 OnLeftDragOut UI Root (UnityEngine.GameObject)
QED 33 OnLeftDragOut UI Root (UnityEngine.GameObject)
QED 34 OnLeftDragOut UI Root (UnityEngine.GameObject)
QED 35 OnLeftDragOut UI Root (UnityEngine.GameObject)
QED 36 OnLeftDragOut UI Root (UnityEngine.GameObject)
QED 37 OnLeftDragOut UI Root (UnityEngine.GameObject)
QED 38 OnLeftDragOut UI Root (UnityEngine.GameObject)
QED 39 OnLeftDragOut UI Root (UnityEngine.GameObject)
QED 40 OnLeftDragOut UI Root (UnityEngine.GameObject)
QED 41 OnLeftReleased

badawe

  • Jr. Member
  • **
  • Thank You
  • -Given: 8
  • -Receive: 7
  • Posts: 70
    • View Profile
Re: How to make a button release when finger slides off it (mobile)
« Reply #7 on: October 16, 2014, 07:55:27 AM »
He probably having the same issue that I've on this topic:
http://www.tasharen.com/forum/index.php?topic=11454.0;topicseen


Try remove the UseMouse on the camera?
« Last Edit: October 16, 2014, 08:03:35 AM by badawe »

arkon3

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 71
    • View Profile
Re: How to make a button release when finger slides off it (mobile)
« Reply #8 on: October 16, 2014, 08:39:32 AM »
Thanks but it changed the behaviour but still not correct. Turning off use mouse cured the continual OnDragOut event across the button BUT now it doesn't Cause a OnDragOver when you slide back onto the button from outside it.

So now it Does OnPressed when I press it (correct), Nothing as I slide over it (correct), OnDragOut as I slide into empty space (correct), continues giving OnDragOut as I slide back into the button (wrong).

Getting frustrated now.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How to make a button release when finger slides off it (mobile)
« Reply #9 on: October 17, 2014, 04:44:24 AM »
I just did a quick test.

1. New scene.
2. ALT+SHIFT+S, ALT+SHIFT+C
3. Added this script to it:
  1. using UnityEngine;
  2.  
  3. public class Test : MonoBehaviour
  4. {
  5.         void OnDragOver (GameObject go)
  6.         {
  7.                 Debug.Log("On Drag Over " + name);
  8.         }
  9.  
  10.         void OnDragOut (GameObject go)
  11.         {
  12.                 Debug.Log("On Drag Over" + name);
  13.         }
  14. }
4. Hit Play, press on the object, start dragging -- On Drag Over.
5. Drag outside - OnDrag Out.
6. Drag back inside - On Drag Over
7. Drag back outside - On Drag Out, etc.

Tried the same thing with mouse events disabled. Results are the same. Tried building for an android device -- same (but I had to change it to NGUIDebug.Log instead of Debug.Log). What's your target platform?

arkon3

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 71
    • View Profile
Re: How to make a button release when finger slides off it (mobile)
« Reply #10 on: October 19, 2014, 06:51:09 AM »
Hi, My target is set to IOS. But I don't intercept the events like you have above. I have the 2 buttons in the UIRoot and each button has a UIEventTrigger script attached sending those events to a single game object.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How to make a button release when finger slides off it (mobile)
« Reply #11 on: October 19, 2014, 12:01:13 PM »
Can you try simplifying it and trying to the example I posted? Does it work as expected?

arkon3

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 71
    • View Profile
Re: How to make a button release when finger slides off it (mobile)
« Reply #12 on: October 24, 2014, 08:46:46 PM »
Sorry for the delay, When something doesn't work I move on to other things. Anyway I just deleted the UIEventTrigger
on each button and added the Test class you suggested and all the events now work as expected. This means you have
some kind of bug in the UIEventTrigger script.

For now I will have to do it without the trigger script. But now I need to send the events from the test script way of doing it to the class that actually needs to know the events. How do I do that, I really didn't want to use SendMessage which is why I used the UIEventTrigger.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: How to make a button release when finger slides off it (mobile)
« Reply #13 on: October 25, 2014, 02:50:58 PM »
UIEventTrigger simply calls remote delegates. Open it up, have a look inside UIEventTrigger.OnDragOver and OnDragOut. Each of those functions is 4 lines of code. I suggest having a closer look at what your delegates were doing.